@electron-memory/monitor 0.2.0 → 0.2.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/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +97 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -206,6 +206,8 @@ interface MonitorConfig {
|
|
|
206
206
|
height: number;
|
|
207
207
|
/** 是否置顶,默认 false */
|
|
208
208
|
alwaysOnTop: boolean;
|
|
209
|
+
/** 打开看板时是否自动打开 DevTools,默认 false;为 true 或环境变量 LAUNCHER_MEMORY_MONITOR_DEVTOOLS=1 时开启 */
|
|
210
|
+
openDevToolsOnStart: boolean;
|
|
209
211
|
};
|
|
210
212
|
/** 给窗口进程打标签,方便识别 */
|
|
211
213
|
processLabels: Record<string, string>;
|
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,8 @@ interface MonitorConfig {
|
|
|
206
206
|
height: number;
|
|
207
207
|
/** 是否置顶,默认 false */
|
|
208
208
|
alwaysOnTop: boolean;
|
|
209
|
+
/** 打开看板时是否自动打开 DevTools,默认 false;为 true 或环境变量 LAUNCHER_MEMORY_MONITOR_DEVTOOLS=1 时开启 */
|
|
210
|
+
openDevToolsOnStart: boolean;
|
|
209
211
|
};
|
|
210
212
|
/** 给窗口进程打标签,方便识别 */
|
|
211
213
|
processLabels: Record<string, string>;
|
package/dist/index.js
CHANGED
|
@@ -1112,11 +1112,30 @@ var path3 = __toESM(require("path"));
|
|
|
1112
1112
|
|
|
1113
1113
|
// src/core/dashboard-protocol.ts
|
|
1114
1114
|
var import_electron2 = require("electron");
|
|
1115
|
+
var import_promises = require("fs/promises");
|
|
1115
1116
|
var path2 = __toESM(require("path"));
|
|
1116
|
-
var import_node_url = require("url");
|
|
1117
1117
|
var SCHEME = "emm-dashboard";
|
|
1118
1118
|
var privilegedRegistered = false;
|
|
1119
1119
|
var handlerRegistered = false;
|
|
1120
|
+
var MIME_BY_EXT = {
|
|
1121
|
+
".html": "text/html; charset=utf-8",
|
|
1122
|
+
".js": "text/javascript; charset=utf-8",
|
|
1123
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
1124
|
+
".css": "text/css; charset=utf-8",
|
|
1125
|
+
".json": "application/json",
|
|
1126
|
+
".map": "application/json",
|
|
1127
|
+
".svg": "image/svg+xml",
|
|
1128
|
+
".png": "image/png",
|
|
1129
|
+
".jpg": "image/jpeg",
|
|
1130
|
+
".jpeg": "image/jpeg",
|
|
1131
|
+
".gif": "image/gif",
|
|
1132
|
+
".webp": "image/webp",
|
|
1133
|
+
".ico": "image/x-icon",
|
|
1134
|
+
".woff": "font/woff",
|
|
1135
|
+
".woff2": "font/woff2",
|
|
1136
|
+
".ttf": "font/ttf",
|
|
1137
|
+
".txt": "text/plain; charset=utf-8"
|
|
1138
|
+
};
|
|
1120
1139
|
function isPathInsideRoot(filePath, root) {
|
|
1121
1140
|
const f = path2.resolve(filePath);
|
|
1122
1141
|
const r = path2.resolve(root);
|
|
@@ -1155,7 +1174,7 @@ function ensureDashboardProtocolHandler(uiRoot) {
|
|
|
1155
1174
|
}
|
|
1156
1175
|
handlerRegistered = true;
|
|
1157
1176
|
const base = path2.resolve(uiRoot);
|
|
1158
|
-
import_electron2.protocol.handle(SCHEME, (request) => {
|
|
1177
|
+
import_electron2.protocol.handle(SCHEME, async (request) => {
|
|
1159
1178
|
try {
|
|
1160
1179
|
const { pathname } = new URL(request.url);
|
|
1161
1180
|
let rel = pathname.startsWith("/") ? pathname.slice(1) : pathname;
|
|
@@ -1166,9 +1185,19 @@ function ensureDashboardProtocolHandler(uiRoot) {
|
|
|
1166
1185
|
if (!isPathInsideRoot(filePath, base)) {
|
|
1167
1186
|
return new Response("Forbidden", { status: 403 });
|
|
1168
1187
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1188
|
+
const body = await (0, import_promises.readFile)(filePath);
|
|
1189
|
+
const ext = path2.extname(filePath).toLowerCase();
|
|
1190
|
+
const mime = MIME_BY_EXT[ext] || "application/octet-stream";
|
|
1191
|
+
return new Response(body, {
|
|
1192
|
+
status: 200,
|
|
1193
|
+
headers: {
|
|
1194
|
+
"Content-Type": mime,
|
|
1195
|
+
"Cache-Control": "no-store"
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
} catch (err) {
|
|
1199
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1200
|
+
return new Response(msg, { status: 404 });
|
|
1172
1201
|
}
|
|
1173
1202
|
});
|
|
1174
1203
|
}
|
|
@@ -1176,6 +1205,51 @@ function getDashboardPageURL() {
|
|
|
1176
1205
|
return `${SCHEME}://electron/index.html`;
|
|
1177
1206
|
}
|
|
1178
1207
|
|
|
1208
|
+
// src/core/dashboard-window-hooks.ts
|
|
1209
|
+
function shouldOpenDevToolsShortcut(input) {
|
|
1210
|
+
if (input.type !== "keyDown") {
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
if (input.key === "F12") {
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1216
|
+
const k = input.key.toLowerCase();
|
|
1217
|
+
if (k !== "i") {
|
|
1218
|
+
return false;
|
|
1219
|
+
}
|
|
1220
|
+
if (input.control && input.shift) {
|
|
1221
|
+
return true;
|
|
1222
|
+
}
|
|
1223
|
+
if (process.platform === "darwin" && input.meta && input.alt) {
|
|
1224
|
+
return true;
|
|
1225
|
+
}
|
|
1226
|
+
return false;
|
|
1227
|
+
}
|
|
1228
|
+
function attachDashboardWindowHooks(win, options) {
|
|
1229
|
+
const wc = win.webContents;
|
|
1230
|
+
wc.on("before-input-event", (event, input) => {
|
|
1231
|
+
if (!shouldOpenDevToolsShortcut(input)) {
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
event.preventDefault();
|
|
1235
|
+
if (wc.isDevToolsOpened()) {
|
|
1236
|
+
wc.closeDevTools();
|
|
1237
|
+
} else {
|
|
1238
|
+
wc.openDevTools({ mode: "detach" });
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
wc.on("did-fail-load", (_e, code, desc, url) => {
|
|
1242
|
+
console.error("[@electron-memory/monitor] dashboard did-fail-load", code, desc, url);
|
|
1243
|
+
});
|
|
1244
|
+
let autoOpened = false;
|
|
1245
|
+
wc.on("did-finish-load", () => {
|
|
1246
|
+
if (options.openDevToolsOnStart && !autoOpened) {
|
|
1247
|
+
autoOpened = true;
|
|
1248
|
+
wc.openDevTools({ mode: "detach" });
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1179
1253
|
// src/core/dashboard.ts
|
|
1180
1254
|
var DashboardManager = class {
|
|
1181
1255
|
constructor(config) {
|
|
@@ -1208,9 +1282,13 @@ var DashboardManager = class {
|
|
|
1208
1282
|
webPreferences: {
|
|
1209
1283
|
preload: preloadPath,
|
|
1210
1284
|
contextIsolation: true,
|
|
1211
|
-
nodeIntegration: false
|
|
1285
|
+
nodeIntegration: false,
|
|
1286
|
+
devTools: true
|
|
1212
1287
|
}
|
|
1213
1288
|
});
|
|
1289
|
+
attachDashboardWindowHooks(this.window, {
|
|
1290
|
+
openDevToolsOnStart: this.config.dashboard.openDevToolsOnStart
|
|
1291
|
+
});
|
|
1214
1292
|
const uiRoot = path3.join(__dirname, "ui");
|
|
1215
1293
|
ensureDashboardProtocolHandler(uiRoot);
|
|
1216
1294
|
this.window.loadURL(getDashboardPageURL());
|
|
@@ -1364,7 +1442,8 @@ var DEFAULT_CONFIG = {
|
|
|
1364
1442
|
dashboard: {
|
|
1365
1443
|
width: 1400,
|
|
1366
1444
|
height: 900,
|
|
1367
|
-
alwaysOnTop: false
|
|
1445
|
+
alwaysOnTop: false,
|
|
1446
|
+
openDevToolsOnStart: false
|
|
1368
1447
|
},
|
|
1369
1448
|
processLabels: {}
|
|
1370
1449
|
};
|
|
@@ -1680,7 +1759,15 @@ var ElectronMemoryMonitor = class extends import_events3.EventEmitter {
|
|
|
1680
1759
|
this.emit("snapshot", snapshot);
|
|
1681
1760
|
}
|
|
1682
1761
|
mergeConfig(userConfig) {
|
|
1683
|
-
if (!userConfig)
|
|
1762
|
+
if (!userConfig) {
|
|
1763
|
+
return {
|
|
1764
|
+
...DEFAULT_CONFIG,
|
|
1765
|
+
dashboard: {
|
|
1766
|
+
...DEFAULT_CONFIG.dashboard,
|
|
1767
|
+
openDevToolsOnStart: process.env.LAUNCHER_MEMORY_MONITOR_DEVTOOLS === "1"
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1684
1771
|
return {
|
|
1685
1772
|
...DEFAULT_CONFIG,
|
|
1686
1773
|
...userConfig,
|
|
@@ -1694,7 +1781,8 @@ var ElectronMemoryMonitor = class extends import_events3.EventEmitter {
|
|
|
1694
1781
|
},
|
|
1695
1782
|
dashboard: {
|
|
1696
1783
|
...DEFAULT_CONFIG.dashboard,
|
|
1697
|
-
...userConfig.dashboard || {}
|
|
1784
|
+
...userConfig.dashboard || {},
|
|
1785
|
+
openDevToolsOnStart: userConfig.dashboard?.openDevToolsOnStart !== void 0 ? userConfig.dashboard.openDevToolsOnStart : process.env.LAUNCHER_MEMORY_MONITOR_DEVTOOLS === "1"
|
|
1698
1786
|
},
|
|
1699
1787
|
processLabels: {
|
|
1700
1788
|
...DEFAULT_CONFIG.processLabels,
|