clickgo-native 0.0.6-dev6 → 0.0.8

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.
@@ -0,0 +1,21 @@
1
+ import * as libFs from './lib/fs';
2
+ export declare const fs: typeof libFs;
3
+ import * as libTool from './lib/tool';
4
+ export declare const tool: typeof libTool;
5
+ export declare abstract class AbstractBoot {
6
+ get isImmersion(): boolean;
7
+ get hasFrame(): boolean;
8
+ get isNoFormQuit(): boolean;
9
+ get platform(): NodeJS.Platform;
10
+ get token(): string;
11
+ abstract main(): void | Promise<void>;
12
+ run(path: string, opt?: {
13
+ 'frame'?: boolean;
14
+ 'quit'?: boolean;
15
+ }): void;
16
+ on(name: string, handler: (...param: any[]) => any | Promise<any>, once?: boolean): void;
17
+ once(name: string, handler: (...param: any[]) => any | Promise<any>): void;
18
+ off(name: string): void;
19
+ }
20
+ export declare function launcher(boot: AbstractBoot): void;
21
+ export declare function verifyToken(t: string): boolean;
package/dist/index.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -32,7 +42,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
42
  });
33
43
  };
34
44
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.verifyToken = exports.launcher = exports.AbstractBoot = exports.tool = exports.fs = void 0;
45
+ exports.AbstractBoot = exports.tool = exports.fs = void 0;
46
+ exports.launcher = launcher;
47
+ exports.verifyToken = verifyToken;
36
48
  const electron = __importStar(require("electron"));
37
49
  const path = __importStar(require("path"));
38
50
  const libFs = __importStar(require("./lib/fs"));
@@ -388,7 +400,6 @@ function launcher(boot) {
388
400
  return;
389
401
  });
390
402
  }
391
- exports.launcher = launcher;
392
403
  electron.Menu.setApplicationMenu(null);
393
404
  electron.ipcMain.handle('pre', function (e, name, ...param) {
394
405
  if (!methods[name]) {
@@ -406,7 +417,6 @@ function verifyToken(t) {
406
417
  }
407
418
  return true;
408
419
  }
409
- exports.verifyToken = verifyToken;
410
420
  function createForm(p) {
411
421
  const op = {
412
422
  'webPreferences': {
@@ -436,7 +446,7 @@ function createForm(p) {
436
446
  }
437
447
  form.show();
438
448
  });
439
- if (p.startsWith('https://')) {
449
+ if (p.startsWith('https://') || p.startsWith('http://')) {
440
450
  form.loadURL(p).catch(function (e) {
441
451
  throw e;
442
452
  });
@@ -0,0 +1,21 @@
1
+ export declare function refreshDrives(): Promise<void>;
2
+ export declare function getContent(path: string, options: {
3
+ 'encoding'?: BufferEncoding;
4
+ 'start'?: number;
5
+ 'end'?: number;
6
+ }): Promise<string | Buffer | null>;
7
+ export declare function putContent(path: string, data: string | Buffer, options: {
8
+ 'encoding'?: BufferEncoding;
9
+ 'mode'?: number;
10
+ 'flag'?: string;
11
+ }): Promise<boolean>;
12
+ export declare function readLink(path: string, encoding?: BufferEncoding): Promise<string | null>;
13
+ export declare function symlink(filePath: string, linkPath: string, type?: 'dir' | 'file' | 'junction'): Promise<boolean>;
14
+ export declare function unlink(path: string): Promise<boolean>;
15
+ export declare function stats(path: string): Promise<Record<string, any> | null>;
16
+ export declare function mkdir(path: string, mode: number): Promise<boolean>;
17
+ export declare function rmdir(path: string): Promise<boolean>;
18
+ export declare function chmod(path: string, mod: string | number): Promise<boolean>;
19
+ export declare function rename(oldPath: string, newPath: string): Promise<boolean>;
20
+ export declare function readDir(path: string, encoding?: BufferEncoding): Promise<any[]>;
21
+ export declare function copyFile(src: string, dest: string): Promise<boolean>;
package/dist/lib/fs.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -32,7 +42,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
42
  });
33
43
  };
34
44
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.copyFile = exports.readDir = exports.rename = exports.chmod = exports.rmdir = exports.mkdir = exports.stats = exports.unlink = exports.symlink = exports.readLink = exports.putContent = exports.getContent = exports.refreshDrives = void 0;
45
+ exports.refreshDrives = refreshDrives;
46
+ exports.getContent = getContent;
47
+ exports.putContent = putContent;
48
+ exports.readLink = readLink;
49
+ exports.symlink = symlink;
50
+ exports.unlink = unlink;
51
+ exports.stats = stats;
52
+ exports.mkdir = mkdir;
53
+ exports.rmdir = rmdir;
54
+ exports.chmod = chmod;
55
+ exports.rename = rename;
56
+ exports.readDir = readDir;
57
+ exports.copyFile = copyFile;
36
58
  const fs = __importStar(require("fs"));
37
59
  const tool = __importStar(require("./tool"));
38
60
  const platform = process.platform;
@@ -63,7 +85,6 @@ function refreshDrives() {
63
85
  }
64
86
  });
