win_webview2 1.1.3 → 1.1.6

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 CHANGED
@@ -1,52 +1,185 @@
1
- # Win Webview2
1
+
2
+ ## win_webview2
2
3
 
3
- ## npm install
4
+ A lightweight Node.js module to build Windows desktop UIs using Microsoft WebView2. A minimal and tiny alternative to Electron for developers who need a simple web-based interface without the heavy Chromium overhead
5
+
4
6
 
5
- ```npm i win_webview2```
6
7
 
8
+ ## Installation
9
+ Install the package via npm:
7
10
 
8
- Win Webview2 is a GUI toolkit for building desktop applications with Node.js. It is similar to Electron but significantly smaller because Win Webview2 utilizes Microsoft WebView2, which is already installed on Windows 10 and later versions.
9
11
 
10
- ## Building the Application
12
+ ```sh
13
+ npm install win_webview2
14
+ ```
15
+
11
16
 
12
- Run the following command:
17
+ ## Interactive Project Management
18
+ The win_webview2 CLI is designed to be your single point of control for the entire development lifecycle.
19
+ ## 1. Scaffolding (First time)
20
+ To download the boilerplate and set up your project, simply run:
13
21
 
14
22
  ```sh
15
23
  npx win_webview2
16
- ```
24
+ ```
17
25
 
18
- A menu will appear in the terminal with the following options:
19
- - `init_webview2` Creates a configuration file in JSON format.
20
- - `deploy` – Builds the application from your Node.js project.
26
+ ## 2. Develop, Watch, and Build
27
+ After the initial setup, you don't need to remember complex commands. Just run the same command again:
21
28
 
22
- ## Example Configuration File
23
29
 
24
- ```json
25
- {
26
- "entry_point": "app.js",
27
- "appname": "openweb",
28
- "icon_path": "./icon.png",
29
- "outdir": "./dist"
30
- }
30
+
31
+ ```sh
32
+ npx win_webview2
31
33
  ```
32
34
 
33
- ## Open Webview Frome Node
35
+ What it does:
36
+ It opens an interactive menu where you can manage your project. You can simply use your arrow keys (↑/↓) to select common tasks:
37
+
38
+ * Watch Mode: Run and see changes in real-time.
39
+ * Build: Compile your application for production.
40
+ * Dev Tools: Open debugging utilities.
41
+
42
+
43
+ >Pro Tip: Just hit npx win_webview2, use the Up/Down arrows to pick your task,
44
+ >and press Enter. It's that simple!
45
+
46
+ ## Features
47
+
48
+ * Built-in Express Server: Easily serve your static HTML folders.
49
+ * Native UI Management: Control window states (maximize, minimize, move, resize).
50
+ * Native Dialogs: Access Windows Open File and Open Folder dialogs directly from the browser.
51
+ * Low-level API: Direct access to the native Node.js addon.
52
+
34
53
 
