nexfep 0.1.1 → 0.1.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.
Files changed (6) hide show
  1. package/LICENSE +20 -20
  2. package/README-CN.md +285 -285
  3. package/README.md +285 -285
  4. package/index.d.ts +45 -45
  5. package/index.js +121 -121
  6. package/package.json +35 -36
package/index.js CHANGED
@@ -102,118 +102,118 @@ class WindowPool {
102
102
  }
103
103
  async __injectControlFunctions(windowObj) {
104
104
  console.log("Create INJECT_CODE");
105
- const INJECT_CSS = `
106
- [nexfep-area-drag],
107
- [nexfep-area-drag] * {
108
- -webkit-app-region: drag;
109
- app-region: drag;
110
- }
111
-
112
- [nexfep-element-drag] {
113
- -webkit-app-region: drag;
114
- app-region: drag;
115
- }
116
-
117
- [nexfep-no-drag],
118
- [nexfep-no-drag] * {
119
- -webkit-app-region: no-drag !important;
120
- app-region: no-drag !important;
121
- }
122
-
123
- [nexfep-auto-drag],
124
- [nexfep-auto-drag] * {
125
- -webkit-app-region: drag;
126
- app-region: drag;
127
- }
128
-
129
- [nexfep-auto-drag] button,
130
- [nexfep-auto-drag] input,
131
- [nexfep-auto-drag] select,
132
- [nexfep-auto-drag] textarea,
133
- [nexfep-auto-drag] a {
134
- -webkit-app-region: no-drag;
135
- app-region: no-drag;
136
- }
105
+ const INJECT_CSS = `
106
+ [nexfep-area-drag],
107
+ [nexfep-area-drag] * {
108
+ -webkit-app-region: drag;
109
+ app-region: drag;
110
+ }
111
+
112
+ [nexfep-element-drag] {
113
+ -webkit-app-region: drag;
114
+ app-region: drag;
115
+ }
116
+
117
+ [nexfep-no-drag],
118
+ [nexfep-no-drag] * {
119
+ -webkit-app-region: no-drag !important;
120
+ app-region: no-drag !important;
121
+ }
122
+
123
+ [nexfep-auto-drag],
124
+ [nexfep-auto-drag] * {
125
+ -webkit-app-region: drag;
126
+ app-region: drag;
127
+ }
128
+
129
+ [nexfep-auto-drag] button,
130
+ [nexfep-auto-drag] input,
131
+ [nexfep-auto-drag] select,
132
+ [nexfep-auto-drag] textarea,
133
+ [nexfep-auto-drag] a {
134
+ -webkit-app-region: no-drag;
135
+ app-region: no-drag;
136
+ }
137
137
  `;
138
- const INJECT_CODE = `
139
- // 事件监听
140
- window.addEventListener("beforeunload", () => {
141
- const MessageBody = { type: 'NexfepBeforeUnload' }
142
- window.ipc.postMessage(JSON.stringify(MessageBody));
143
- });
144
-
145
- // 窗口控制函数
146
- window.close = () => {
147
- const MessageBody = { type: 'NexfepCloseWindow' }
148
- window.ipc.postMessage(JSON.stringify(MessageBody));
149
- };
150
-
151
- window.minimize = () => {
152
- const MessageBody = { type: 'NexfepMinimizeWindow' }
153
- window.ipc.postMessage(JSON.stringify(MessageBody));
154
- };
155
-
156
- window.unminimize = () => {
157
- const MessageBody = { type: 'NexfepUnMinimizeWindow' }
158
- window.ipc.postMessage(JSON.stringify(MessageBody));
159
- };
160
-
161
- window.maximize = () => {
162
- const MessageBody = { type: 'NexfepMaximizeWindow' }
163
- window.ipc.postMessage(JSON.stringify(MessageBody));
164
- };
165
-
166
- window.unmaximize = () => {
167
- const MessageBody = { type: 'NexfepUnMaximizeWindow' }
168
- window.ipc.postMessage(JSON.stringify(MessageBody));
169
- };
170
- window.setTitle = (title) => {
171
- const MessageBody = { type: 'NexfepSetTitle', title: title }
172
- window.ipc.postMessage(JSON.stringify(MessageBody));
173
- };
174
-
175
- window.openDevTools = () => {
176
- const MessageBody = { type: 'NexfepOpenDevTools' }
177
- window.ipc.postMessage(JSON.stringify(MessageBody));
178
- };
179
-
180
- window.closeDevTools = () => {
181
- const MessageBody = { type: 'NexfepCloseDevTools' }
182
- window.ipc.postMessage(JSON.stringify(MessageBody));
183
- };
184
-
185
- window.postMessage = (data) => {
186
- const MessageBody = { type: 'CustomMessage', data: data }
187
- window.ipc.postMessage(JSON.stringify(MessageBody));
188
- };
189
-
190
- window.eventCount = 0;
191
-
192
- window.invoke = async (event, data) => {
193
- const MessageBody = { type: 'NexfepInvoke', eventId: [${this.injectCount}, ++window.eventCount], event: event, data: data }
194
- window.ipc.postMessage(JSON.stringify(MessageBody));
195
- return new Promise((resolve, reject) => {
196
- window.addEventListener("nexfep-invoke-result-"+${this.injectCount}+"-"+window.eventCount, (event) => {
197
- window.removeEventListener("nexfep-invoke-result-"+${this.injectCount}+"-"+window.eventCount, event);
198
- if(event.detail){
199
- resolve(event.detail);
200
- }else{
201
- resolve();
202
- }
203
- });
204
- });
205
- }
206
-
207
- // 注入 CSS 样式
208
- const style = document.createElement('style');
209
- style.textContent = \`${INJECT_CSS}\`;
210
- document.head.appendChild(style);
211
-
212
- // 标记加载完成
213
- window.isNexfepLoadDone = true;
214
-
215
- // 触发加载完成事件
216
- window.dispatchEvent(new Event('nexfep-load-done'));
138
+ const INJECT_CODE = `
139
+ // 事件监听
140
+ window.addEventListener("beforeunload", () => {
141
+ const MessageBody = { type: 'NexfepBeforeUnload' }
142
+ window.ipc.postMessage(JSON.stringify(MessageBody));
143
+ });
144
+
145
+ // 窗口控制函数
146
+ window.close = () => {
147
+ const MessageBody = { type: 'NexfepCloseWindow' }
148
+ window.ipc.postMessage(JSON.stringify(MessageBody));
149
+ };
150
+
151
+ window.minimize = () => {
152
+ const MessageBody = { type: 'NexfepMinimizeWindow' }
153
+ window.ipc.postMessage(JSON.stringify(MessageBody));
154
+ };
155
+
156
+ window.unminimize = () => {
157
+ const MessageBody = { type: 'NexfepUnMinimizeWindow' }
158
+ window.ipc.postMessage(JSON.stringify(MessageBody));
159
+ };
160
+
161
+ window.maximize = () => {
162
+ const MessageBody = { type: 'NexfepMaximizeWindow' }
163
+ window.ipc.postMessage(JSON.stringify(MessageBody));
164
+ };
165
+
166
+ window.unmaximize = () => {
167
+ const MessageBody = { type: 'NexfepUnMaximizeWindow' }
168
+ window.ipc.postMessage(JSON.stringify(MessageBody));
169
+ };
170
+ window.setTitle = (title) => {
171
+ const MessageBody = { type: 'NexfepSetTitle', title: title }
172
+ window.ipc.postMessage(JSON.stringify(MessageBody));
173
+ };
174
+
175
+ window.openDevTools = () => {
176
+ const MessageBody = { type: 'NexfepOpenDevTools' }
177
+ window.ipc.postMessage(JSON.stringify(MessageBody));
178
+ };
179
+
180
+ window.closeDevTools = () => {
181
+ const MessageBody = { type: 'NexfepCloseDevTools' }
182
+ window.ipc.postMessage(JSON.stringify(MessageBody));
183
+ };
184
+
185
+ window.postMessage = (data) => {
186
+ const MessageBody = { type: 'CustomMessage', data: data }
187
+ window.ipc.postMessage(JSON.stringify(MessageBody));
188
+ };
189
+
190
+ window.eventCount = 0;
191
+
192
+ window.invoke = async (event, data) => {
193
+ const MessageBody = { type: 'NexfepInvoke', eventId: [${this.injectCount}, ++window.eventCount], event: event, data: data }
194
+ window.ipc.postMessage(JSON.stringify(MessageBody));
195
+ return new Promise((resolve, reject) => {
196
+ window.addEventListener("nexfep-invoke-result-"+${this.injectCount}+"-"+window.eventCount, (event) => {
197
+ window.removeEventListener("nexfep-invoke-result-"+${this.injectCount}+"-"+window.eventCount, event);
198
+ if(event.detail){
199
+ resolve(event.detail);
200
+ }else{
201
+ resolve();
202
+ }
203
+ });
204
+ });
205
+ }
206
+
207
+ // 注入 CSS 样式
208
+ const style = document.createElement('style');
209
+ style.textContent = \`${INJECT_CSS}\`;
210
+ document.head.appendChild(style);
211
+
212
+ // 标记加载完成
213
+ window.isNexfepLoadDone = true;
214
+
215
+ // 触发加载完成事件
216
+ window.dispatchEvent(new Event('nexfep-load-done'));
217
217
  `;
218
218
  console.log("Before inject code INJECT_CODE");
219
219
  await this.__injectCode(windowObj, INJECT_CODE);
@@ -230,12 +230,12 @@ class WindowPool {
230
230
  const dataText = data.body.toString();
231
231
  const dataObj = JSON.parse(dataText);
232
232
  if (dataObj.type == 'NexfepBeforeUnload') {
233
- webview.evaluateScript(`if(window?.isNexfepLoadDone){
234
- const MessageBody = { type: 'NexfepBeforeUnload' }
235
- window.ipc.postMessage(JSON.stringify(MessageBody));
236
- }else{
237
- const MessageBody = { type: 'NexfepLoadFalse' }
238
- window.ipc.postMessage(JSON.stringify(MessageBody));
233
+ webview.evaluateScript(`if(window?.isNexfepLoadDone){
234
+ const MessageBody = { type: 'NexfepBeforeUnload' }
235
+ window.ipc.postMessage(JSON.stringify(MessageBody));
236
+ }else{
237
+ const MessageBody = { type: 'NexfepLoadFalse' }
238
+ window.ipc.postMessage(JSON.stringify(MessageBody));
239
239
  }`);
240
240
  }
241
241
  else if (dataObj.type == 'NexfepLoadFalse') {
@@ -273,13 +273,13 @@ class WindowPool {
273
273
  handlers.forEach(async (handler) => {
274
274
  const result = await handler(dataObj.data);
275
275
  if (result) {
276
- webview.evaluateScript(`
277
- window.dispatchEvent(new Event('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(result)} }));
276
+ webview.evaluateScript(`
277
+ window.dispatchEvent(new Event('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(result)} }));
278
278
  `);
279
279
  }
280
280
  else {
281
- webview.evaluateScript(`
282
- window.dispatchEvent(new Event('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: undefined }));
281
+ webview.evaluateScript(`
282
+ window.dispatchEvent(new Event('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: undefined }));
283
283
  `);
284
284
  }
285
285
  });
package/package.json CHANGED
@@ -1,37 +1,36 @@
1
- {
2
- "name": "nexfep",
3
- "description": "A desktop application framework based on @webviewjs/webview",
4
- "repository": "https://github.com/nexfteam/Nexfep",
5
- "homepage": "https://github.com/nexfteam/Nexfep#readme",
6
- "bugs": {
7
- "url": "https://github.com/nexfteam/Nexfep/issues"
8
- },
9
- "keywords": [
10
- "desktop",
11
- "application",
12
- "framework",
13
- "@webviewjs/webview",
14
- "webview",
15
- "typescript"
16
- ],
17
- "version": "0.1.1",
18
- "type": "module",
19
- "packageManager": "pnpm@9.15.9",
20
- "main": "./index.js",
21
- "scripts": {
22
- "compile": "tsc"
23
- },
24
- "author": "nexfteam",
25
- "license": "MIT",
26
- "engines": {
27
- "node": ">=20.11.0"
28
- },
29
- "dependencies": {
30
- "@webviewjs/webview": "^0.1.0"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^22.0.0",
34
- "tsx": "^4.0.0",
35
- "typescript": "^5.0.0"
36
- }
1
+ {
2
+ "name": "nexfep",
3
+ "description": "A desktop application framework based on @webviewjs/webview",
4
+ "repository": "https://github.com/nexfteam/Nexfep",
5
+ "homepage": "https://github.com/nexfteam/Nexfep#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/nexfteam/Nexfep/issues"
8
+ },
9
+ "keywords": [
10
+ "desktop",
11
+ "application",
12
+ "framework",
13
+ "@webviewjs/webview",
14
+ "webview",
15
+ "typescript"
16
+ ],
17
+ "version": "0.1.2",
18
+ "type": "module",
19
+ "main": "./index.js",
20
+ "scripts": {
21
+ "compile": "tsc"
22
+ },
23
+ "author": "nexfteam",
24
+ "license": "MIT",
25
+ "engines": {
26
+ "node": ">=20.11.0"
27
+ },
28
+ "dependencies": {
29
+ "@webviewjs/webview": "^0.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.0.0",
33
+ "tsx": "^4.0.0",
34
+ "typescript": "^5.0.0"
35
+ }
37
36
  }