ewvjs 1.0.0 → 1.0.2
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/README.md +141 -15
- package/dist/js/api.js +46 -0
- package/dist/webview.d.ts +1 -0
- package/dist/webview.d.ts.map +1 -1
- package/dist/webview.js +12 -4
- package/dist/window.d.ts +2 -1
- package/dist/window.d.ts.map +1 -1
- package/dist/window.js +40 -10
- package/native/WebView.dll +0 -0
- package/package.json +11 -13
- package/src/csharp/bin/Release/net10.0-windows/WebView.dll +0 -0
- package/src/csharp/bin/Release/net10.0-windows/WebView.pdb +0 -0
- package/bin/ewvjs-cli.js +0 -318
- package/lib/assets.js +0 -129
- package/lib/icon.js +0 -150
- package/lib/packager.js +0 -347
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<img width="786" height="593" alt="image" src="https://github.com/user-attachments/assets/94957de5-1abd-458f-84cf-43174e05015c" />
|
|
2
|
+
|
|
1
3
|
# ewvjs
|
|
2
4
|
|
|
3
5
|
**Embedded WebView for JavaScript**
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
- 🖱️ **Context Menus**: Customizable native right-click context menus.
|
|
13
15
|
- 📦 **Packaging**: Built-in CLI tool to package your app into a standalone executable.
|
|
14
16
|
- 🔧 **Native Bindings**: High-performance C# bindings via `node-api-dotnet`.
|
|
15
|
-
- 🖼️ **Customization**: Support for frameless windows, transparency,
|
|
17
|
+
- 🖼️ **Customization**: Support for frameless windows, transparency, vibrancy, and more.
|
|
16
18
|
|
|
17
19
|
## Installation
|
|
18
20
|
|
|
@@ -31,7 +33,6 @@ const { create_window, start } = require('ewvjs');
|
|
|
31
33
|
const win = create_window('My App', 'https://www.google.com', {
|
|
32
34
|
width: 1024,
|
|
33
35
|
height: 768,
|
|
34
|
-
dark_mode: true
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
// Run the window
|
|
@@ -83,13 +84,21 @@ Creates a new WebView window.
|
|
|
83
84
|
* `url` (string): The URL to load (http/https) or path to a local HTML file or HTML string.
|
|
84
85
|
* `options` (object): Configuration options.
|
|
85
86
|
|
|
87
|
+
### `start()`
|
|
88
|
+
|
|
89
|
+
Starts the application event loop. This keeps the Node.js process alive until all windows are closed.
|
|
90
|
+
|
|
91
|
+
### `expose(name, callback)`
|
|
92
|
+
|
|
93
|
+
Exposes a Node.js function to the frontend.
|
|
94
|
+
|
|
95
|
+
* `name` (string): The name of the function as it will appear in `window.ewvjs.api`.
|
|
96
|
+
* `callback` (function): The Node.js function to execute. Can be async.
|
|
97
|
+
|
|
86
98
|
### Window Options
|
|
87
99
|
|
|
88
100
|
```typescript
|
|
89
101
|
{
|
|
90
|
-
title?: string; // Window title (overrides create_window arg)
|
|
91
|
-
url?: string; // URL to load (overrides create_window arg)
|
|
92
|
-
html?: string; // HTML content to load directly
|
|
93
102
|
width?: number; // Window width
|
|
94
103
|
height?: number; // Window height
|
|
95
104
|
x?: number; // X position
|
|
@@ -124,20 +133,34 @@ Creates a new WebView window.
|
|
|
124
133
|
Once a window is created, you can control it using the returned `Window` instance:
|
|
125
134
|
|
|
126
135
|
* **Lifecycle**: `run()`, `close()`, `destroy()`
|
|
127
|
-
* **State**: `maximize()`, `minimize()`, `restore()`, `
|
|
136
|
+
* **State**: `maximize()`, `minimize()`, `restore()`, `hide()`, `focus()`, `show()`
|
|
128
137
|
* **Size & Position**:
|
|
129
138
|
* `getSize()`, `setSize(w, h)`, `resize(w, h)`
|
|
130
139
|
* `getPosition()`, `setPosition(x, y)`, `move(x, y)`
|
|
131
140
|
* **Interaction**:
|
|
132
141
|
* `setTitle(title)`
|
|
133
|
-
* `navigate(url)`
|
|
134
142
|
* `evaluate(script)`: Execute JavaScript in the WebView.
|
|
135
143
|
* `setIcon(path)`
|
|
136
144
|
* **Cookies**: `get_cookies()`, `set_cookie(...)`, `clear_cookies()`
|
|
137
145
|
|
|
138
146
|
### Custom Context Menus
|
|
139
147
|
|
|
140
|
-
Define native context menus using `on_context_menu
|
|
148
|
+
Define native context menus using `on_context_menu`. It should return an array of `ContextMenuItem` objects.
|
|
149
|
+
|
|
150
|
+
#### ContextMenuItem Interface
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
interface ContextMenuItem {
|
|
154
|
+
label?: string;
|
|
155
|
+
type?: 'normal' | 'separator' | 'checkbox' | 'submenu';
|
|
156
|
+
checked?: boolean;
|
|
157
|
+
enabled?: boolean;
|
|
158
|
+
submenu?: ContextMenuItem[];
|
|
159
|
+
click?: () => void;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Example:
|
|
141
164
|
|
|
142
165
|
```javascript
|
|
143
166
|
win.on_context_menu = (params) => {
|
|
@@ -149,19 +172,122 @@ win.on_context_menu = (params) => {
|
|
|
149
172
|
};
|
|
150
173
|
```
|
|
151
174
|
|
|
152
|
-
## CLI
|
|
175
|
+
## CLI Reference
|
|
176
|
+
|
|
177
|
+
`ewvjs` provides a command-line interface for creating and packaging applications.
|
|
178
|
+
|
|
179
|
+
### Installation
|
|
153
180
|
|
|
154
|
-
|
|
181
|
+
The CLI is included with the `ewvjs` package and can be run using `npx`:
|
|
155
182
|
|
|
156
183
|
```bash
|
|
157
|
-
npx ewvjs
|
|
184
|
+
npx ewvjs <command> [options]
|
|
158
185
|
```
|
|
159
186
|
|
|
187
|
+
### Commands
|
|
188
|
+
|
|
189
|
+
#### `init` - Initialize a New Project
|
|
190
|
+
|
|
191
|
+
Create a new ewvjs project with a sample application structure.
|
|
192
|
+
|
|
193
|
+
**Usage:**
|
|
194
|
+
```bash
|
|
195
|
+
npx ewvjs init [name]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Arguments:**
|
|
199
|
+
* `name` - Project name (default: `my-ewvjs-app`)
|
|
200
|
+
|
|
201
|
+
**Example:**
|
|
202
|
+
```bash
|
|
203
|
+
npx ewvjs init my-awesome-app
|
|
204
|
+
cd my-awesome-app
|
|
205
|
+
npm install
|
|
206
|
+
npm start
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
This creates:
|
|
210
|
+
* `package.json` - Project configuration with scripts
|
|
211
|
+
* `app.js` - Sample application with Node.js integration
|
|
212
|
+
* `assets/` - Directory for static assets
|
|
213
|
+
* `README.md` - Project documentation
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
#### `package` - Package Application
|
|
218
|
+
|
|
219
|
+
Package your ewvjs application into a standalone executable.
|
|
220
|
+
|
|
221
|
+
**Usage:**
|
|
222
|
+
```bash
|
|
223
|
+
npx ewvjs package <entry> [options]
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Arguments:**
|
|
227
|
+
* `entry` - Entry point JavaScript file (required, e.g., `app.js`)
|
|
228
|
+
|
|
160
229
|
**Options:**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
230
|
+
|
|
231
|
+
| Option | Alias | Description | Default |
|
|
232
|
+
|--------|-------|-------------|---------|
|
|
233
|
+
| `--output <name>` | `-o` | Output executable name (without .exe) | `app` |
|
|
234
|
+
| `--name <name>` | `-n` | Application name | `My App` |
|
|
235
|
+
| `--icon <file>` | `-i` | Path to application icon (.ico file) | None |
|
|
236
|
+
| `--assets <dir>` | `-a` | Assets directory to include in package | `./assets` |
|
|
237
|
+
| `--target <target>` | `-t` | Target platform | `node18-win-x64` |
|
|
238
|
+
| `--modules <modules>` | `-m` | Additional node modules to bundle (comma-separated) | None |
|
|
239
|
+
| `--compress` | | Compress executable with UPX | `false` |
|
|
240
|
+
| `--no-native` | | Skip bundling native DLLs (if already included) | Includes by default |
|
|
241
|
+
|
|
242
|
+
**Examples:**
|
|
243
|
+
|
|
244
|
+
Basic packaging:
|
|
245
|
+
```bash
|
|
246
|
+
npx ewvjs package app.js
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Full customization:
|
|
250
|
+
```bash
|
|
251
|
+
npx ewvjs package app.js \
|
|
252
|
+
--output myapp \
|
|
253
|
+
--name "My Application" \
|
|
254
|
+
--icon icon.ico \
|
|
255
|
+
--assets ./public \
|
|
256
|
+
--modules axios,lodash \
|
|
257
|
+
--compress
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Package with custom target:
|
|
261
|
+
```bash
|
|
262
|
+
npx ewvjs package app.js -o myapp -t node20-win-x64
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Output:**
|
|
266
|
+
|
|
267
|
+
The packaged application will be created in the `dist/` directory with:
|
|
268
|
+
* `<output>.exe` - Standalone executable
|
|
269
|
+
* Native WebView2 dependencies (unless `--no-native` is used)
|
|
270
|
+
* Bundled assets from the specified directory
|
|
271
|
+
|
|
272
|
+
**Notes:**
|
|
273
|
+
* Icon file must be in `.ico` format
|
|
274
|
+
* Additional modules should be listed without spaces: `axios,lodash,express`
|
|
275
|
+
* The `--compress` option requires UPX to be installed and available in PATH
|
|
276
|
+
* Default target `node18-win-x64` works with Node.js 18+ on 64-bit Windows
|
|
277
|
+
|
|
278
|
+
### Getting Help
|
|
279
|
+
|
|
280
|
+
Display available commands and options:
|
|
281
|
+
```bash
|
|
282
|
+
npx ewvjs --help
|
|
283
|
+
npx ewvjs package --help
|
|
284
|
+
npx ewvjs init --help
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Display version:
|
|
288
|
+
```bash
|
|
289
|
+
npx ewvjs --version
|
|
290
|
+
```
|
|
165
291
|
|
|
166
292
|
## License
|
|
167
293
|
|
package/dist/js/api.js
CHANGED
|
@@ -231,6 +231,15 @@ window.ewvjs = {
|
|
|
231
231
|
}
|
|
232
232
|
}, 10);
|
|
233
233
|
},
|
|
234
|
+
|
|
235
|
+
_callWindowMethod: function (methodName) {
|
|
236
|
+
var __id = (Math.random() + "").substring(2);
|
|
237
|
+
window.chrome.webview.postMessage([
|
|
238
|
+
'window_' + methodName,
|
|
239
|
+
'[]',
|
|
240
|
+
__id
|
|
241
|
+
]);
|
|
242
|
+
},
|
|
234
243
|
};
|
|
235
244
|
|
|
236
245
|
window.ewvjs._hookConsole = function () {
|
|
@@ -254,3 +263,40 @@ window.ewvjs._hookConsole = function () {
|
|
|
254
263
|
|
|
255
264
|
window.ewvjs._hookConsole();
|
|
256
265
|
window.ewvjs._hookDrag();
|
|
266
|
+
|
|
267
|
+
// Add window state methods directly to window object
|
|
268
|
+
window.close = function () {
|
|
269
|
+
window.ewvjs._callWindowMethod('close');
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
window.maximize = function () {
|
|
273
|
+
window.ewvjs._callWindowMethod('maximize');
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
window.restore = function () {
|
|
277
|
+
window.ewvjs._callWindowMethod('restore');
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
window.minimize = function () {
|
|
281
|
+
window.ewvjs._callWindowMethod('minimize');
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
window.focus = function () {
|
|
285
|
+
window.ewvjs._callWindowMethod('focus');
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
window.show = function () {
|
|
289
|
+
window.ewvjs._callWindowMethod('show');
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
window.hide = function () {
|
|
293
|
+
window.ewvjs._callWindowMethod('hide');
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
window.resize = function () {
|
|
297
|
+
window.ewvjs._callWindowMethod('resize');
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
window.move = function () {
|
|
301
|
+
window.ewvjs._callWindowMethod('move');
|
|
302
|
+
};
|
package/dist/webview.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class WebView {
|
|
|
9
9
|
private _startPromise;
|
|
10
10
|
private _resolveStart;
|
|
11
11
|
private _heartbeat;
|
|
12
|
+
private _resolveOnce;
|
|
12
13
|
constructor();
|
|
13
14
|
create_window(title: string, url_or_html?: string, options?: Partial<WindowOptions>): Window;
|
|
14
15
|
start(): Promise<void>;
|
package/dist/webview.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webview.d.ts","sourceRoot":"","sources":["../src/webview.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,OAAO;IAChB,QAAQ,EAAE,GAAG,CAAC;IACd,iBAAiB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,CAAM;IACpD,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,UAAU,CAA+B;;
|
|
1
|
+
{"version":3,"file":"webview.d.ts","sourceRoot":"","sources":["../src/webview.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,OAAO;IAChB,QAAQ,EAAE,GAAG,CAAC;IACd,iBAAiB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,CAAM;IACpD,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,YAAY,CAAkB;;IAUtC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAW,EAAE,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,MAAM;IAgB9F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,QAAQ;IAkBhB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI;IAIpC,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,OAAO,CAAC,mBAAmB;CAgC9B"}
|
package/dist/webview.js
CHANGED
|
@@ -19,6 +19,7 @@ class WebView {
|
|
|
19
19
|
this._startPromise = null;
|
|
20
20
|
this._resolveStart = null;
|
|
21
21
|
this._heartbeat = null;
|
|
22
|
+
this._resolveOnce = false;
|
|
22
23
|
if (process.platform === 'win32') {
|
|
23
24
|
this.platform = new windows_1.WindowsPlatform();
|
|
24
25
|
}
|
|
@@ -57,12 +58,15 @@ class WebView {
|
|
|
57
58
|
}
|
|
58
59
|
if (this._resolveStart) {
|
|
59
60
|
this._resolveStart();
|
|
61
|
+
this._resolveOnce = true;
|
|
60
62
|
this._resolveStart = null;
|
|
61
63
|
}
|
|
62
64
|
// Force exit after a short delay to ensure cleanup completes
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
if (this._resolveOnce) {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}, 100);
|
|
69
|
+
}
|
|
66
70
|
}
|
|
67
71
|
expose(name, func) {
|
|
68
72
|
this.exposed_functions[name] = func;
|
|
@@ -80,7 +84,11 @@ class WebView {
|
|
|
80
84
|
path: (_b = options.session) === null || _b === void 0 ? void 0 : _b.path,
|
|
81
85
|
envname: (_c = options.session) === null || _c === void 0 ? void 0 : _c.envname
|
|
82
86
|
}, jsCallback: this._handle_message.bind(this) }, options);
|
|
83
|
-
|
|
87
|
+
const urlRegex = /^(https?|file|data):/i;
|
|
88
|
+
const isUrl = urlRegex.test(url_or_html) ||
|
|
89
|
+
/^localhost(:\d+)?$/i.test(url_or_html) ||
|
|
90
|
+
/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?$/i.test(url_or_html);
|
|
91
|
+
if (isUrl) {
|
|
84
92
|
opts.url = url_or_html;
|
|
85
93
|
}
|
|
86
94
|
else {
|
package/dist/window.d.ts
CHANGED
|
@@ -7,11 +7,13 @@ export declare class Window {
|
|
|
7
7
|
private _resolveClosed;
|
|
8
8
|
private _menuCallbacks;
|
|
9
9
|
private _exposedFunctions;
|
|
10
|
+
private _isClosed;
|
|
10
11
|
on_context_menu: (items: any[]) => ContextMenuItem[] | null | Promise<ContextMenuItem[] | null>;
|
|
11
12
|
constructor(platform: any, options: WindowOptions, exposedFunctions: {
|
|
12
13
|
[key: string]: Function;
|
|
13
14
|
});
|
|
14
15
|
get closed(): Promise<void>;
|
|
16
|
+
get is_closed(): boolean;
|
|
15
17
|
run(): Promise<any>;
|
|
16
18
|
private _call;
|
|
17
19
|
evaluate_js(script: string): Promise<any>;
|
|
@@ -22,7 +24,6 @@ export declare class Window {
|
|
|
22
24
|
restore(): Promise<any>;
|
|
23
25
|
minimize(): Promise<any>;
|
|
24
26
|
focus(): Promise<any>;
|
|
25
|
-
blur(): Promise<any>;
|
|
26
27
|
show(): Promise<any>;
|
|
27
28
|
hide(): Promise<any>;
|
|
28
29
|
getSize(): Promise<any>;
|
package/dist/window.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../src/window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGzD,qBAAa,MAAM;IACf,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;IAEvB,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,iBAAiB,CAA8B;
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../src/window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGzD,qBAAa,MAAM;IACf,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;IAEvB,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,iBAAiB,CAA8B;IACvD,OAAO,CAAC,SAAS,CAAkB;IAEnC,eAAe,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,eAAe,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,CAAc;gBAEjG,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE;IAiBhG,IAAI,MAAM,kBAET;IAED,IAAI,SAAS,YAEZ;IAEK,GAAG;YAkBK,KAAK;IA+Bb,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIzC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAItC,KAAK;IAQL,OAAO;IAKP,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,KAAK;IACL,IAAI;IACJ,IAAI;IAGJ,OAAO;IACP,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAGrC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAIpC,WAAW;IACX,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAGhC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAIzB,YAAY;IACZ,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAIjC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAK5B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B,QAAQ,CAAC,KAAK,EAAE,MAAM;IAGtB,SAAS,CAAC,KAAK,EAAE,MAAM;IAKvB,aAAa;IACb,aAAa;IAGb,OAAO,CAAC,QAAQ,EAAE,MAAM;IAKxB,WAAW;IACX,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,EAAE,IAAI,GAAE,MAAY;IAG/E,aAAa;YAEL,WAAW;IA+CzB,OAAO,CAAC,YAAY;IAmBpB,OAAO,CAAC,gBAAgB;YAOV,kBAAkB;YAUlB,sBAAsB;YAmBtB,oBAAoB;YAMpB,kBAAkB;IAMhC,OAAO,CAAC,YAAY;CAkBvB"}
|
package/dist/window.js
CHANGED
|
@@ -14,6 +14,7 @@ const utils_1 = require("./utils");
|
|
|
14
14
|
class Window {
|
|
15
15
|
constructor(platform, options, exposedFunctions) {
|
|
16
16
|
this._menuCallbacks = new Map();
|
|
17
|
+
this._isClosed = false;
|
|
17
18
|
this.on_context_menu = () => null;
|
|
18
19
|
this.platform = platform;
|
|
19
20
|
this.options = Object.assign({}, options);
|
|
@@ -32,6 +33,9 @@ class Window {
|
|
|
32
33
|
get closed() {
|
|
33
34
|
return this._closedPromise;
|
|
34
35
|
}
|
|
36
|
+
get is_closed() {
|
|
37
|
+
return this._isClosed;
|
|
38
|
+
}
|
|
35
39
|
run() {
|
|
36
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
41
|
this.controller = yield this.platform.createWindow(this.options);
|
|
@@ -50,16 +54,31 @@ class Window {
|
|
|
50
54
|
}
|
|
51
55
|
_call(method_1) {
|
|
52
56
|
return __awaiter(this, arguments, void 0, function* (method, payload = null) {
|
|
57
|
+
if (this._isClosed) {
|
|
58
|
+
console.warn(`Cannot call ${method}: Window is closed`);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
53
61
|
if (!this.controller || !this.controller[method]) {
|
|
54
62
|
throw new Error(`Window not running or ${method} not supported`);
|
|
55
63
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
try {
|
|
65
|
+
const result = this.controller[method](payload);
|
|
66
|
+
// Check if method returns a Promise (node-api-dotnet JSCallback style)
|
|
67
|
+
if (result && typeof result.then === 'function') {
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
60
73
|
}
|
|
61
|
-
|
|
62
|
-
return
|
|
74
|
+
catch (err) {
|
|
75
|
+
// If window was closed mid-operation, mark as closed and return null
|
|
76
|
+
if (err && err.message && err.message.includes('Window not initialized')) {
|
|
77
|
+
this._isClosed = true;
|
|
78
|
+
console.warn(`Window was closed during ${method} call`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
63
82
|
}
|
|
64
83
|
});
|
|
65
84
|
}
|
|
@@ -76,7 +95,12 @@ class Window {
|
|
|
76
95
|
}
|
|
77
96
|
close() {
|
|
78
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
|
|
98
|
+
if (this._isClosed)
|
|
99
|
+
return;
|
|
100
|
+
this._isClosed = true;
|
|
101
|
+
const result = yield this._call('close');
|
|
102
|
+
this._resolveClosed();
|
|
103
|
+
return result;
|
|
80
104
|
});
|
|
81
105
|
}
|
|
82
106
|
destroy() {
|
|
@@ -97,9 +121,6 @@ class Window {
|
|
|
97
121
|
focus() {
|
|
98
122
|
return __awaiter(this, void 0, void 0, function* () { return this._call('focus'); });
|
|
99
123
|
}
|
|
100
|
-
blur() {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () { return this._call('blur'); });
|
|
102
|
-
}
|
|
103
124
|
show() {
|
|
104
125
|
return __awaiter(this, void 0, void 0, function* () { return this._call('show'); });
|
|
105
126
|
}
|
|
@@ -201,6 +222,7 @@ class Window {
|
|
|
201
222
|
const params = this._parseParams(rawParams);
|
|
202
223
|
// Handle special messages
|
|
203
224
|
if (funcName === 'closed') {
|
|
225
|
+
this._isClosed = true;
|
|
204
226
|
this._resolveClosed();
|
|
205
227
|
return null;
|
|
206
228
|
}
|
|
@@ -214,6 +236,14 @@ class Window {
|
|
|
214
236
|
if (funcName === 'context_menu_requested') {
|
|
215
237
|
return this._handleContextMenu(params);
|
|
216
238
|
}
|
|
239
|
+
// Handle window state methods
|
|
240
|
+
if (funcName.startsWith('window_')) {
|
|
241
|
+
const method = funcName.substring(7); // Remove 'window_' prefix
|
|
242
|
+
if (typeof this[method] === 'function') {
|
|
243
|
+
yield this[method]();
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
217
247
|
// Handle exposed function calls
|
|
218
248
|
return this._handleExposedFunction(funcName, params, id, exposedFunctions);
|
|
219
249
|
}
|
package/native/WebView.dll
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ewvjs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Embedded WebView for JavaScript -
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Embedded WebView for JavaScript - Edge WebView2 bindings for Node.js",
|
|
5
|
+
"workspaces": [
|
|
6
|
+
"packages/*"
|
|
7
|
+
],
|
|
5
8
|
"main": "./dist/index.js",
|
|
6
9
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"ewvjs": "./bin/ewvjs-cli.js"
|
|
9
|
-
},
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist/**/*",
|
|
18
18
|
"native/**/*",
|
|
19
|
-
"bin/**/*",
|
|
20
|
-
"lib/**/*",
|
|
21
19
|
"src/csharp/bin/Release/**/*",
|
|
22
20
|
"README.md",
|
|
23
21
|
"LICENSE"
|
|
@@ -39,19 +37,19 @@
|
|
|
39
37
|
],
|
|
40
38
|
"author": "miukyo",
|
|
41
39
|
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/miukyo/ewvjs"
|
|
43
|
+
},
|
|
42
44
|
"type": "commonjs",
|
|
43
45
|
"os": [
|
|
44
46
|
"win32"
|
|
45
47
|
],
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/node": "^25.2.0",
|
|
48
|
-
"@yao-pkg/pkg": "^6.12.0",
|
|
49
50
|
"typescript": "^5.9.3"
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"
|
|
53
|
-
"commander": "^12.1.0",
|
|
54
|
-
"node-api-dotnet": "^0.9.19",
|
|
55
|
-
"resedit": "^2.0.2"
|
|
53
|
+
"node-api-dotnet": "^0.9.19"
|
|
56
54
|
}
|
|
57
|
-
}
|
|
55
|
+
}
|
|
Binary file
|
|
Binary file
|