35
- ```js
36
- import { openDialogFile, openDialogFolder, openWeb } from 'win_webview2';
37
54
 
38
- function openWebview(address) {
39
- openWeb({
40
- height : 400,
55
+ ## Basic Usage (Server-side)
56
+
57
+ Use ww2_CreateServer to host your HTML files and initialize the WebView2 window.
58
+
59
+ ```ts
60
+
61
+ import { existsSync } from "node:fs";
62
+ import path from "node:path";
63
+ import { closeSplash, ww2_CreateServer } from "win_webview2/node"
64
+ // Determine your HTML folder path
65
+
66
+ let htmlFolder = (() => {
67
+ let result = path.join(__dirname, "html");
68
+ if (!existsSync(result)) {
69
+ result = path.join(process.cwd(), "assets/lib/html")
70
+ }
71
+ return result;
72
+ })();
73
+ // Create the server and UI
74
+
75
+ ww2_CreateServer({
76
+ port: 0, // 0 for auto-assign
77
+ uiConfig: {
41
78
  width: 800,
42
- kiosk : false,
43
- maximize : false,
44
- title : "auto",
45
- url : address,
46
- isDebugMode : false
47
- })
79
+ height: 400,
80
+ title: "Ww2 UI",
81
+ wclassname: "myuiclass",
82
+ isDebug: true,
83
+ isKiosk: false,
84
+ isMaximize: false,
85
+ },
86
+ onExpressCreate: (app) => {
87
+ // You can add custom express middlewares here
88
+ },
89
+ htmlfolder: htmlFolder
90
+ });
91
+ // Close splash screen if active
92
+ closeSplash();
93
+
94
+ ```
95
+
96
+
97
+
98
+ ------------------------------
99
+ ## Browser Integration (Client-side)
100
+ Once the server is running, you can interact with the native Windows layer using callWw2.
101
+
102
+ ```ts
103
+
104
+ import { callWw2 } from "win_webview2/browser"
105
+ // Open File Dialog
106
+ const openFile = async () => {
107
+ let r = await callWw2({
108
+ openFileDialog: {
109
+ filter: "All Files (*.*)|*.*",
110
+ ownerClassName: "myuiclass",
111
+ }
112
+ });
113
+ console.log("Selected file:", r.result);
114
+ };
115
+ // Window Controls (Close, Move, Resize, Max/Min)
116
+ const closeWindow = async () => {
117
+
118
+ await callWw2({
119
+ controlWindow: {
120
+ controlcmd: "close",
121
+ wndClassName: "myuiclass"
122
+ }
123
+ });
124
+ };
125
+
126
+ const resizeWindow = async () => {
127
+ await callWw2({
128
+ controlWindow: {
129
+ controlcmd: "resize",
130
+ wndClassName: "myuiclass",
131
+ width: 800,
132
+ height: 700
133
+ }
134
+ });
135
+ };
136
+
137
+ ```
138
+
139
+ ------------------------------
140
+
141
+ ## Low-Level API
142
+ If you need direct access to the native module (.node addon), you can use getModule.
143
+
144
+ ```ts
145
+
146
+ import { getModule } from "win_webview2/node";
147
+ async function runLowLevel() {
148
+ const ww2 = await getModule();
149
+
150
+ // Manual window control
151
+ ww2.controlWindow({
152
+ wndClassName: "myuiclass",
153
+ controlcmd: "maximize"
154
+ });
48
155
  }
49
156
 
