nexfep 0.4.4 → 0.5.1
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-CN.md +160 -118
- package/README.md +161 -121
- package/cli/build.mjs +108 -99
- package/cli/help.mjs +9 -9
- package/cli/index.mjs +13 -15
- package/cli/timeTyper.mjs +29 -29
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +31 -22
- package/src/Application.d.ts +6 -4
- package/src/Application.js +12 -5
- package/src/Logger.js +70 -64
- package/src/SingleInstance.d.ts +9 -0
- package/src/SingleInstance.js +17 -0
- package/src/Tray.d.ts +1 -1
- package/src/Tray.js +4 -4
- package/src/WindowManager.d.ts +9 -0
- package/src/WindowManager.js +80 -44
package/src/Logger.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import fs from
|
|
1
|
+
import fs from "fs";
|
|
2
2
|
class Logger {
|
|
3
3
|
logFilePath;
|
|
4
4
|
constructor(logFilePath) {
|
|
@@ -6,56 +6,56 @@ class Logger {
|
|
|
6
6
|
}
|
|
7
7
|
__formatConsoleArgs(args) {
|
|
8
8
|
if (!Array.isArray(args) || args.length === 0)
|
|
9
|
-
return
|
|
9
|
+
return "";
|
|
10
10
|
const template = args[0];
|
|
11
|
-
if (typeof template !==
|
|
12
|
-
return args.map(String).join(
|
|
11
|
+
if (typeof template !== "string" || !template.includes("%c")) {
|
|
12
|
+
return args.map(String).join(" ");
|
|
13
13
|
}
|
|
14
|
-
const RESET =
|
|
14
|
+
const RESET = "\x1b[0m";
|
|
15
15
|
const parts = template.split(/(%c)/);
|
|
16
16
|
let styleArgIndex = 1;
|
|
17
|
-
let result =
|
|
18
|
-
let currentAnsiStyle =
|
|
17
|
+
let result = "";
|
|
18
|
+
let currentAnsiStyle = "";
|
|
19
19
|
// 命名前景色映射
|
|
20
20
|
const fgColors = {
|
|
21
|
-
black:
|
|
22
|
-
red:
|
|
23
|
-
green:
|
|
24
|
-
yellow:
|
|
25
|
-
blue:
|
|
26
|
-
magenta:
|
|
27
|
-
cyan:
|
|
28
|
-
white:
|
|
29
|
-
gray:
|
|
30
|
-
grey:
|
|
31
|
-
lightred:
|
|
32
|
-
lightgreen:
|
|
33
|
-
lightyellow:
|
|
34
|
-
lightblue:
|
|
35
|
-
lightmagenta:
|
|
36
|
-
lightcyan:
|
|
37
|
-
lightwhite:
|
|
21
|
+
black: "\x1b[30m",
|
|
22
|
+
red: "\x1b[31m",
|
|
23
|
+
green: "\x1b[32m",
|
|
24
|
+
yellow: "\x1b[33m",
|
|
25
|
+
blue: "\x1b[34m",
|
|
26
|
+
magenta: "\x1b[35m",
|
|
27
|
+
cyan: "\x1b[36m",
|
|
28
|
+
white: "\x1b[37m",
|
|
29
|
+
gray: "\x1b[90m",
|
|
30
|
+
grey: "\x1b[90m",
|
|
31
|
+
lightred: "\x1b[91m",
|
|
32
|
+
lightgreen: "\x1b[92m",
|
|
33
|
+
lightyellow: "\x1b[93m",
|
|
34
|
+
lightblue: "\x1b[94m",
|
|
35
|
+
lightmagenta: "\x1b[95m",
|
|
36
|
+
lightcyan: "\x1b[96m",
|
|
37
|
+
lightwhite: "\x1b[97m",
|
|
38
38
|
};
|
|
39
39
|
// 命名背景色映射
|
|
40
40
|
const bgColors = {
|
|
41
|
-
black:
|
|
42
|
-
red:
|
|
43
|
-
green:
|
|
44
|
-
yellow:
|
|
45
|
-
blue:
|
|
46
|
-
magenta:
|
|
47
|
-
cyan:
|
|
48
|
-
white:
|
|
41
|
+
black: "\x1b[40m",
|
|
42
|
+
red: "\x1b[41m",
|
|
43
|
+
green: "\x1b[42m",
|
|
44
|
+
yellow: "\x1b[43m",
|
|
45
|
+
blue: "\x1b[44m",
|
|
46
|
+
magenta: "\x1b[45m",
|
|
47
|
+
cyan: "\x1b[46m",
|
|
48
|
+
white: "\x1b[47m",
|
|
49
49
|
};
|
|
50
50
|
// 文字样式:加粗、斜体、下划线
|
|
51
51
|
const textStyles = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
bold: "\x1b[1m",
|
|
53
|
+
"font-weight:bold": "\x1b[1m",
|
|
54
|
+
italic: "\x1b[3m",
|
|
55
|
+
"font-style:italic": "\x1b[3m",
|
|
56
|
+
underline: "\x1b[4m",
|
|
57
|
+
"text-decoration:underline": "\x1b[4m",
|
|
58
|
+
none: RESET,
|
|
59
59
|
};
|
|
60
60
|
/** hex/rgb 转 ANSI 24位真彩色 */
|
|
61
61
|
function colorToAnsi(colorVal, isBg = false) {
|
|
@@ -67,9 +67,12 @@ class Logger {
|
|
|
67
67
|
// hex #fff #ffffff
|
|
68
68
|
const hexReg = /^#([0-9a-f]{3}|[0-9a-f]{6})$/;
|
|
69
69
|
if (hexReg.test(val)) {
|
|
70
|
-
let hex = val.replace(
|
|
70
|
+
let hex = val.replace("#", "");
|
|
71
71
|
if (hex.length === 3)
|
|
72
|
-
hex = hex
|
|
72
|
+
hex = hex
|
|
73
|
+
.split("")
|
|
74
|
+
.map((c) => c + c)
|
|
75
|
+
.join("");
|
|
73
76
|
const r = parseInt(hex.slice(0, 2), 16);
|
|
74
77
|
const g = parseInt(hex.slice(2, 4), 16);
|
|
75
78
|
const b = parseInt(hex.slice(4, 6), 16);
|
|
@@ -82,30 +85,33 @@ class Logger {
|
|
|
82
85
|
const [, r, g, b] = rgbMatch;
|
|
83
86
|
return isBg ? `\x1b[48;2;${r};${g};${b}m` : `\x1b[38;2;${r};${g};${b}m`;
|
|
84
87
|
}
|
|
85
|
-
return
|
|
88
|
+
return "";
|
|
86
89
|
}
|
|
87
90
|
/** 解析CSS样式字符串为ANSI序列 */
|
|
88
91
|
function parseColorStyle(styleStr) {
|
|
89
92
|
if (!styleStr)
|
|
90
93
|
return RESET;
|
|
91
|
-
let ansi =
|
|
92
|
-
const rules = styleStr
|
|
94
|
+
let ansi = "";
|
|
95
|
+
const rules = styleStr
|
|
96
|
+
.split(";")
|
|
97
|
+
.map((s) => s.trim())
|
|
98
|
+
.filter(Boolean);
|
|
93
99
|
for (const rule of rules) {
|
|
94
|
-
const [prop, ...rest] = rule.split(
|
|
100
|
+
const [prop, ...rest] = rule.split(":");
|
|
95
101
|
const propKey = prop.trim().toLowerCase();
|
|
96
|
-
const value = rest.join(
|
|
102
|
+
const value = rest.join(":").trim().toLowerCase();
|
|
97
103
|
// 文字样式
|
|
98
104
|
if (textStyles[`${propKey}:${value}`] || textStyles[value]) {
|
|
99
105
|
ansi += textStyles[`${propKey}:${value}`] ?? textStyles[value];
|
|
100
106
|
continue;
|
|
101
107
|
}
|
|
102
108
|
// 前景色
|
|
103
|
-
if (propKey ===
|
|
109
|
+
if (propKey === "color") {
|
|
104
110
|
ansi += colorToAnsi(value, false);
|
|
105
111
|
continue;
|
|
106
112
|
}
|
|
107
113
|
// 背景色
|
|
108
|
-
if (propKey ===
|
|
114
|
+
if (propKey === "background" || propKey === "background-color") {
|
|
109
115
|
ansi += colorToAnsi(value, true);
|
|
110
116
|
continue;
|
|
111
117
|
}
|
|
@@ -113,14 +119,14 @@ class Logger {
|
|
|
113
119
|
return ansi;
|
|
114
120
|
}
|
|
115
121
|
for (const segment of parts) {
|
|
116
|
-
if (segment ===
|
|
122
|
+
if (segment === "%c") {
|
|
117
123
|
// 取出下一个样式参数,参数不足则重置样式
|
|
118
124
|
const styleStr = args[styleArgIndex];
|
|
119
125
|
styleArgIndex++;
|
|
120
|
-
currentAnsiStyle = parseColorStyle(String(styleStr ??
|
|
126
|
+
currentAnsiStyle = parseColorStyle(String(styleStr ?? ""));
|
|
121
127
|
}
|
|
122
128
|
else {
|
|
123
|
-
if (segment ===
|
|
129
|
+
if (segment === "")
|
|
124
130
|
continue;
|
|
125
131
|
if (currentAnsiStyle) {
|
|
126
132
|
result += currentAnsiStyle + segment;
|
|
@@ -136,54 +142,54 @@ class Logger {
|
|
|
136
142
|
// 剩余非样式参数直接拼接
|
|
137
143
|
const extraArgs = args.slice(styleArgIndex);
|
|
138
144
|
if (extraArgs.length) {
|
|
139
|
-
result +=
|
|
145
|
+
result += " " + extraArgs.map(String).join(" ");
|
|
140
146
|
}
|
|
141
147
|
return result;
|
|
142
148
|
}
|
|
143
149
|
__printLog(winid, type, args, colorANSI, colorRESET) {
|
|
144
150
|
if (this.logFilePath) {
|
|
145
|
-
fs.appendFileSync(this.logFilePath, `${new Date().toISOString()} [${winid}] ${type}: ${args.join(
|
|
151
|
+
fs.appendFileSync(this.logFilePath, `${new Date().toISOString()} [${winid}] ${type}: ${args.join(" ")}\n`);
|
|
146
152
|
}
|
|
147
|
-
console.log(`${colorANSI ||
|
|
153
|
+
console.log(`${colorANSI || ""}[${winid}] ${type}:${colorRESET || ""}`, this.__formatConsoleArgs(args));
|
|
148
154
|
}
|
|
149
155
|
log(args) {
|
|
150
156
|
if (Array.isArray(args)) {
|
|
151
|
-
this.__printLog(0,
|
|
157
|
+
this.__printLog(0, "Log", args);
|
|
152
158
|
}
|
|
153
159
|
else {
|
|
154
|
-
this.__printLog(0,
|
|
160
|
+
this.__printLog(0, "Log", [args]);
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
error(args) {
|
|
158
164
|
if (Array.isArray(args)) {
|
|
159
|
-
this.__printLog(0,
|
|
165
|
+
this.__printLog(0, "Error", args, "\x1b[31m", "\x1b[0m");
|
|
160
166
|
}
|
|
161
167
|
else {
|
|
162
|
-
this.__printLog(0,
|
|
168
|
+
this.__printLog(0, "Error", [args], "\x1b[31m", "\x1b[0m");
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
171
|
warn(args) {
|
|
166
172
|
if (Array.isArray(args)) {
|
|
167
|
-
this.__printLog(0,
|
|
173
|
+
this.__printLog(0, "Warn", args, "\x1b[33m", "\x1b[0m");
|
|
168
174
|
}
|
|
169
175
|
else {
|
|
170
|
-
this.__printLog(0,
|
|
176
|
+
this.__printLog(0, "Warn", [args], "\x1b[33m", "\x1b[0m");
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
179
|
info(args) {
|
|
174
180
|
if (Array.isArray(args)) {
|
|
175
|
-
this.__printLog(0,
|
|
181
|
+
this.__printLog(0, "Info", args, "\x1b[34m", "\x1b[0m");
|
|
176
182
|
}
|
|
177
183
|
else {
|
|
178
|
-
this.__printLog(0,
|
|
184
|
+
this.__printLog(0, "Info", [args], "\x1b[34m", "\x1b[0m");
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
debug(args) {
|
|
182
188
|
if (Array.isArray(args)) {
|
|
183
|
-
this.__printLog(0,
|
|
189
|
+
this.__printLog(0, "Debug", args, "\x1b[90m", "\x1b[0m");
|
|
184
190
|
}
|
|
185
191
|
else {
|
|
186
|
-
this.__printLog(0,
|
|
192
|
+
this.__printLog(0, "Debug", [args], "\x1b[90m", "\x1b[0m");
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
195
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SingleInstance } from "@nexfteam/single-instance";
|
|
2
|
+
class Locker {
|
|
3
|
+
locker;
|
|
4
|
+
constructor(appName) {
|
|
5
|
+
this.locker = new SingleInstance(appName);
|
|
6
|
+
}
|
|
7
|
+
lock() {
|
|
8
|
+
return this.locker.lock();
|
|
9
|
+
}
|
|
10
|
+
unlock() {
|
|
11
|
+
return this.locker.unlock();
|
|
12
|
+
}
|
|
13
|
+
whenLost(callback) {
|
|
14
|
+
this.locker.on("connection-attempt", callback);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export { Locker };
|
package/src/Tray.d.ts
CHANGED
package/src/Tray.js
CHANGED
|
@@ -12,13 +12,13 @@ class Tray {
|
|
|
12
12
|
tooltip: options.tooltip,
|
|
13
13
|
icon: options.icon,
|
|
14
14
|
menu: {
|
|
15
|
-
items: this.menuItems
|
|
16
|
-
}
|
|
15
|
+
items: this.menuItems,
|
|
16
|
+
},
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
__ErrorWhenDestroyed() {
|
|
20
20
|
if (this.destroyed) {
|
|
21
|
-
throw new Error(
|
|
21
|
+
throw new Error("Tray has been destroyed");
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
addMenuItem(item) {
|
|
@@ -28,7 +28,7 @@ class Tray {
|
|
|
28
28
|
}
|
|
29
29
|
removeMenuItem(id) {
|
|
30
30
|
this.__ErrorWhenDestroyed();
|
|
31
|
-
this.menuItems = this.menuItems.filter(item => item.id !== id);
|
|
31
|
+
this.menuItems = this.menuItems.filter((item) => item.id !== id);
|
|
32
32
|
this.tray.setMenu({ items: this.menuItems });
|
|
33
33
|
}
|
|
34
34
|
setMenuItems(items) {
|
package/src/WindowManager.d.ts
CHANGED
|
@@ -16,9 +16,18 @@ declare class Window {
|
|
|
16
16
|
minimize(): void;
|
|
17
17
|
unMaximize(): void;
|
|
18
18
|
unMinimize(): void;
|
|
19
|
+
isMaximized(): boolean;
|
|
20
|
+
isMinimized(): boolean;
|
|
21
|
+
toggleMaximize(): void;
|
|
22
|
+
toggleMinimize(): void;
|
|
19
23
|
openDevTools(): void;
|
|
20
24
|
closeDevTools(): void;
|
|
21
25
|
setSize(width: number, height: number): void;
|
|
26
|
+
getSize(): import("@webviewjs/webview").Dimensions;
|
|
27
|
+
setPosition(x: number, y: number): void;
|
|
28
|
+
getPosition(): import("@webviewjs/webview").Position;
|
|
29
|
+
isFocused(): boolean;
|
|
30
|
+
focus(): void;
|
|
22
31
|
hide(): void;
|
|
23
32
|
show(): void;
|
|
24
33
|
close(): void;
|
package/src/WindowManager.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from "./Logger.js";
|
|
2
|
-
import os from
|
|
3
|
-
import path from
|
|
4
|
-
import fs from
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import fs from "fs";
|
|
5
5
|
class Window {
|
|
6
6
|
window;
|
|
7
7
|
webview;
|
|
@@ -41,6 +41,28 @@ class Window {
|
|
|
41
41
|
unMinimize() {
|
|
42
42
|
this.window.setMinimized(false);
|
|
43
43
|
}
|
|
44
|
+
isMaximized() {
|
|
45
|
+
return this.window.isMaximized();
|
|
46
|
+
}
|
|
47
|
+
isMinimized() {
|
|
48
|
+
return this.window.isMinimized();
|
|
49
|
+
}
|
|
50
|
+
toggleMaximize() {
|
|
51
|
+
if (this.isMaximized()) {
|
|
52
|
+
this.unMaximize();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.maximize();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
toggleMinimize() {
|
|
59
|
+
if (this.isMinimized()) {
|
|
60
|
+
this.unMinimize();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.minimize();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
44
66
|
openDevTools() {
|
|
45
67
|
this.webview.openDevtools();
|
|
46
68
|
}
|
|
@@ -50,6 +72,22 @@ class Window {
|
|
|
50
72
|
setSize(width, height) {
|
|
51
73
|
this.window.setSize(width, height);
|
|
52
74
|
}
|
|
75
|
+
getSize() {
|
|
76
|
+
return this.window.getInnerSize();
|
|
77
|
+
}
|
|
78
|
+
setPosition(x, y) {
|
|
79
|
+
this.window.setPosition(x, y);
|
|
80
|
+
}
|
|
81
|
+
getPosition() {
|
|
82
|
+
return this.window.getPosition();
|
|
83
|
+
}
|
|
84
|
+
isFocused() {
|
|
85
|
+
return this.window.isFocused();
|
|
86
|
+
}
|
|
87
|
+
focus() {
|
|
88
|
+
this.window.setMinimized(false);
|
|
89
|
+
this.window.focus();
|
|
90
|
+
}
|
|
53
91
|
hide() {
|
|
54
92
|
this.window.hide();
|
|
55
93
|
this.isShow = false;
|
|
@@ -81,16 +119,16 @@ class WindowPool {
|
|
|
81
119
|
freeWindowCount;
|
|
82
120
|
global;
|
|
83
121
|
constructor(app, options) {
|
|
84
|
-
if (os.platform() ===
|
|
85
|
-
|
|
86
|
-
|
|
122
|
+
if (os.platform() === "win32") {
|
|
123
|
+
const userDataDir = options.WindowsWebview2UserDataFolder ||
|
|
124
|
+
path.join(process.env.LOCALAPPDATA || os.homedir(), "NexfepDevelopment.webview2-data");
|
|
87
125
|
if (!fs.existsSync(userDataDir)) {
|
|
88
126
|
fs.mkdirSync(userDataDir, { recursive: true });
|
|
89
127
|
}
|
|
90
128
|
process.env.WEBVIEW2_USER_DATA_FOLDER = userDataDir;
|
|
91
129
|
}
|
|
92
130
|
this.onCustomMessage = (window, data) => {
|
|
93
|
-
console.log(
|
|
131
|
+
console.log("Get Custom Message:", data, "from window", window.id);
|
|
94
132
|
};
|
|
95
133
|
this.handlers = new Map();
|
|
96
134
|
this.app = app;
|
|
@@ -139,13 +177,11 @@ class WindowPool {
|
|
|
139
177
|
}
|
|
140
178
|
`;
|
|
141
179
|
const INJECT_CODE = `
|
|
142
|
-
// 事件监听
|
|
143
180
|
window.addEventListener("beforeunload", () => {
|
|
144
181
|
const MessageBody = { type: 'NexfepBeforeUnload' }
|
|
145
182
|
window.ipc.postMessage(JSON.stringify(MessageBody));
|
|
146
183
|
});
|
|
147
184
|
|
|
148
|
-
// 窗口控制函数
|
|
149
185
|
window.close = () => {
|
|
150
186
|
const MessageBody = { type: 'NexfepCloseWindow' }
|
|
151
187
|
window.ipc.postMessage(JSON.stringify(MessageBody));
|
|
@@ -270,24 +306,24 @@ class WindowPool {
|
|
|
270
306
|
window.__originConsoleDebug(...args);
|
|
271
307
|
}
|
|
272
308
|
|
|
273
|
-
// 注入 CSS 样式
|
|
274
309
|
const style = document.createElement('style');
|
|
275
310
|
style.textContent = \`${INJECT_CSS}\`;
|
|
276
311
|
document.head.appendChild(style);
|
|
277
312
|
|
|
278
|
-
// 标记加载完成
|
|
279
313
|
window.isNexfepLoadDone = true;
|
|
280
314
|
|
|
281
|
-
// 触发加载完成事件
|
|
282
315
|
window.dispatchEvent(new CustomEvent('nexfep-load-done'));
|
|
283
316
|
`;
|
|
284
317
|
await this.__injectCode(windowObj, INJECT_CODE);
|
|
285
318
|
}
|
|
286
319
|
async __createNewWindowObj() {
|
|
287
|
-
return await new Promise((resolve
|
|
320
|
+
return await new Promise((resolve) => {
|
|
288
321
|
setImmediate(() => {
|
|
289
|
-
const window = this.app.createBrowserWindow({
|
|
290
|
-
|
|
322
|
+
const window = this.app.createBrowserWindow({
|
|
323
|
+
title: "Nexfep",
|
|
324
|
+
visible: false,
|
|
325
|
+
focused: false,
|
|
326
|
+
});
|
|
291
327
|
this.freeWindowCount++;
|
|
292
328
|
const webview = window.createWebview();
|
|
293
329
|
const windowObj = new Window(window, webview, ++this.windowCount, this);
|
|
@@ -295,7 +331,7 @@ class WindowPool {
|
|
|
295
331
|
webview.onIpcMessage((data) => {
|
|
296
332
|
const dataText = data.body.toString();
|
|
297
333
|
const dataObj = JSON.parse(dataText);
|
|
298
|
-
if (dataObj.type ==
|
|
334
|
+
if (dataObj.type == "NexfepBeforeUnload") {
|
|
299
335
|
webview.evaluateScript(`if(window?.isNexfepLoadDone){
|
|
300
336
|
const MessageBody = { type: 'NexfepBeforeUnload' }
|
|
301
337
|
window.ipc.postMessage(JSON.stringify(MessageBody));
|
|
@@ -304,37 +340,37 @@ class WindowPool {
|
|
|
304
340
|
window.ipc.postMessage(JSON.stringify(MessageBody));
|
|
305
341
|
}`);
|
|
306
342
|
}
|
|
307
|
-
else if (dataObj.type ==
|
|
343
|
+
else if (dataObj.type == "NexfepLoadFalse") {
|
|
308
344
|
this.__injectControlFunctions(windowObj);
|
|
309
345
|
}
|
|
310
|
-
else if (dataObj.type ==
|
|
346
|
+
else if (dataObj.type == "NexfepCloseWindow") {
|
|
311
347
|
this.closeWindow(windowObj);
|
|
312
348
|
}
|
|
313
|
-
else if (dataObj.type ==
|
|
349
|
+
else if (dataObj.type == "NexfepMinimizeWindow") {
|
|
314
350
|
window.setMinimized(true);
|
|
315
351
|
}
|
|
316
|
-
else if (dataObj.type ==
|
|
352
|
+
else if (dataObj.type == "NexfepUnMinimizeWindow") {
|
|
317
353
|
window.setMinimized(false);
|
|
318
354
|
}
|
|
319
|
-
else if (dataObj.type ==
|
|
355
|
+
else if (dataObj.type == "NexfepMaximizeWindow") {
|
|
320
356
|
window.setMaximized(true);
|
|
321
357
|
}
|
|
322
|
-
else if (dataObj.type ==
|
|
358
|
+
else if (dataObj.type == "NexfepUnMaximizeWindow") {
|
|
323
359
|
window.setMaximized(false);
|
|
324
360
|
}
|
|
325
|
-
else if (dataObj.type ==
|
|
361
|
+
else if (dataObj.type == "NexfepSetTitle") {
|
|
326
362
|
window.setTitle(dataObj.title);
|
|
327
363
|
}
|
|
328
|
-
else if (dataObj.type ==
|
|
364
|
+
else if (dataObj.type == "NexfepOpenDevTools") {
|
|
329
365
|
webview.openDevtools();
|
|
330
366
|
}
|
|
331
|
-
else if (dataObj.type ==
|
|
367
|
+
else if (dataObj.type == "NexfepCloseDevTools") {
|
|
332
368
|
webview.closeDevtools();
|
|
333
369
|
}
|
|
334
|
-
else if (dataObj.type ==
|
|
370
|
+
else if (dataObj.type == "CustomMessage") {
|
|
335
371
|
this.onCustomMessage(windowObj, dataObj.data);
|
|
336
372
|
}
|
|
337
|
-
else if (dataObj.type ==
|
|
373
|
+
else if (dataObj.type == "NexfepInvoke") {
|
|
338
374
|
const handlers = this.handlers.get(dataObj.event) || [];
|
|
339
375
|
handlers.forEach(async (handler) => {
|
|
340
376
|
const result = await handler(dataObj.data);
|
|
@@ -350,16 +386,16 @@ class WindowPool {
|
|
|
350
386
|
}
|
|
351
387
|
});
|
|
352
388
|
}
|
|
353
|
-
else if (dataObj.type ==
|
|
389
|
+
else if (dataObj.type == "NexfepSetGlobal") {
|
|
354
390
|
this.global.set(dataObj.name, dataObj.value);
|
|
355
391
|
}
|
|
356
|
-
else if (dataObj.type ==
|
|
392
|
+
else if (dataObj.type == "NexfepGetGlobal") {
|
|
357
393
|
const value = this.global.get(dataObj.name);
|
|
358
394
|
webview.evaluateScript(`
|
|
359
395
|
window.dispatchEvent(new CustomEvent('nexfep-get-global-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(value)} }));
|
|
360
396
|
`);
|
|
361
397
|
}
|
|
362
|
-
else if (dataObj.type ==
|
|
398
|
+
else if (dataObj.type == "NexfepBroadcast") {
|
|
363
399
|
this.windows.forEach(async (w) => {
|
|
364
400
|
if (w != windowObj && w.isOpen) {
|
|
365
401
|
w.webview.evaluateScript(`
|
|
@@ -368,7 +404,7 @@ class WindowPool {
|
|
|
368
404
|
}
|
|
369
405
|
});
|
|
370
406
|
}
|
|
371
|
-
else if (dataObj.type ==
|
|
407
|
+
else if (dataObj.type == "NexfepTell") {
|
|
372
408
|
this.windows.forEach(async (w) => {
|
|
373
409
|
if (w.id == dataObj.to) {
|
|
374
410
|
w.webview.evaluateScript(`
|
|
@@ -377,20 +413,20 @@ class WindowPool {
|
|
|
377
413
|
}
|
|
378
414
|
});
|
|
379
415
|
}
|
|
380
|
-
else if (dataObj.type ==
|
|
381
|
-
this.logger.__printLog(windowObj.id,
|
|
416
|
+
else if (dataObj.type == "NexfepConsoleLog") {
|
|
417
|
+
this.logger.__printLog(windowObj.id, "Log", dataObj.message);
|
|
382
418
|
}
|
|
383
|
-
else if (dataObj.type ==
|
|
384
|
-
this.logger.__printLog(windowObj.id,
|
|
419
|
+
else if (dataObj.type == "NexfepConsoleError") {
|
|
420
|
+
this.logger.__printLog(windowObj.id, "Error", dataObj.message, "\x1b[31m", "\x1b[0m");
|
|
385
421
|
}
|
|
386
|
-
else if (dataObj.type ==
|
|
387
|
-
this.logger.__printLog(windowObj.id,
|
|
422
|
+
else if (dataObj.type == "NexfepConsoleInfo") {
|
|
423
|
+
this.logger.__printLog(windowObj.id, "Info", dataObj.message, "\x1b[34m", "\x1b[0m");
|
|
388
424
|
}
|
|
389
|
-
else if (dataObj.type ==
|
|
390
|
-
this.logger.__printLog(windowObj.id,
|
|
425
|
+
else if (dataObj.type == "NexfepConsoleWarn") {
|
|
426
|
+
this.logger.__printLog(windowObj.id, "Warn", dataObj.message, "\x1b[33m", "\x1b[0m");
|
|
391
427
|
}
|
|
392
|
-
else if (dataObj.type ==
|
|
393
|
-
this.logger.__printLog(windowObj.id,
|
|
428
|
+
else if (dataObj.type == "NexfepConsoleDebug") {
|
|
429
|
+
this.logger.__printLog(windowObj.id, "Debug", dataObj.message, "\x1b[90m", "\x1b[0m");
|
|
394
430
|
}
|
|
395
431
|
});
|
|
396
432
|
resolve(windowObj);
|
|
@@ -398,7 +434,7 @@ class WindowPool {
|
|
|
398
434
|
});
|
|
399
435
|
}
|
|
400
436
|
async createWindow(isShow = true, isDecorated = true) {
|
|
401
|
-
const window = this.windows.find(w => w.isOpen === false) || await this.__createNewWindowObj();
|
|
437
|
+
const window = this.windows.find((w) => w.isOpen === false) || (await this.__createNewWindowObj());
|
|
402
438
|
this.freeWindowCount--;
|
|
403
439
|
if (window) {
|
|
404
440
|
window.isOpen = true;
|
|
@@ -427,10 +463,10 @@ class WindowPool {
|
|
|
427
463
|
}
|
|
428
464
|
}
|
|
429
465
|
async handle(event, callback) {
|
|
430
|
-
this.handlers.set(event, [...this.handlers.get(event) || [], callback]);
|
|
466
|
+
this.handlers.set(event, [...(this.handlers.get(event) || []), callback]);
|
|
431
467
|
}
|
|
432
468
|
async unhandle(event, callback) {
|
|
433
|
-
this.handlers.set(event, (this.handlers.get(event) || []).filter(c => c !== callback));
|
|
469
|
+
this.handlers.set(event, (this.handlers.get(event) || []).filter((c) => c !== callback));
|
|
434
470
|
}
|
|
435
471
|
}
|
|
436
472
|
export { WindowPool, Window };
|