@wailsio/runtime 3.0.0-alpha.9 → 3.0.0-alpha.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/android.js +39 -0
- package/{src → dist}/application.js +32 -46
- package/dist/browser.js +20 -0
- package/dist/callable.js +144 -0
- package/dist/calls.js +114 -0
- package/dist/cancellable.js +792 -0
- package/dist/clipboard.js +30 -0
- package/dist/contextmenu.js +83 -0
- package/dist/create.js +99 -0
- package/dist/dialogs.js +69 -0
- package/dist/drag.js +268 -0
- package/dist/environment.js +17 -0
- package/dist/event_types.js +292 -0
- package/dist/events.js +119 -0
- package/dist/flags.js +23 -0
- package/dist/index.js +88 -0
- package/dist/ios.js +28 -0
- package/dist/listener.js +44 -0
- package/dist/nanoid.js +38 -0
- package/dist/plugins/vite.js +64 -0
- package/dist/runtime.js +198 -0
- package/dist/screens.js +58 -0
- package/dist/system.js +158 -0
- package/dist/updater.js +74 -0
- package/dist/utils.js +98 -0
- package/dist/window.js +734 -0
- package/dist/wml.js +179 -0
- package/package.json +71 -26
- package/types/android.d.ts +21 -0
- package/types/application.d.ts +3 -10
- package/types/browser.d.ts +4 -4
- package/types/callable.d.ts +3 -0
- package/types/calls.d.ts +52 -24
- package/types/cancellable.d.ts +433 -0
- package/types/clipboard.d.ts +6 -5
- package/types/contextmenu.d.ts +1 -1
- package/types/create.d.ts +36 -0
- package/types/dialogs.d.ts +132 -20
- package/types/drag.d.ts +1 -4
- package/types/environment.d.ts +8 -0
- package/types/event_types.d.ts +281 -0
- package/types/events.d.ts +70 -33
- package/types/flags.d.ts +3 -3
- package/types/index.d.ts +32 -48
- package/types/ios.d.ts +13 -0
- package/types/listener.d.ts +9 -0
- package/types/nanoid.d.ts +1 -0
- package/types/plugins/vite.d.ts +10 -0
- package/types/runtime.d.ts +61 -22
- package/types/screens.d.ts +64 -7
- package/types/system.d.ts +74 -39
- package/types/updater.d.ts +65 -0
- package/types/utils.d.ts +21 -0
- package/types/window.d.ts +327 -13
- package/types/wml.d.ts +5 -3
- package/src/browser.js +0 -24
- package/src/calls.js +0 -123
- package/src/clipboard.js +0 -35
- package/src/contextmenu.js +0 -98
- package/src/dialogs.js +0 -138
- package/src/drag.js +0 -125
- package/src/events.js +0 -134
- package/src/flags.js +0 -63
- package/src/index.d.ts +0 -136
- package/src/index.js +0 -58
- package/src/runtime.js +0 -122
- package/src/screens.js +0 -45
- package/src/system.js +0 -122
- package/src/window.js +0 -122
- package/src/wml.js +0 -151
- package/tsconfig.json +0 -20
package/dist/window.js
ADDED
|
@@ -0,0 +1,734 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
import { newRuntimeCaller, objectNames } from "./runtime.js";
|
|
11
|
+
// Drop target constants
|
|
12
|
+
const DROP_TARGET_ATTRIBUTE = 'data-file-drop-target';
|
|
13
|
+
const DROP_TARGET_ACTIVE_CLASS = 'file-drop-target-active';
|
|
14
|
+
let currentDropTarget = null;
|
|
15
|
+
const PositionMethod = 0;
|
|
16
|
+
const CenterMethod = 1;
|
|
17
|
+
const CloseMethod = 2;
|
|
18
|
+
const DisableSizeConstraintsMethod = 3;
|
|
19
|
+
const EnableSizeConstraintsMethod = 4;
|
|
20
|
+
const FocusMethod = 5;
|
|
21
|
+
const ForceReloadMethod = 6;
|
|
22
|
+
const FullscreenMethod = 7;
|
|
23
|
+
const GetScreenMethod = 8;
|
|
24
|
+
const GetZoomMethod = 9;
|
|
25
|
+
const HeightMethod = 10;
|
|
26
|
+
const HideMethod = 11;
|
|
27
|
+
const IsFocusedMethod = 12;
|
|
28
|
+
const IsFullscreenMethod = 13;
|
|
29
|
+
const IsMaximisedMethod = 14;
|
|
30
|
+
const IsMinimisedMethod = 15;
|
|
31
|
+
const MaximiseMethod = 16;
|
|
32
|
+
const MinimiseMethod = 17;
|
|
33
|
+
const NameMethod = 18;
|
|
34
|
+
const OpenDevToolsMethod = 19;
|
|
35
|
+
const RelativePositionMethod = 20;
|
|
36
|
+
const ReloadMethod = 21;
|
|
37
|
+
const ResizableMethod = 22;
|
|
38
|
+
const RestoreMethod = 23;
|
|
39
|
+
const SetPositionMethod = 24;
|
|
40
|
+
const SetAlwaysOnTopMethod = 25;
|
|
41
|
+
const SetBackgroundColourMethod = 26;
|
|
42
|
+
const SetFramelessMethod = 27;
|
|
43
|
+
const SetFullscreenButtonEnabledMethod = 28;
|
|
44
|
+
const SetMaxSizeMethod = 29;
|
|
45
|
+
const SetMinSizeMethod = 30;
|
|
46
|
+
const SetRelativePositionMethod = 31;
|
|
47
|
+
const SetResizableMethod = 32;
|
|
48
|
+
const SetSizeMethod = 33;
|
|
49
|
+
const SetTitleMethod = 34;
|
|
50
|
+
const SetZoomMethod = 35;
|
|
51
|
+
const ShowMethod = 36;
|
|
52
|
+
const SizeMethod = 37;
|
|
53
|
+
const ToggleFullscreenMethod = 38;
|
|
54
|
+
const ToggleMaximiseMethod = 39;
|
|
55
|
+
const ToggleFramelessMethod = 40;
|
|
56
|
+
const UnFullscreenMethod = 41;
|
|
57
|
+
const UnMaximiseMethod = 42;
|
|
58
|
+
const UnMinimiseMethod = 43;
|
|
59
|
+
const WidthMethod = 44;
|
|
60
|
+
const ZoomMethod = 45;
|
|
61
|
+
const ZoomInMethod = 46;
|
|
62
|
+
const ZoomOutMethod = 47;
|
|
63
|
+
const ZoomResetMethod = 48;
|
|
64
|
+
const SnapAssistMethod = 49;
|
|
65
|
+
const FilesDropped = 50;
|
|
66
|
+
const PrintMethod = 51;
|
|
67
|
+
const SetScreenMethod = 52;
|
|
68
|
+
/**
|
|
69
|
+
* Finds the nearest drop target element by walking up the DOM tree.
|
|
70
|
+
*/
|
|
71
|
+
function getDropTargetElement(element) {
|
|
72
|
+
if (!element) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return element.closest(`[${DROP_TARGET_ATTRIBUTE}]`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if we can use WebView2's postMessageWithAdditionalObjects (Windows)
|
|
79
|
+
* Also checks that EnableFileDrop is true for this window.
|
|
80
|
+
*/
|
|
81
|
+
function canResolveFilePaths() {
|
|
82
|
+
var _a, _b, _c, _d;
|
|
83
|
+
// Must have WebView2's postMessageWithAdditionalObjects API (Windows only)
|
|
84
|
+
if (((_b = (_a = window.chrome) === null || _a === void 0 ? void 0 : _a.webview) === null || _b === void 0 ? void 0 : _b.postMessageWithAdditionalObjects) == null) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Must have EnableFileDrop set to true for this window
|
|
88
|
+
// This flag is set by the Go backend during runtime initialization
|
|
89
|
+
return ((_d = (_c = window._wails) === null || _c === void 0 ? void 0 : _c.flags) === null || _d === void 0 ? void 0 : _d.enableFileDrop) === true;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Send file drop to backend via WebView2 (Windows only)
|
|
93
|
+
*/
|
|
94
|
+
function resolveFilePaths(x, y, files) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
if ((_b = (_a = window.chrome) === null || _a === void 0 ? void 0 : _a.webview) === null || _b === void 0 ? void 0 : _b.postMessageWithAdditionalObjects) {
|
|
97
|
+
window.chrome.webview.postMessageWithAdditionalObjects(`file:drop:${x}:${y}`, files);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Native drag state (Linux/macOS intercept DOM drag events)
|
|
101
|
+
let nativeDragActive = false;
|
|
102
|
+
/**
|
|
103
|
+
* Cleans up native drag state and hover effects.
|
|
104
|
+
* Called on drop or when drag leaves the window.
|
|
105
|
+
*/
|
|
106
|
+
function cleanupNativeDrag() {
|
|
107
|
+
nativeDragActive = false;
|
|
108
|
+
if (currentDropTarget) {
|
|
109
|
+
currentDropTarget.classList.remove(DROP_TARGET_ACTIVE_CLASS);
|
|
110
|
+
currentDropTarget = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Called from Go when a file drag enters the window on Linux/macOS.
|
|
115
|
+
*/
|
|
116
|
+
function handleDragEnter() {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
// Check if file drops are enabled for this window
|
|
119
|
+
if (((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.flags) === null || _b === void 0 ? void 0 : _b.enableFileDrop) === false) {
|
|
120
|
+
return; // File drops disabled, don't activate drag state
|
|
121
|
+
}
|
|
122
|
+
nativeDragActive = true;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Called from Go when a file drag leaves the window on Linux/macOS.
|
|
126
|
+
*/
|
|
127
|
+
function handleDragLeave() {
|
|
128
|
+
cleanupNativeDrag();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Called from Go during file drag to update hover state on Linux/macOS.
|
|
132
|
+
* @param x - X coordinate in CSS pixels
|
|
133
|
+
* @param y - Y coordinate in CSS pixels
|
|
134
|
+
*/
|
|
135
|
+
function handleDragOver(x, y) {
|
|
136
|
+
var _a, _b;
|
|
137
|
+
if (!nativeDragActive)
|
|
138
|
+
return;
|
|
139
|
+
// Check if file drops are enabled for this window
|
|
140
|
+
if (((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.flags) === null || _b === void 0 ? void 0 : _b.enableFileDrop) === false) {
|
|
141
|
+
return; // File drops disabled, don't show hover effects
|
|
142
|
+
}
|
|
143
|
+
const targetElement = document.elementFromPoint(x, y);
|
|
144
|
+
const dropTarget = getDropTargetElement(targetElement);
|
|
145
|
+
if (currentDropTarget && currentDropTarget !== dropTarget) {
|
|
146
|
+
currentDropTarget.classList.remove(DROP_TARGET_ACTIVE_CLASS);
|
|
147
|
+
}
|
|
148
|
+
if (dropTarget) {
|
|
149
|
+
dropTarget.classList.add(DROP_TARGET_ACTIVE_CLASS);
|
|
150
|
+
currentDropTarget = dropTarget;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
currentDropTarget = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Export the handlers for use by Go via index.ts
|
|
157
|
+
export { handleDragEnter, handleDragLeave, handleDragOver };
|
|
158
|
+
// Private field names.
|
|
159
|
+
const callerSym = Symbol("caller");
|
|
160
|
+
class Window {
|
|
161
|
+
/**
|
|
162
|
+
* Initialises a window object with the specified name.
|
|
163
|
+
*
|
|
164
|
+
* @private
|
|
165
|
+
* @param name - The name of the target window.
|
|
166
|
+
*/
|
|
167
|
+
constructor(name = '') {
|
|
168
|
+
this[callerSym] = newRuntimeCaller(objectNames.Window, name);
|
|
169
|
+
// bind instance method to make them easily usable in event handlers
|
|
170
|
+
for (const method of Object.getOwnPropertyNames(Window.prototype)) {
|
|
171
|
+
if (method !== "constructor"
|
|
172
|
+
&& typeof this[method] === "function") {
|
|
173
|
+
this[method] = this[method].bind(this);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Gets the specified window.
|
|
179
|
+
*
|
|
180
|
+
* @param name - The name of the window to get.
|
|
181
|
+
* @returns The corresponding window object.
|
|
182
|
+
*/
|
|
183
|
+
Get(name) {
|
|
184
|
+
return new Window(name);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Returns the absolute position of the window.
|
|
188
|
+
*
|
|
189
|
+
* @returns The current absolute position of the window.
|
|
190
|
+
*/
|
|
191
|
+
Position() {
|
|
192
|
+
return this[callerSym](PositionMethod);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Centers the window on the screen.
|
|
196
|
+
*/
|
|
197
|
+
Center() {
|
|
198
|
+
return this[callerSym](CenterMethod);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Closes the window.
|
|
202
|
+
*/
|
|
203
|
+
Close() {
|
|
204
|
+
return this[callerSym](CloseMethod);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Disables min/max size constraints.
|
|
208
|
+
*/
|
|
209
|
+
DisableSizeConstraints() {
|
|
210
|
+
return this[callerSym](DisableSizeConstraintsMethod);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Enables min/max size constraints.
|
|
214
|
+
*/
|
|
215
|
+
EnableSizeConstraints() {
|
|
216
|
+
return this[callerSym](EnableSizeConstraintsMethod);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Focuses the window.
|
|
220
|
+
*/
|
|
221
|
+
Focus() {
|
|
222
|
+
return this[callerSym](FocusMethod);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Forces the window to reload the page assets.
|
|
226
|
+
*/
|
|
227
|
+
ForceReload() {
|
|
228
|
+
return this[callerSym](ForceReloadMethod);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Switches the window to fullscreen mode.
|
|
232
|
+
*/
|
|
233
|
+
Fullscreen() {
|
|
234
|
+
return this[callerSym](FullscreenMethod);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns the screen that the window is on.
|
|
238
|
+
*
|
|
239
|
+
* @returns The screen the window is currently on.
|
|
240
|
+
*/
|
|
241
|
+
GetScreen() {
|
|
242
|
+
return this[callerSym](GetScreenMethod);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Returns the current zoom level of the window.
|
|
246
|
+
*
|
|
247
|
+
* @returns The current zoom level.
|
|
248
|
+
*/
|
|
249
|
+
GetZoom() {
|
|
250
|
+
return this[callerSym](GetZoomMethod);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Returns the height of the window.
|
|
254
|
+
*
|
|
255
|
+
* @returns The current height of the window.
|
|
256
|
+
*/
|
|
257
|
+
Height() {
|
|
258
|
+
return this[callerSym](HeightMethod);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Hides the window.
|
|
262
|
+
*/
|
|
263
|
+
Hide() {
|
|
264
|
+
return this[callerSym](HideMethod);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Returns true if the window is focused.
|
|
268
|
+
*
|
|
269
|
+
* @returns Whether the window is currently focused.
|
|
270
|
+
*/
|
|
271
|
+
IsFocused() {
|
|
272
|
+
return this[callerSym](IsFocusedMethod);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Returns true if the window is fullscreen.
|
|
276
|
+
*
|
|
277
|
+
* @returns Whether the window is currently fullscreen.
|
|
278
|
+
*/
|
|
279
|
+
IsFullscreen() {
|
|
280
|
+
return this[callerSym](IsFullscreenMethod);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Returns true if the window is maximised.
|
|
284
|
+
*
|
|
285
|
+
* @returns Whether the window is currently maximised.
|
|
286
|
+
*/
|
|
287
|
+
IsMaximised() {
|
|
288
|
+
return this[callerSym](IsMaximisedMethod);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Returns true if the window is minimised.
|
|
292
|
+
*
|
|
293
|
+
* @returns Whether the window is currently minimised.
|
|
294
|
+
*/
|
|
295
|
+
IsMinimised() {
|
|
296
|
+
return this[callerSym](IsMinimisedMethod);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Maximises the window.
|
|
300
|
+
*/
|
|
301
|
+
Maximise() {
|
|
302
|
+
return this[callerSym](MaximiseMethod);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Minimises the window.
|
|
306
|
+
*/
|
|
307
|
+
Minimise() {
|
|
308
|
+
return this[callerSym](MinimiseMethod);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Returns the name of the window.
|
|
312
|
+
*
|
|
313
|
+
* @returns The name of the window.
|
|
314
|
+
*/
|
|
315
|
+
Name() {
|
|
316
|
+
return this[callerSym](NameMethod);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Opens the development tools pane.
|
|
320
|
+
*/
|
|
321
|
+
OpenDevTools() {
|
|
322
|
+
return this[callerSym](OpenDevToolsMethod);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Returns the relative position of the window to the screen.
|
|
326
|
+
*
|
|
327
|
+
* @returns The current relative position of the window.
|
|
328
|
+
*/
|
|
329
|
+
RelativePosition() {
|
|
330
|
+
return this[callerSym](RelativePositionMethod);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Reloads the page assets.
|
|
334
|
+
*/
|
|
335
|
+
Reload() {
|
|
336
|
+
return this[callerSym](ReloadMethod);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Returns true if the window is resizable.
|
|
340
|
+
*
|
|
341
|
+
* @returns Whether the window is currently resizable.
|
|
342
|
+
*/
|
|
343
|
+
Resizable() {
|
|
344
|
+
return this[callerSym](ResizableMethod);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Restores the window to its previous state if it was previously minimised, maximised or fullscreen.
|
|
348
|
+
*/
|
|
349
|
+
Restore() {
|
|
350
|
+
return this[callerSym](RestoreMethod);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Sets the absolute position of the window.
|
|
354
|
+
*
|
|
355
|
+
* @param x - The desired horizontal absolute position of the window.
|
|
356
|
+
* @param y - The desired vertical absolute position of the window.
|
|
357
|
+
*/
|
|
358
|
+
SetPosition(x, y) {
|
|
359
|
+
return this[callerSym](SetPositionMethod, { x, y });
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Sets the window to be always on top.
|
|
363
|
+
*
|
|
364
|
+
* @param alwaysOnTop - Whether the window should stay on top.
|
|
365
|
+
*/
|
|
366
|
+
SetAlwaysOnTop(alwaysOnTop) {
|
|
367
|
+
return this[callerSym](SetAlwaysOnTopMethod, { alwaysOnTop });
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Sets the background colour of the window.
|
|
371
|
+
*
|
|
372
|
+
* @param r - The desired red component of the window background.
|
|
373
|
+
* @param g - The desired green component of the window background.
|
|
374
|
+
* @param b - The desired blue component of the window background.
|
|
375
|
+
* @param a - The desired alpha component of the window background.
|
|
376
|
+
*/
|
|
377
|
+
SetBackgroundColour(r, g, b, a) {
|
|
378
|
+
return this[callerSym](SetBackgroundColourMethod, { r, g, b, a });
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Removes the window frame and title bar.
|
|
382
|
+
*
|
|
383
|
+
* @param frameless - Whether the window should be frameless.
|
|
384
|
+
*/
|
|
385
|
+
SetFrameless(frameless) {
|
|
386
|
+
return this[callerSym](SetFramelessMethod, { frameless });
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Disables the system fullscreen button.
|
|
390
|
+
*
|
|
391
|
+
* @param enabled - Whether the fullscreen button should be enabled.
|
|
392
|
+
*/
|
|
393
|
+
SetFullscreenButtonEnabled(enabled) {
|
|
394
|
+
return this[callerSym](SetFullscreenButtonEnabledMethod, { enabled });
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Sets the maximum size of the window.
|
|
398
|
+
*
|
|
399
|
+
* @param width - The desired maximum width of the window.
|
|
400
|
+
* @param height - The desired maximum height of the window.
|
|
401
|
+
*/
|
|
402
|
+
SetMaxSize(width, height) {
|
|
403
|
+
return this[callerSym](SetMaxSizeMethod, { width, height });
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Sets the minimum size of the window.
|
|
407
|
+
*
|
|
408
|
+
* @param width - The desired minimum width of the window.
|
|
409
|
+
* @param height - The desired minimum height of the window.
|
|
410
|
+
*/
|
|
411
|
+
SetMinSize(width, height) {
|
|
412
|
+
return this[callerSym](SetMinSizeMethod, { width, height });
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Sets the relative position of the window to the screen.
|
|
416
|
+
*
|
|
417
|
+
* @param x - The desired horizontal relative position of the window.
|
|
418
|
+
* @param y - The desired vertical relative position of the window.
|
|
419
|
+
*/
|
|
420
|
+
SetRelativePosition(x, y) {
|
|
421
|
+
return this[callerSym](SetRelativePositionMethod, { x, y });
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Sets whether the window is resizable.
|
|
425
|
+
*
|
|
426
|
+
* @param resizable - Whether the window should be resizable.
|
|
427
|
+
*/
|
|
428
|
+
SetResizable(resizable) {
|
|
429
|
+
return this[callerSym](SetResizableMethod, { resizable });
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Sets the size of the window.
|
|
433
|
+
*
|
|
434
|
+
* @param width - The desired width of the window.
|
|
435
|
+
* @param height - The desired height of the window.
|
|
436
|
+
*/
|
|
437
|
+
SetSize(width, height) {
|
|
438
|
+
return this[callerSym](SetSizeMethod, { width, height });
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Sets the title of the window.
|
|
442
|
+
*
|
|
443
|
+
* @param title - The desired title of the window.
|
|
444
|
+
*/
|
|
445
|
+
SetTitle(title) {
|
|
446
|
+
return this[callerSym](SetTitleMethod, { title });
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Sets the zoom level of the window.
|
|
450
|
+
*
|
|
451
|
+
* @param zoom - The desired zoom level.
|
|
452
|
+
*/
|
|
453
|
+
SetZoom(zoom) {
|
|
454
|
+
return this[callerSym](SetZoomMethod, { zoom });
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Shows the window.
|
|
458
|
+
*/
|
|
459
|
+
Show() {
|
|
460
|
+
return this[callerSym](ShowMethod);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Returns the size of the window.
|
|
464
|
+
*
|
|
465
|
+
* @returns The current size of the window.
|
|
466
|
+
*/
|
|
467
|
+
Size() {
|
|
468
|
+
return this[callerSym](SizeMethod);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Toggles the window between fullscreen and normal.
|
|
472
|
+
*/
|
|
473
|
+
ToggleFullscreen() {
|
|
474
|
+
return this[callerSym](ToggleFullscreenMethod);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Toggles the window between maximised and normal.
|
|
478
|
+
*/
|
|
479
|
+
ToggleMaximise() {
|
|
480
|
+
return this[callerSym](ToggleMaximiseMethod);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Toggles the window between frameless and normal.
|
|
484
|
+
*/
|
|
485
|
+
ToggleFrameless() {
|
|
486
|
+
return this[callerSym](ToggleFramelessMethod);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Un-fullscreens the window.
|
|
490
|
+
*/
|
|
491
|
+
UnFullscreen() {
|
|
492
|
+
return this[callerSym](UnFullscreenMethod);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Un-maximises the window.
|
|
496
|
+
*/
|
|
497
|
+
UnMaximise() {
|
|
498
|
+
return this[callerSym](UnMaximiseMethod);
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Un-minimises the window.
|
|
502
|
+
*/
|
|
503
|
+
UnMinimise() {
|
|
504
|
+
return this[callerSym](UnMinimiseMethod);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Returns the width of the window.
|
|
508
|
+
*
|
|
509
|
+
* @returns The current width of the window.
|
|
510
|
+
*/
|
|
511
|
+
Width() {
|
|
512
|
+
return this[callerSym](WidthMethod);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Zooms the window.
|
|
516
|
+
*/
|
|
517
|
+
Zoom() {
|
|
518
|
+
return this[callerSym](ZoomMethod);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Increases the zoom level of the webview content.
|
|
522
|
+
*/
|
|
523
|
+
ZoomIn() {
|
|
524
|
+
return this[callerSym](ZoomInMethod);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Decreases the zoom level of the webview content.
|
|
528
|
+
*/
|
|
529
|
+
ZoomOut() {
|
|
530
|
+
return this[callerSym](ZoomOutMethod);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Resets the zoom level of the webview content.
|
|
534
|
+
*/
|
|
535
|
+
ZoomReset() {
|
|
536
|
+
return this[callerSym](ZoomResetMethod);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Handles file drops originating from platform-specific code (e.g., macOS/Linux native drag-and-drop).
|
|
540
|
+
* Gathers information about the drop target element and sends it back to the Go backend.
|
|
541
|
+
*
|
|
542
|
+
* @param filenames - An array of file paths (strings) that were dropped.
|
|
543
|
+
* @param x - The x-coordinate of the drop event (CSS pixels).
|
|
544
|
+
* @param y - The y-coordinate of the drop event (CSS pixels).
|
|
545
|
+
*/
|
|
546
|
+
HandlePlatformFileDrop(filenames, x, y) {
|
|
547
|
+
var _a, _b;
|
|
548
|
+
// Check if file drops are enabled for this window
|
|
549
|
+
if (((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.flags) === null || _b === void 0 ? void 0 : _b.enableFileDrop) === false) {
|
|
550
|
+
return; // File drops disabled, ignore the drop
|
|
551
|
+
}
|
|
552
|
+
const element = document.elementFromPoint(x, y);
|
|
553
|
+
const dropTarget = getDropTargetElement(element);
|
|
554
|
+
if (!dropTarget) {
|
|
555
|
+
// Drop was not on a designated drop target - ignore
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const elementDetails = {
|
|
559
|
+
id: dropTarget.id,
|
|
560
|
+
classList: Array.from(dropTarget.classList),
|
|
561
|
+
attributes: {},
|
|
562
|
+
};
|
|
563
|
+
for (let i = 0; i < dropTarget.attributes.length; i++) {
|
|
564
|
+
const attr = dropTarget.attributes[i];
|
|
565
|
+
elementDetails.attributes[attr.name] = attr.value;
|
|
566
|
+
}
|
|
567
|
+
const payload = {
|
|
568
|
+
filenames,
|
|
569
|
+
x,
|
|
570
|
+
y,
|
|
571
|
+
elementDetails,
|
|
572
|
+
};
|
|
573
|
+
this[callerSym](FilesDropped, payload);
|
|
574
|
+
// Clean up native drag state after drop
|
|
575
|
+
cleanupNativeDrag();
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Moves the window to the center of the specified screen's work area.
|
|
579
|
+
*
|
|
580
|
+
* @param screenID - The ID of the target screen.
|
|
581
|
+
*/
|
|
582
|
+
SetScreen(screenID) {
|
|
583
|
+
return this[callerSym](SetScreenMethod, { screenID });
|
|
584
|
+
}
|
|
585
|
+
/* Triggers Windows 11 Snap Assist feature (Windows only).
|
|
586
|
+
* This is equivalent to pressing Win+Z and shows snap layout options.
|
|
587
|
+
*/
|
|
588
|
+
SnapAssist() {
|
|
589
|
+
return this[callerSym](SnapAssistMethod);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Opens the print dialog for the window.
|
|
593
|
+
*/
|
|
594
|
+
Print() {
|
|
595
|
+
return this[callerSym](PrintMethod);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* The window within which the script is running.
|
|
600
|
+
*/
|
|
601
|
+
const thisWindow = new Window('');
|
|
602
|
+
/**
|
|
603
|
+
* Sets up global drag and drop event listeners for file drops.
|
|
604
|
+
* Handles visual feedback (hover state) and file drop processing.
|
|
605
|
+
*/
|
|
606
|
+
function setupDropTargetListeners() {
|
|
607
|
+
const docElement = document.documentElement;
|
|
608
|
+
let dragEnterCounter = 0;
|
|
609
|
+
docElement.addEventListener('dragenter', (event) => {
|
|
610
|
+
var _a, _b, _c;
|
|
611
|
+
if (!((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.types.includes('Files'))) {
|
|
612
|
+
return; // Only handle file drags, let other drags pass through
|
|
613
|
+
}
|
|
614
|
+
event.preventDefault(); // Always prevent default to stop browser navigation
|
|
615
|
+
// On Windows, check if file drops are enabled for this window
|
|
616
|
+
if (((_c = (_b = window._wails) === null || _b === void 0 ? void 0 : _b.flags) === null || _c === void 0 ? void 0 : _c.enableFileDrop) === false) {
|
|
617
|
+
event.dataTransfer.dropEffect = 'none'; // Show "no drop" cursor
|
|
618
|
+
return; // File drops disabled, don't show hover effects
|
|
619
|
+
}
|
|
620
|
+
dragEnterCounter++;
|
|
621
|
+
const targetElement = document.elementFromPoint(event.clientX, event.clientY);
|
|
622
|
+
const dropTarget = getDropTargetElement(targetElement);
|
|
623
|
+
// Update hover state
|
|
624
|
+
if (currentDropTarget && currentDropTarget !== dropTarget) {
|
|
625
|
+
currentDropTarget.classList.remove(DROP_TARGET_ACTIVE_CLASS);
|
|
626
|
+
}
|
|
627
|
+
if (dropTarget) {
|
|
628
|
+
dropTarget.classList.add(DROP_TARGET_ACTIVE_CLASS);
|
|
629
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
630
|
+
currentDropTarget = dropTarget;
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
event.dataTransfer.dropEffect = 'none';
|
|
634
|
+
currentDropTarget = null;
|
|
635
|
+
}
|
|
636
|
+
}, false);
|
|
637
|
+
docElement.addEventListener('dragover', (event) => {
|
|
638
|
+
var _a, _b, _c;
|
|
639
|
+
if (!((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.types.includes('Files'))) {
|
|
640
|
+
return; // Only handle file drags
|
|
641
|
+
}
|
|
642
|
+
event.preventDefault(); // Always prevent default to stop browser navigation
|
|
643
|
+
// On Windows, check if file drops are enabled for this window
|
|
644
|
+
if (((_c = (_b = window._wails) === null || _b === void 0 ? void 0 : _b.flags) === null || _c === void 0 ? void 0 : _c.enableFileDrop) === false) {
|
|
645
|
+
event.dataTransfer.dropEffect = 'none'; // Show "no drop" cursor
|
|
646
|
+
return; // File drops disabled, don't show hover effects
|
|
647
|
+
}
|
|
648
|
+
// Update drop target as cursor moves
|
|
649
|
+
const targetElement = document.elementFromPoint(event.clientX, event.clientY);
|
|
650
|
+
const dropTarget = getDropTargetElement(targetElement);
|
|
651
|
+
if (currentDropTarget && currentDropTarget !== dropTarget) {
|
|
652
|
+
currentDropTarget.classList.remove(DROP_TARGET_ACTIVE_CLASS);
|
|
653
|
+
}
|
|
654
|
+
if (dropTarget) {
|
|
655
|
+
if (!dropTarget.classList.contains(DROP_TARGET_ACTIVE_CLASS)) {
|
|
656
|
+
dropTarget.classList.add(DROP_TARGET_ACTIVE_CLASS);
|
|
657
|
+
}
|
|
658
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
659
|
+
currentDropTarget = dropTarget;
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
event.dataTransfer.dropEffect = 'none';
|
|
663
|
+
currentDropTarget = null;
|
|
664
|
+
}
|
|
665
|
+
}, false);
|
|
666
|
+
docElement.addEventListener('dragleave', (event) => {
|
|
667
|
+
var _a, _b, _c;
|
|
668
|
+
if (!((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.types.includes('Files'))) {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
event.preventDefault(); // Always prevent default to stop browser navigation
|
|
672
|
+
// On Windows, check if file drops are enabled for this window
|
|
673
|
+
if (((_c = (_b = window._wails) === null || _b === void 0 ? void 0 : _b.flags) === null || _c === void 0 ? void 0 : _c.enableFileDrop) === false) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
// On Linux/WebKitGTK and macOS, dragleave fires immediately with relatedTarget=null when native
|
|
677
|
+
// drag handling is involved. Ignore these spurious events - we'll clean up on drop instead.
|
|
678
|
+
if (event.relatedTarget === null) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
dragEnterCounter--;
|
|
682
|
+
if (dragEnterCounter === 0 ||
|
|
683
|
+
(currentDropTarget && !currentDropTarget.contains(event.relatedTarget))) {
|
|
684
|
+
if (currentDropTarget) {
|
|
685
|
+
currentDropTarget.classList.remove(DROP_TARGET_ACTIVE_CLASS);
|
|
686
|
+
currentDropTarget = null;
|
|
687
|
+
}
|
|
688
|
+
dragEnterCounter = 0;
|
|
689
|
+
}
|
|
690
|
+
}, false);
|
|
691
|
+
docElement.addEventListener('drop', (event) => {
|
|
692
|
+
var _a, _b, _c;
|
|
693
|
+
if (!((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.types.includes('Files'))) {
|
|
694
|
+
return; // Only handle file drops
|
|
695
|
+
}
|
|
696
|
+
event.preventDefault(); // Always prevent default to stop browser navigation
|
|
697
|
+
// On Windows, check if file drops are enabled for this window
|
|
698
|
+
if (((_c = (_b = window._wails) === null || _b === void 0 ? void 0 : _b.flags) === null || _c === void 0 ? void 0 : _c.enableFileDrop) === false) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
dragEnterCounter = 0;
|
|
702
|
+
if (currentDropTarget) {
|
|
703
|
+
currentDropTarget.classList.remove(DROP_TARGET_ACTIVE_CLASS);
|
|
704
|
+
currentDropTarget = null;
|
|
705
|
+
}
|
|
706
|
+
// On Windows, handle file drops via JavaScript
|
|
707
|
+
// On macOS/Linux, native code will call HandlePlatformFileDrop
|
|
708
|
+
if (canResolveFilePaths()) {
|
|
709
|
+
const files = [];
|
|
710
|
+
if (event.dataTransfer.items) {
|
|
711
|
+
for (const item of event.dataTransfer.items) {
|
|
712
|
+
if (item.kind === 'file') {
|
|
713
|
+
const file = item.getAsFile();
|
|
714
|
+
if (file)
|
|
715
|
+
files.push(file);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
else if (event.dataTransfer.files) {
|
|
720
|
+
for (const file of event.dataTransfer.files) {
|
|
721
|
+
files.push(file);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (files.length > 0) {
|
|
725
|
+
resolveFilePaths(event.clientX, event.clientY, files);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}, false);
|
|
729
|
+
}
|
|
730
|
+
// Initialize listeners when the script loads
|
|
731
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
732
|
+
setupDropTargetListeners();
|
|
733
|
+
}
|
|
734
|
+
export default thisWindow;
|