clickgo-native 0.0.1-dev → 0.0.3-dev3

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/lib/fs.js ADDED
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
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
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ 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;
36
+ const fs = __importStar(require("fs"));
37
+ const tool = __importStar(require("./tool"));
38
+ const platform = process.platform;
39
+ function formatPath(path) {
40
+ if (platform !== 'win32') {
41
+ return path;
42
+ }
43
+ if (path === '/') {
44
+ return path;
45
+ }
46
+ return path[1] + ':' + path.slice(2);
47
+ }
48
+ const drives = [];
49
+ function refreshDrives() {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (platform !== 'win32') {
52
+ return;
53
+ }
54
+ drives.length = 0;
55
+ for (let i = 0; i < 26; ++i) {
56
+ const char = String.fromCharCode(97 + i);
57
+ try {
58
+ yield fs.promises.stat(char + ':/');
59
+ drives.push(char);
60
+ }
61
+ catch (_a) {
62
+ }
63
+ }
64
+ });
65
+ }
66
+ exports.refreshDrives = refreshDrives;
67
+ function getContent(path, options) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ path = formatPath(path);
70
+ const encoding = options.encoding;
71
+ const start = options.start;
72
+ const end = options.end;
73
+ if (start || end) {
74
+ return new Promise(function (resolve) {
75
+ const rs = fs.createReadStream(path, {
76
+ 'encoding': encoding,
77
+ 'start': start,
78
+ 'end': end
79
+ });
80
+ const data = [];
81
+ rs.on('data', function (chunk) {
82
+ data.push(chunk);
83
+ }).on('end', function () {
84
+ const buf = Buffer.concat(data);
85
+ if (encoding) {
86
+ resolve(buf.toString());
87
+ }
88
+ else {
89
+ resolve(buf);
90
+ }
91
+ }).on('error', function () {
92
+ resolve(null);
93
+ });
94
+ });
95
+ }
96
+ else {
97
+ try {
98
+ if (encoding) {
99
+ return yield fs.promises.readFile(path, {
100
+ 'encoding': encoding
101
+ });
102
+ }
103
+ else {
104
+ return yield fs.promises.readFile(path);
105
+ }
106
+ }
107
+ catch (_a) {
108
+ return null;
109
+ }
110
+ }
111
+ });
112
+ }
113
+ exports.getContent = getContent;
114
+ function putContent(path, data, options) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ path = formatPath(path);
117
+ try {
118
+ yield fs.promises.writeFile(path, data, options);
119
+ return true;
120
+ }
121
+ catch (_a) {
122
+ return false;
123
+ }
124
+ });
125
+ }
126
+ exports.putContent = putContent;
127
+ function readLink(path, encoding) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ path = formatPath(path);
130
+ try {
131
+ return yield fs.promises.readlink(path, {
132
+ 'encoding': encoding
133
+ });
134
+ }
135
+ catch (_a) {
136
+ return null;
137
+ }
138
+ });
139
+ }
140
+ exports.readLink = readLink;
141
+ function symlink(filePath, linkPath, type) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ filePath = formatPath(filePath);
144
+ linkPath = formatPath(linkPath);
145
+ try {
146
+ yield fs.promises.symlink(filePath, linkPath, type);
147
+ return true;
148
+ }
149
+ catch (_a) {
150
+ return false;
151
+ }
152
+ });
153
+ }
154
+ exports.symlink = symlink;
155
+ function unlink(path) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ path = formatPath(path);
158
+ for (let i = 0; i <= 2; ++i) {
159
+ try {
160
+ yield fs.promises.unlink(path);
161
+ return true;
162
+ }
163
+ catch (_a) {
164
+ yield tool.sleep(250);
165
+ }
166
+ }
167
+ try {
168
+ yield fs.promises.unlink(path);
169
+ return true;
170
+ }
171
+ catch (_b) {
172
+ return false;
173
+ }
174
+ });
175
+ }
176
+ exports.unlink = unlink;
177
+ function stats(path) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ path = formatPath(path);
180
+ try {
181
+ const item = yield fs.promises.lstat(path);
182
+ return {
183
+ isFile: item.isFile(),
184
+ isDirectory: item.isDirectory(),
185
+ isSymbolicLink: item.isSymbolicLink(),
186
+ 'size': item.size,
187
+ 'blksize': item.blksize,
188
+ 'atimeMs': item.atimeMs,
189
+ 'mtimeMs': item.mtimeMs,
190
+ 'ctimeMs': item.ctimeMs,
191
+ 'birthtimeMs': item.birthtimeMs,
192
+ 'atime': item.atime,
193
+ 'mtime': item.mtime,
194
+ 'ctime': item.ctime,
195
+ 'birthtime': item.birthtime
196
+ };
197
+ }
198
+ catch (_a) {
199
+ return null;
200
+ }
201
+ });
202
+ }
203
+ exports.stats = stats;
204
+ function mkdir(path, mode) {
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ path = formatPath(path);
207
+ const stats = yield fs.promises.lstat(path);
208
+ if (stats.isDirectory()) {
209
+ return true;
210
+ }
211
+ try {
212
+ yield fs.promises.mkdir(path, {
213
+ 'recursive': true,
214
+ 'mode': mode
215
+ });
216
+ return true;
217
+ }
218
+ catch (_a) {
219
+ return false;
220
+ }
221
+ });
222
+ }
223
+ exports.mkdir = mkdir;
224
+ function rmdir(path) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ path = formatPath(path);
227
+ const stats = yield fs.promises.lstat(path);
228
+ if (!stats.isDirectory()) {
229
+ return true;
230
+ }
231
+ try {
232
+ yield fs.promises.rmdir(path);
233
+ return true;
234
+ }
235
+ catch (_a) {
236
+ return false;
237
+ }
238
+ });
239
+ }
240
+ exports.rmdir = rmdir;
241
+ function chmod(path, mod) {
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ path = formatPath(path);
244
+ try {
245
+ yield fs.promises.chmod(path, mod);
246
+ return true;
247
+ }
248
+ catch (_a) {
249
+ return false;
250
+ }
251
+ });
252
+ }
253
+ exports.chmod = chmod;
254
+ function rename(oldPath, newPath) {
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ oldPath = formatPath(oldPath);
257
+ newPath = formatPath(newPath);
258
+ try {
259
+ yield fs.promises.rename(oldPath, newPath);
260
+ return true;
261
+ }
262
+ catch (_a) {
263
+ return false;
264
+ }
265
+ });
266
+ }
267
+ exports.rename = rename;
268
+ function readDir(path, encoding) {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ try {
271
+ const list = [];
272
+ if (platform === 'win32') {
273
+ if (path === '/') {
274
+ for (const item of drives) {
275
+ list.push({
276
+ isFile: false,
277
+ isDirectory: true,
278
+ isSymbolicLink: false,
279
+ 'name': item
280
+ });
281
+ }
282
+ return list;
283
+ }
284
+ else {
285
+ path = path[1] + ':' + path.slice(2);
286
+ }
287
+ }
288
+ const dlist = yield fs.promises.readdir(path, {
289
+ 'encoding': encoding,
290
+ 'withFileTypes': true
291
+ });
292
+ for (const item of dlist) {
293
+ if (item.name === '.' || item.name === '..') {
294
+ continue;
295
+ }
296
+ list.push({
297
+ isFile: item.isFile(),
298
+ isDirectory: item.isDirectory(),
299
+ isSymbolicLink: item.isSymbolicLink(),
300
+ 'name': item.name
301
+ });
302
+ }
303
+ return list;
304
+ }
305
+ catch (_a) {
306
+ return [];
307
+ }
308
+ });
309
+ }
310
+ exports.readDir = readDir;
311
+ function copyFile(src, dest) {
312
+ return __awaiter(this, void 0, void 0, function* () {
313
+ src = formatPath(src);
314
+ dest = formatPath(dest);
315
+ try {
316
+ yield fs.promises.copyFile(src, dest);
317
+ return true;
318
+ }
319
+ catch (_a) {
320
+ return false;
321
+ }
322
+ });
323
+ }
324
+ exports.copyFile = copyFile;
package/dist/lib/fs.ts ADDED
@@ -0,0 +1,284 @@
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
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sleep = void 0;
4
+ function sleep(ms) {
5
+ return new Promise(function (resolve) {
6
+ setTimeout(function () {
7
+ resolve();
8
+ }, ms);
9
+ });
10
+ }
11
+ exports.sleep = sleep;
@@ -0,0 +1,11 @@
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.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
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
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const electron = __importStar(require("electron"));
27
+ electron.contextBridge.exposeInMainWorld('clickgoNative', {
28
+ invoke: function (name, ...param) {
29
+ return electron.ipcRenderer.invoke('pre', name, ...param);
30
+ }
31
+ });
package/dist/pre.ts ADDED
@@ -0,0 +1,7 @@
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clickgo-native",
3
- "version": "0.0.1-dev",
3
+ "version": "0.0.3-dev3",
4
4
  "description": "The software developed with ClickGo will run in Windows, Mac OS, Linux.",
5
5
  "keywords": [
6
6
  "clickgo",
@@ -14,15 +14,14 @@
14
14
  "native": "electron ./dist/test"
15
15
  },
16
16
  "devDependencies": {
17
- "@litert/loader": "^3.3.0",
18
- "@types/node": "^17.0.45",
19
- "@typescript-eslint/eslint-plugin": "^5.30.5",
20
- "@typescript-eslint/parser": "^5.30.5",
21
- "clickgo": "^3.0.3-dev4",
22
- "eslint": "^8.19.0",
23
- "typescript": "^4.7.4"
17
+ "@litert/eslint-plugin-rules": "^0.1.2",
18
+ "@litert/loader": "^3.4.6",
19
+ "@types/jszip": "^3.4.1",
20
+ "@types/node": "^18.11.14",
21
+ "clickgo": "^3.1.6-dev15",
22
+ "typescript": "^4.9.4"
24
23
  },
25
24
  "dependencies": {
26
- "electron": "^19.0.8"
25
+ "electron": "^22.0.2"
27
26
  }
28
27
  }