65
87
  }
66
- exports.refreshDrives = refreshDrives;
67
88
  function getContent(path, options) {
68
89
  return __awaiter(this, void 0, void 0, function* () {
69
90
  path = formatPath(path);
@@ -79,6 +100,9 @@ function getContent(path, options) {
79
100
  });
80
101
  const data = [];
81
102
  rs.on('data', function (chunk) {
103
+ if (!(chunk instanceof Buffer)) {
104
+ return;
105
+ }
82
106
  data.push(chunk);
83
107
  }).on('end', function () {
84
108
  const buf = Buffer.concat(data);
@@ -110,7 +134,6 @@ function getContent(path, options) {
110
134
  }
111
135
  });
112
136
  }
113
- exports.getContent = getContent;
114
137
  function putContent(path, data, options) {
115
138
  return __awaiter(this, void 0, void 0, function* () {
116
139
  path = formatPath(path);
@@ -123,7 +146,6 @@ function putContent(path, data, options) {
123
146
  }
124
147
  });
125
148
  }
126
- exports.putContent = putContent;
127
149
  function readLink(path, encoding) {
128
150
  return __awaiter(this, void 0, void 0, function* () {
129
151
  path = formatPath(path);
@@ -137,7 +159,6 @@ function readLink(path, encoding) {
137
159
  }
138
160
  });
139
161
  }
140
- exports.readLink = readLink;
141
162
  function symlink(filePath, linkPath, type) {
142
163
  return __awaiter(this, void 0, void 0, function* () {
143
164
  filePath = formatPath(filePath);
@@ -151,7 +172,6 @@ function symlink(filePath, linkPath, type) {
151
172
  }
152
173
  });
153
174
  }
154
- exports.symlink = symlink;
155
175
  function unlink(path) {
156
176
  return __awaiter(this, void 0, void 0, function* () {
157
177
  path = formatPath(path);
@@ -173,7 +193,6 @@ function unlink(path) {
173
193
  }
174
194
  });
175
195
  }
176
- exports.unlink = unlink;
177
196
  function stats(path) {
178
197
  return __awaiter(this, void 0, void 0, function* () {
179
198
  path = formatPath(path);
@@ -200,7 +219,6 @@ function stats(path) {
200
219
  }
201
220
  });
202
221
  }
203
- exports.stats = stats;
204
222
  function mkdir(path, mode) {
205
223
  return __awaiter(this, void 0, void 0, function* () {
206
224
  path = formatPath(path);
@@ -220,7 +238,6 @@ function mkdir(path, mode) {
220
238
  }
221
239
  });
222
240
  }
223
- exports.mkdir = mkdir;
224
241
  function rmdir(path) {
225
242
  return __awaiter(this, void 0, void 0, function* () {
226
243
  path = formatPath(path);
@@ -237,7 +254,6 @@ function rmdir(path) {
237
254
  }
238
255
  });
239
256
  }
240
- exports.rmdir = rmdir;
241
257
  function chmod(path, mod) {
242
258
  return __awaiter(this, void 0, void 0, function* () {
243
259
  path = formatPath(path);
@@ -250,7 +266,6 @@ function chmod(path, mod) {
250
266
  }
251
267
  });
252
268
  }
253
- exports.chmod = chmod;
254
269
  function rename(oldPath, newPath) {
255
270
  return __awaiter(this, void 0, void 0, function* () {
256
271
  oldPath = formatPath(oldPath);
@@ -264,7 +279,6 @@ function rename(oldPath, newPath) {
264
279
  }
265
280
  });
266
281
  }
267
- exports.rename = rename;
268
282
  function readDir(path, encoding) {
269
283
  return __awaiter(this, void 0, void 0, function* () {
270
284
  try {
@@ -307,7 +321,6 @@ function readDir(path, encoding) {
307
321
  }
308
322
  });
309
323
  }
310
- exports.readDir = readDir;
311
324
  function copyFile(src, dest) {
312
325
  return __awaiter(this, void 0, void 0, function* () {
313
326
  src = formatPath(src);
@@ -321,4 +334,3 @@ function copyFile(src, dest) {
321
334
  }
322
335
  });
323
336
  }
324
- exports.copyFile = copyFile;
@@ -0,0 +1 @@
1
+ export declare function sleep(ms: number): Promise<void>;
package/dist/lib/tool.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = void 0;
3
+ exports.sleep = sleep;
4
4
  function sleep(ms) {
5
5
  return new Promise(function (resolve) {
6
6
  setTimeout(function () {
@@ -8,4 +8,3 @@ function sleep(ms) {
8
8
  }, ms);
9
9
  });
10
10
  }
11
- exports.sleep = sleep;
package/dist/pre.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/pre.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  const electron = __importStar(require("electron"));
27
37
  electron.contextBridge.exposeInMainWorld('clickgoNative', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clickgo-native",
3
- "version": "0.0.6-dev6",
3
+ "version": "0.0.8",
4
4
  "description": "The software developed with ClickGo will run in Windows, Mac OS, Linux.",
5
5
  "keywords": [
6
6
  "clickgo",
@@ -16,12 +16,12 @@
16
16
  "devDependencies": {
17
17
  "@litert/eslint-plugin-rules": "^0.3.1",
18
18
  "@litert/loader": "^3.5.9",
19
- "@types/node": "^24.0.3",
19
+ "@types/node": "^24.0.13",
20
20
  "clickgo": "^3.16.16",
21
21
  "jszip": "^3.10.1",
22
22
  "typescript": "^5.8.3"
23
23
  },
24
24
  "dependencies": {
25
- "electron": "^36.4.0"
25
+ "electron": "^37.2.1"
26
26
  }
27
27
  }
@@ -0,0 +1,10 @@
1
+ import * as litertLoader from '@litert/loader';
2
+
3
+ declare global {
4
+ type ILoader = litertLoader.ILoader;
5
+ type ILoaderUrl = litertLoader.ILoaderUrl;
6
+
7
+ const loader: typeof litertLoader.loader;
8
+ const __invoke: typeof litertLoader.__invoke;
9
+ const __preprocess: typeof litertLoader.__preprocess;
10
+ }
package/dist/index.ts DELETED
@@ -1,537 +0,0 @@
1
- import * as electron from 'electron';
2
- import * as path from 'path';
3
- import * as libFs from './lib/fs';
4
- export const fs = libFs;
5
- import * as libTool from './lib/tool';
6
- export const tool = libTool;
7
-
8
- // npm publish --tag dev --access public
9
- // --- sass --watch dist/:dist/ --style compressed --no-source-map ---
10
-
11
- /** --- 是否是沉浸式的 --- */
12
- let isImmersion: boolean = false;
13
- // --- windows 下是且只会是沉浸式,其他系统以启动的第一个窗体为准绑定大小最小化最大化关闭等功能 ---
14
-
15
- /** --- 窗体是否含有 border 边框,有的话将不是沉浸式,也不会绑定任何窗体的大小和相关事件 --- */
16
- let hasFrame: boolean = false;
17
-
18
- /** --- 是否没有物理窗体时就主动退出软件(进程结束),如果不要窗体只有 node 的话,会用到 false 的情况 --- */
19
- let isNoFormQuit: boolean = true;
20
-
21
- /** --- 主窗体 --- */
22
- let form: electron.BrowserWindow | undefined;
23
-
24
- /** --- 当前设定的通讯 token --- */
25
- let token: string = '';
26
-
27
- /** --- 当前系统平台 --- */
28
- const platform: NodeJS.Platform = process.platform;
29
- // const platform: NodeJS.Platform = 'darwin';
30
-
31
- /** --- 监听前台的执行的方法,内置的方法,用户可调用方法自行添加 --- */
32
- const methods: Record<string, {
33
- 'once': boolean;
34
- 'handler': (...param: any[]) => any | Promise<any>;
35
- }> = {
36
- // --- 成功运行一个 task 后 init ---
37
- 'cg-init': {
38
- 'once': true,
39
- handler: function(t: string) {
40
- // --- t 是网页传来的 token ---
41
- if (!t || !form) {
42
- return;
43
- }
44
- form.resizable = true;
45
- token = t;
46
- }
47
- },
48
- // --- 完全退出软件进程 ---
49
- 'cg-quit': {
50
- 'once': false,
51
- handler: function(t: string): void {
52
- if (!t || !form) {
53
- return;
54
- }
55
- if (!verifyToken(t)) {
56
- return;
57
- }
58
- electron.app.quit();
59
- }
60
- },
61
- // --- 设置实体窗体大小,仅非沉浸式可设置 ---
62
- 'cg-set-size': {
63
- 'once': false,
64
- handler: function(t: string, width: number, height: number): void {
65
- if (isImmersion || !form || !width || !height) {
66
- return;
67
- }
68
- if (!verifyToken(t)) {
69
- return;
70
- }
71
- form.setSize(width, height);
72
- form.center();
73
- }
74
- },
75
- // --- 设置窗体最大化、最小化、还原,仅非 frame 可设置 ---
76
- 'cg-set-state': {
77
- 'once': false,
78
- handler: function(t: string, state: string): void {
79
- if (!hasFrame || !form || !state) {
80
- return;
81
- }
82
- if (!verifyToken(t)) {
83
- return;
84
- }
85
- switch (state) {
86
- case 'max': {
87
- form.maximize();
88
- break;
89
- }
90
- case 'min': {
91
- form.minimize();
92
- break;
93
- }
94
- default: {
95
- form.restore();
96
- }
97
- }
98
- }
99
- },
100
- // --- 激活窗体 ---
101
- 'cg-activate': {
102
- 'once': false,
103
- handler: function(t: string): void {
104
- if (!form) {
105
- return;
106
- }
107
- if (!verifyToken(t)) {
108
- return;
109
- }
110
- if (form.isMinimized()) {
111
- form.restore();
112
- }
113
- form.setAlwaysOnTop(true);
114
- form.show();
115
- form.focus();
116
- form.setAlwaysOnTop(false);
117
- },
118
- },
119
- // --- 关闭窗体(可能软件进程不会被退出) ---
120
- 'cg-close': {
121
- 'once': false,
122
- handler: function(t: string): void {
123
- if (!form) {
124
- return;
125
- }
126
- if (!verifyToken(t)) {
127
- return;
128
- }
129
- form.close();
130
- }
131
- },
132
- // --- 设置 IgnoreMouseEvents,仅限沉浸式 ---
133
- 'cg-mouse-ignore': {
134
- 'once': false,
135
- handler: function(t: string, val: boolean): void {
136
- if (!isImmersion || !form) {
137
- return;
138
- }
139
- if (!verifyToken(t)) {
140
- return;
141
- }
142
- if (val) {
143
- form.setIgnoreMouseEvents(true, { 'forward': true });
144
- }
145
- else {
146
- form.setIgnoreMouseEvents(false);
147
- }
148
- }
149
- },
150
- // --- 是否允许最大化 ---
151
- 'cg-maximizable': {
152
- 'once': false,
153
- handler: function(t: string, val: boolean): void {
154
- if (isImmersion || !form) {
155
- return;
156
- }
157
- if (!verifyToken(t)) {
158
- return;
159
- }
160
- form.setMaximizable(val);
161
- }
162
- },
163
-
164
- // --- fs 相关操作 ---
165
-
166
- 'cg-fs-getContent': {
167
- 'once': false,
168
- handler: async function(
169
- t: string,
170
- path: string,
171
- options: Record<string, any>
172
- ): Promise<string | Buffer | null> {
173
- if (!verifyToken(t)) {
174
- return null;
175
- }
176
- return libFs.getContent(path, options);
177
- }
178
- },
179
- 'cg-fs-putContent': {
180
- 'once': false,
181
- handler: async function(
182
- t: string, path: string, data: string | Buffer, options: Record<string, any>
183
- ): Promise<boolean> {
184
- if (!verifyToken(t)) {
185
- return false;
186
- }
187
- return fs.putContent(path, data, options);
188
- }
189
- },
190
- 'cg-fs-readLink': {
191
- 'once': false,
192
- handler: async function(t: string, path: string, encoding?: BufferEncoding): Promise<string | null> {
193
- if (!verifyToken(t)) {
194
- return null;
195
- }
196
- return fs.readLink(path, encoding);
197
- }
198
- },
199
- 'cg-fs-symlink': {
200
- 'once': false,
201
- handler: async function(t: string, filePath: string, linkPath: string, type?: 'dir' | 'file' | 'junction'): Promise<boolean> {
202
- if (!verifyToken(t)) {
203
- return false;
204
- }
205
- return fs.symlink(filePath, linkPath, type);
206
- }
207
- },
208
- 'cg-fs-unlink': {
209
- 'once': false,
210
- handler: async function(t: string, path: string): Promise<boolean> {
211
- if (!verifyToken(t)) {
212
- return false;
213
- }
214
- return fs.unlink(path);
215
- }
216
- },
217
- 'cg-fs-stats': {
218
- 'once': false,
219
- handler: async function(t: string, path: string): Promise<Record<string, any> | null> {
220
- if (!verifyToken(t)) {
221
- return null;
222
- }
223
- return fs.stats(path);
224
- }
225
- },
226
- 'cg-fs-mkdir': {
227
- 'once': false,
228
- handler: async function(t: string, path: string, mode: number): Promise<boolean> {
229
- if (!verifyToken(t)) {
230
- return false;
231
- }
232
- return fs.mkdir(path, mode);
233
- }
234
- },
235
- 'cg-fs-rmdir': {
236
- 'once': false,
237
- handler: async function(t: string, path: string): Promise<boolean> {
238
- if (!verifyToken(t)) {
239
- return false;
240
- }
241
- return fs.rmdir(path);
242
- }
243
- },
244
- 'cg-fs-chmod': {
245
- 'once': false,
246
- handler: async function(t: string, path: string, mod: string | number): Promise<boolean> {
247
- if (!verifyToken(t)) {
248
- return false;
249
- }
250
- return fs.chmod(path, mod);
251
- }
252
- },
253
- 'cg-fs-rename': {
254
- 'once': false,
255
- handler: async function(t: string, oldPath: string, newPath: string): Promise<boolean> {
256
- if (!verifyToken(t)) {
257
- return false;
258
- }
259
- return fs.rename(oldPath, newPath);
260
- }
261
- },
262
- 'cg-fs-readDir': {
263
- 'once': false,
264
- handler: async function(t: string, path: string, encoding?: BufferEncoding): Promise<any[]> {
265
- if (!verifyToken(t)) {
266
- return [];
267
- }
268
- return fs.readDir(path, encoding);
269
- }
270
- },
271
- 'cg-fs-copyFile': {
272
- 'once': false,
273
- handler: async function(t: string, src: string, dest: string): Promise<boolean> {
274
- if (!verifyToken(t)) {
275
- return false;
276
- }
277
- return fs.copyFile(src, dest);
278
- }
279
- },
280
-
281
- // --- 无需校验码 ---
282
-
283
- // --- 测试与 native 的连通性 ---
284
- 'cg-ping': {
285
- 'once': false,
286
- handler: function(t: string): string {
287
- // --- t 不是 token,传过来什么就会传回去 ---
288
- return 'pong: ' + t;
289
- }
290
- },
291
- // --- 判断窗体是否是最大化状态 ---
292
- 'cg-is-max': {
293
- 'once': false,
294
- handler: function(): boolean {
295
- return form?.isMaximized ? true : false;
296
- }
297
- }
298
- };
299
-
300
- /** --- 全局类 --- */
301
- export abstract class AbstractBoot {
302
-
303
- /**
304
- * --- 是否是沉浸式运行 ---
305
- */
306
- public get isImmersion(): boolean {
307
- return isImmersion;
308
- }
309
-
310
- /**
311
- * --- 是否含有实体窗体边框和标题 ---
312
- */
313
- public get hasFrame(): boolean {
314
- return hasFrame;
315
- }
316
-
317
- /**
318
- * --- 没有实体窗体时整个实体进程是不是会被结束 ---
319
- */
320
- public get isNoFormQuit(): boolean {
321
- return isNoFormQuit;
322
- }
323
-
324
- /**
325
- * --- 当前系统代号 ---
326
- */
327
- public get platform(): NodeJS.Platform {
328
- return platform;
329
- }
330
-
331
- /**
332
- * --- 当前的通讯 token ---
333
- */
334
- public get token(): string {
335
- return token;
336
- }
337
-
338
- /** --- 入口方法 --- */
339
- public abstract main(): void | Promise<void>;
340
-
341
- /**
342
- * --- 开始运行起来一个主实体窗体,整个进程本方法只能执行一次 ---
343
- * @param path 实体窗体网页路径
344
- * @param opt 参数
345
- */
346
- public run(path: string, opt: { 'frame'?: boolean; 'quit'?: boolean; } = {}): void {
347
- if (opt.frame !== undefined) {
348
- // --- 默认 false ---
349
- hasFrame = opt.frame;
350
- }
351
- if (opt.quit !== undefined) {
352
- // --- 默认 true ---
353
- isNoFormQuit = opt.quit;
354
- }
355
- // --- 判断是否是沉浸式 ---
356
- if (platform === 'win32') {
357
- // --- 是 Windows 才有可能是沉浸式 ---
358
- if (!hasFrame) {
359
- // --- 实体窗体没有边框,一定是沉浸式 ---
360
- isImmersion = true;
361
- }
362
- }
363
- // --- 创建实体窗体 ---
364
- createForm(path);
365
- // --- 监听所有实体窗体关闭事件 ---
366
- electron.app.on('window-all-closed', function(): void {
367
- if (isNoFormQuit) {
368
- electron.app.quit();
369
- }
370
- });
371
- // --- 软件被活动性激活的事件 ---
372
- electron.app.on('activate', function(): void {
373
- if (electron.BrowserWindow.getAllWindows().length > 0) {
374
- return;
375
- }
376
- createForm(path);
377
- // --- 成功运行一个 task 后再次添加 init ---
378
- methods['cg-init'] = {
379
- 'once': true,
380
- handler: function(t: string) {
381
- // --- t 是网页传来的 token ---
382
- if (!t || !form) {
383
- return;
384
- }
385
- form.resizable = true;
386
- token = t;
387
- }
388
- };
389
- });
390
- }
391
-
392
- /**
393
- * --- 绑定监听网页调用方法的方法 ---
394
- * @param name 方法名
395
- * @param handler 要执行的函数
396
- * @param once 是否只执行一次
397
- */
398
- public on(
399
- name: string,
400
- handler: (...param: any[]) => any | Promise<any>,
401
- once: boolean = false
402
- ): void {
403
- methods[name] = {
404
- 'once': once,
405
- 'handler': handler
406
- };
407
- }
408
-
409
- /**
410
- * --- 绑定监听网页调用方法的方法但只会执行一次 ---
411
- * @param name 方法名
412
- * @param handler 要执行的函数
413
- */
414
- public once(name: string, handler: (...param: any[]) => any | Promise<any>): void {
415
- this.on(name, handler, true);
416
- }
417
-
418
- /**
419
- * --- 解绑监听的方法 ---
420
- * @param name 方法名
421
- */
422
- public off(name: string): void {
423
- if (!methods[name]) {
424
- return;
425
- }
426
- delete methods[name];
427
- }
428
-
429
- }
430
-
431
- /** --- 用户调用运行 boot 类 --- */
432
- export function launcher(boot: AbstractBoot): void {
433
- (async function() {
434
- // --- 等到 native 环境装载完毕 ---
435
- await electron.app.whenReady();
436
- await fs.refreshDrives();
437
- // --- 执行回调 ---
438
- await boot.main();
439
- })().catch(function() {
440
- return;
441
- });
442
- }
443
-
444
- // --- 系统启动 ---
445
-
446
- electron.Menu.setApplicationMenu(null);
447
-
448
- // --- 实际用来监听网页传输过来的数据 ---
449
- electron.ipcMain.handle('pre', function(e: electron.IpcMainInvokeEvent, name: string, ...param: any[]): any {
450
- if (!methods[name]) {
451
- return;
452
- }
453
- const r = methods[name].handler(...param);
454
- if (methods[name].once) {
455
- delete methods[name];
456
- }
457
- return r;
458
- });
459
-
460
- /**
461
- * --- 验证 token 是否正确 ---
462
- * @param t 要验证的 token
463
- */
464
- export function verifyToken(t: string): boolean {
465
- if (t !== token) {
466
- return false;
467
- }
468
- return true;
469
- }
470
-
471
- /**
472
- * --- 内部调用用来创建实体窗体的函数 ---
473
- * @param p 窗体网页路径
474
- */
475
- function createForm(p: string): void {
476
- const op: Electron.BrowserWindowConstructorOptions = {
477
- 'webPreferences': {
478
- 'nodeIntegration': false,
479
- 'contextIsolation': true,
480
- 'preload': path.join(__dirname, '/pre.js')
481
- },
482
- 'width': hasFrame ? 800 : 500,
483
- 'height': hasFrame ? 700 : 300,
484
- 'frame': hasFrame,
485
- 'resizable': false,
486
- 'show': false,
487
- 'center': true,
488
- 'transparent': isImmersion ? true : false
489
- };
490
- form = new electron.BrowserWindow(op);
491
- form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' immersion/' + (isImmersion ? '1' : '0') + ' frame/' + (hasFrame ? '1' : '0');
492
- // form.webContents.openDevTools();
493
- form.once('ready-to-show', function(): void {
494
- if (!form) {
495
- return;
496
- }
497
- if (isImmersion) {
498
- // --- 沉浸式默认最大化 ---
499
- form.maximize();
500
- form.setIgnoreMouseEvents(true, { 'forward': true });
501
- }
502
- else {
503
- // --- 设置为第一个窗体的大小 ---
504
- }
505
- form.show();
506
- });
507
- if (p.startsWith('https://') || p.startsWith('http://')) {
508
- // --- 加载网页 ---
509
- form.loadURL(p).catch(function(e): void {
510
- throw e;
511
- });
512
- }
513
- else {
514
- // --- 加载本地文件 ---
515
- const lio = p.indexOf('?');
516
- const search = lio === -1 ? '' : p.slice(lio + 1);
517
- if (lio !== -1) {
518
- p = p.slice(0, lio);
519
- }
520
- form.loadFile(p, {
521
- 'search': search
522
- }).catch(function(e): void {
523
- throw e;
524
- });
525
- }
526
- form.on('close', function() {
527
- form = undefined;
528
- });
529
- // --- 最大化事件 ---
530
- form.on('maximize', function() {
531
- form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}') as any;
532
- });
533
- // --- 最大化还原 ---
534
- form.on('unmaximize', function() {
535
- form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}') as any;
536
- });
537
- }
package/dist/lib/fs.ts DELETED
@@ -1,284 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as tool from './tool';
3
-
4
- /** --- 当前系统平台 --- */
5
- const platform: NodeJS.Platform = process.platform;
6
-
7
- /** --- path 要额外处理一下,因为 windows 下可能有点不一样 --- */
8
- function formatPath(path: string): string {
9
- if (platform !== 'win32') {
10
- return path;
11
- }
12
- if (path === '/') {
13
- return path;
14
- }
15
- return path[1] + ':' + path.slice(2);
16
- }
17
-
18
- /** --- windows 下驱动器列表 --- */
19
- const drives: string[] = [];
20
-
21
- /** --- 更新 drives 列表 --- */
22
- export async function refreshDrives(): Promise<void> {
23
- if (platform !== 'win32') {
24
- return;
25
- }
26
- drives.length = 0;
27
- for (let i = 0; i < 26; ++i) {
28
- const char = String.fromCharCode(97 + i);
29
- try {
30
- await fs.promises.stat(char + ':/');
31
- drives.push(char);
32
- }
33
- catch {
34
- // --- 无所谓 ---
35
- }
36
- }
37
- }
38
-
39
- export async function getContent(
40
- path: string,
41
- options: {
42
- 'encoding'?: BufferEncoding;
43
- 'start'?: number;
44
- 'end'?: number;
45
- }
46
- ): Promise<string | Buffer | null> {
47
- path = formatPath(path);
48
- const encoding = options.encoding;
49
- const start = options.start;
50
- const end = options.end;
51
- if (start || end) {
52
- return new Promise(function(resolve) {
53
- const rs = fs.createReadStream(path, {
54
- 'encoding': encoding,
55
- 'start': start,
56
- 'end': end
57
- });
58
- const data: Buffer[] = [];
59
- rs.on('data', function(chunk: Buffer) {
60
- data.push(chunk);
61
- }).on('end', function() {
62
- const buf = Buffer.concat(data);
63
- if (encoding) {
64
- resolve(buf.toString());
65
- }
66
- else {
67
- resolve(buf);
68
- }
69
- }).on('error', function() {
70
- resolve(null);
71
- });
72
- });
73
- }
74
- else {
75
- try {
76
- if (encoding) {
77
- return await fs.promises.readFile(path, {
78
- 'encoding': encoding
79
- });
80
- }
81
- else {
82
- return await fs.promises.readFile(path);
83
- }
84
- }
85
- catch {
86
- return null;
87
- }
88
- }
89
- }
90
-
91
- export async function putContent(path: string, data: string | Buffer, options: {
92
- 'encoding'?: BufferEncoding;
93
- 'mode'?: number;
94
- 'flag'?: string;
95
- }): Promise<boolean> {
96
- path = formatPath(path);
97
- try {
98
- await fs.promises.writeFile(path, data, options);
99
- return true;
100
- }
101
- catch {
102
- return false;
103
- }
104
- }
105
-
106
- export async function readLink(path: string, encoding?: BufferEncoding): Promise<string | null> {
107
- path = formatPath(path);
108
- try {
109
- return await fs.promises.readlink(path, {
110
- 'encoding': encoding
111
- });
112
- }
113
- catch {
114
- return null;
115
- }
116
- }
117
-
118
- export async function symlink(filePath: string, linkPath: string, type?: 'dir' | 'file' | 'junction'): Promise<boolean> {
119
- filePath = formatPath(filePath);
120
- linkPath = formatPath(linkPath);
121
- try {
122
- await fs.promises.symlink(filePath, linkPath, type);
123
- return true;
124
- }
125
- catch {
126
- return false;
127
- }
128
- }
129
-
130
- export async function unlink(path: string): Promise<boolean> {
131
- path = formatPath(path);
132
- for (let i = 0; i <= 2; ++i) {
133
- try {
134
- await fs.promises.unlink(path);
135
- return true;
136
- }
137
- catch {
138
- await tool.sleep(250);
139
- }
140
- }
141
- try {
142
- await fs.promises.unlink(path);
143
- return true;
144
- }
145
- catch {
146
- return false;
147
- }
148
- }
149
-
150
- export async function stats(path: string): Promise<Record<string, any> | null> {
151
- path = formatPath(path);
152
- try {
153
- const item = await fs.promises.lstat(path);
154
- return {
155
- isFile: item.isFile(),
156
- isDirectory: item.isDirectory(),
157
- isSymbolicLink: item.isSymbolicLink(),
158
- 'size': item.size,
159
- 'blksize': item.blksize,
160
- 'atimeMs': item.atimeMs,
161
- 'mtimeMs': item.mtimeMs,
162
- 'ctimeMs': item.ctimeMs,
163
- 'birthtimeMs': item.birthtimeMs,
164
- 'atime': item.atime,
165
- 'mtime': item.mtime,
166
- 'ctime': item.ctime,
167
- 'birthtime': item.birthtime
168
- };
169
- }
170
- catch {
171
- return null;
172
- }
173
- }
174
-
175
- export async function mkdir(path: string, mode: number): Promise<boolean> {
176
- path = formatPath(path);
177
- const stats = await fs.promises.lstat(path);
178
- if (stats.isDirectory()) {
179
- return true;
180
- }
181
- // --- 深度创建目录 ---
182
- try {
183
- await fs.promises.mkdir(path, {
184
- 'recursive': true,
185
- 'mode': mode
186
- });
187
- return true;
188
- }
189
- catch {
190
- return false;
191
- }
192
- }
193
-
194
- export async function rmdir(path: string): Promise<boolean> {
195
- path = formatPath(path);
196
- const stats = await fs.promises.lstat(path);
197
- if (!stats.isDirectory()) {
198
- return true;
199
- }
200
- try {
201
- await fs.promises.rmdir(path);
202
- return true;
203
- }
204
- catch {
205
- return false;
206
- }
207
- }
208
-
209
- export async function chmod(path: string, mod: string | number): Promise<boolean> {
210
- path = formatPath(path);
211
- try {
212
- await fs.promises.chmod(path, mod);
213
- return true;
214
- }
215
- catch {
216
- return false;
217
- }
218
- }
219
-
220
- export async function rename(oldPath: string, newPath: string): Promise<boolean> {
221
- oldPath = formatPath(oldPath);
222
- newPath = formatPath(newPath);
223
- try {
224
- await fs.promises.rename(oldPath, newPath);
225
- return true;
226
- }
227
- catch {
228
- return false;
229
- }
230
- }
231
-
232
- export async function readDir(path: string, encoding?: BufferEncoding): Promise<any[]> {
233
- try {
234
- const list: any[] = [];
235
- if (platform === 'win32') {
236
- // --- 此处不能用 formatPath,因为还要读 drives ---
237
- if (path === '/') {
238
- for (const item of drives) {
239
- list.push({
240
- isFile: false,
241
- isDirectory: true,
242
- isSymbolicLink: false,
243
- 'name': item
244
- });
245
- }
246
- return list;
247
- }
248
- else {
249
- path = path[1] + ':' + path.slice(2);
250
- }
251
- }
252
- const dlist = await fs.promises.readdir(path, {
253
- 'encoding': encoding,
254
- 'withFileTypes': true
255
- });
256
- for (const item of dlist) {
257
- if (item.name === '.' || item.name === '..') {
258
- continue;
259
- }
260
- list.push({
261
- isFile: item.isFile(),
262
- isDirectory: item.isDirectory(),
263
- isSymbolicLink: item.isSymbolicLink(),
264
- 'name': item.name
265
- });
266
- }
267
- return list;
268
- }
269
- catch {
270
- return [];
271
- }
272
- }
273
-
274
- export async function copyFile(src: string, dest: string): Promise<boolean> {
275
- src = formatPath(src);
276
- dest = formatPath(dest);
277
- try {
278
- await fs.promises.copyFile(src, dest);
279
- return true;
280
- }
281
- catch {
282
- return false;
283
- }
284
- }
package/dist/lib/tool.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * --- 间隔一段时间 ---
3
- * @param ms 间隔毫秒
4
- */
5
- export function sleep(ms: number): Promise<void> {
6
- return new Promise(function(resolve) {
7
- setTimeout(function() {
8
- resolve();
9
- }, ms);
10
- });
11
- }
package/dist/pre.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as electron from 'electron';
2
-
3
- electron.contextBridge.exposeInMainWorld('clickgoNative', {
4
- invoke: function(name: string, ...param: any[]): Promise<void> {
5
- return electron.ipcRenderer.invoke('pre', name, ...param);
6
- }
7
- });