50
157
  ```
51
158
 
52
- look at github examples folder for detail
159
+
160
+
161
+ ## Module Interfaces
162
+
163
+ ```ts
164
+
165
+ export interface WW2ControlWindowsArg {
166
+ wndClassName: string;
167
+ controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check";
168
+ left?: number;
169
+ top?: number;
170
+ height?: number;
171
+ width?: number;
172
+ }
173
+ interface Ww2Module {
174
+ openWeb: (arg: Ww2WebConfig) => void;
175
+ openFileDialog: (arg: WW2FileDialogArg) => void;
176
+ openFolderDialog: (arg: WW2FileDialogArg) => void;
177
+ controlWindow: (arg: WW2ControlWindowsArg) => void;
178
+ }
179
+
180
+ ```
181
+
182
+ ------------------------------
183
+ ## License
184
+ MIT
185
+
@@ -27,7 +27,27 @@ let ww2Choise = {
27
27
  }
28
28
  }
29
29
  };
30
+ async function fetchFromList() {
31
+ try {
32
+ console.log("get list example");
33
+ let url = "https://raw.githubusercontent.com/nnttoo/win_webview2/refs/heads/master/example/listexample.json";
34
+ let txt = await fetch(url);
35
+ let content = await txt.text();
36
+ let obj = JSON.parse(content);
37
+ for (let item of obj) {
38
+ ww2Choise[item.path] = {
39
+ description: item.desctiption,
40
+ fun: () => {
41
+ runCommand(`npx degit nnttoo/win_webview2/example/${item.path}#master ${item.path}`);
42
+ }
43
+ };
44
+ }
45
+ }
46
+ catch (error) {
47
+ }
48
+ }
30
49
  async function ww2Init() {
50
+ await fetchFromList();
31
51
  const response = await (0, prompts_1.default)({
32
52
  type: 'select',
33
53
  name: 'menu',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win_webview2",
3
- "version": "1.1.3",
3
+ "version": "1.1.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nnttoo/win_webview2"
@@ -5,21 +5,21 @@ import path from "path";
5
5
  import { exec, execSync } from "child_process";
6
6
  import { ConfigWW2 } from "../tsExport/ww2_config";
7
7
  import prompts from "prompts";
8
-
9
-
10
- function runCommand(command : string) {
11
- try {
12
- const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
13
- execSync(command, { stdio: 'inherit', shell: currentShell, killSignal : "SIGINT" });
14
- } catch (error) {
15
- console.error(`Command Error: ${command}`);
16
- process.exit();
17
- }
8
+
9
+
10
+ function runCommand(command: string) {
11
+ try {
12
+ const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
13
+ execSync(command, { stdio: 'inherit', shell: currentShell, killSignal: "SIGINT" });
14
+ } catch (error) {
15
+ console.error(`Command Error: ${command}`);
16
+ process.exit();
17
+ }
18
18
  }
19
19
 
20
20
  const jsonConfigFilePath = "./win_webview2.json";
21
21
  let mdirname = getWw2Dirname();
22
-
22
+
23
23
 
24
24
  interface ChoiseItem {
25
25
  fun: () => any;
@@ -33,9 +33,9 @@ let ww2Choise: WW2Choise = {
33
33
  "ww2_typescript": {
34
34
  description: "init win_webview2",
35
35
  fun: async () => {
36
- runCommand('npx degit nnttoo/win_webview2/example/ww2_typescript#master ww2_typescript')
36
+ runCommand('npx degit nnttoo/win_webview2/example/ww2_typescript#master ww2_typescript')
37
37
  }
38
- }
38
+ }
39
39
  }
40
40
 
41
41
 
@@ -43,36 +43,68 @@ type promChoise = {
43
43
  title: string,
44
44
  value: () => any,
45
45
  description: string,
46
- disable? :boolean
46
+ disable?: boolean
47
+ }
48
+
49
+ interface ListFromGithub {
50
+ path: string,
51
+ desctiption: string
52
+ }
53
+
54
+ async function fetchFromList() {
55
+ try {
56
+ console.log("get list example")
57
+ let url = "https://raw.githubusercontent.com/nnttoo/win_webview2/refs/heads/master/example/listexample.json";
58
+ let txt = await fetch(url);
59
+ let content = await txt.text();
60
+ let obj = JSON.parse(content) as ListFromGithub[];
61
+
62
+ for (let item of obj) {
63
+
64
+ ww2Choise[item.path] = {
65
+ description: item.desctiption,
66
+ fun: () => {
67
+ runCommand(`npx degit nnttoo/win_webview2/example/${item.path}#master ${item.path}`);
68
+ }
69
+ }
70
+
71
+ }
72
+ } catch (error) {
73
+
74
+ }
75
+
76
+
47
77
  }
48
78
 
49
79
  export async function ww2Init() {
50
- const response = await prompts({
51
- type: 'select',
52
- name: 'menu',
53
- message: 'Pick one example',
54
- instructions: '(Use arrow keys to navigate, press enter to select)',
55
- choices: (() => {
56
- let result: promChoise[] = [];
57
-
58
- for (let item in ww2Choise) {
59
- let val = ww2Choise[item];
60
-
61
- result.push({
62
- title: item,
63
- value: val.fun,
64
- description : val.description,
65
- });
66
- }
67
- return result;
68
-
69
-
70
- })(),
71
- });
72
- if (response && response.menu) {
73
-
74
- await response.menu();
75
- }
76
-
80
+ await fetchFromList();
81
+
82
+ const response = await prompts({
83
+ type: 'select',
84
+ name: 'menu',
85
+ message: 'Pick one example',
86
+ instructions: '(Use arrow keys to navigate, press enter to select)',
87
+ choices: (() => {
88
+ let result: promChoise[] = [];
89
+
90
+ for (let item in ww2Choise) {
91
+ let val = ww2Choise[item];
92
+
93
+ result.push({
94
+ title: item,
95
+ value: val.fun,
96
+ description: val.description,
97
+ });
98
+ }
99
+ return result;
100
+
101
+
102
+ })(),
103
+ });
104
+ if (response && response.menu) {
105
+
106
+ await response.menu();
107
+ }
108
+
77
109
 
78
110
  }