@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.mjs
CHANGED
|
@@ -1073,12 +1073,31 @@ import { BrowserWindow as BrowserWindow2 } from "electron";
|
|
|
1073
1073
|
import * as path3 from "path";
|
|
1074
1074
|
|
|
1075
1075
|
// src/core/dashboard-protocol.ts
|
|
1076
|
-
import { app as app2,
|
|
1076
|
+
import { app as app2, protocol } from "electron";
|
|
1077
|
+
import { readFile } from "fs/promises";
|
|
1077
1078
|
import * as path2 from "path";
|
|
1078
|
-
import { pathToFileURL } from "url";
|
|
1079
1079
|
var SCHEME = "emm-dashboard";
|
|
1080
1080
|
var privilegedRegistered = false;
|
|
1081
1081
|
var handlerRegistered = false;
|
|
1082
|
+
var MIME_BY_EXT = {
|
|
1083
|
+
".html": "text/html; charset=utf-8",
|
|
1084
|
+
".js": "text/javascript; charset=utf-8",
|
|
1085
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
1086
|
+
".css": "text/css; charset=utf-8",
|
|
1087
|
+
".json": "application/json",
|
|
1088
|
+
".map": "application/json",
|
|
1089
|
+
".svg": "image/svg+xml",
|
|
1090
|
+
".png": "image/png",
|
|
1091
|
+
".jpg": "image/jpeg",
|
|
1092
|
+
".jpeg": "image/jpeg",
|
|
1093
|
+
".gif": "image/gif",
|
|
1094
|
+
".webp": "image/webp",
|
|
1095
|
+
".ico": "image/x-icon",
|
|
1096
|
+
".woff": "font/woff",
|
|
1097
|
+
".woff2": "font/woff2",
|
|
1098
|
+
".ttf": "font/ttf",
|
|
1099
|
+
".txt": "text/plain; charset=utf-8"
|
|
1100
|
+
};
|
|
1082
1101
|
function isPathInsideRoot(filePath, root) {
|
|
1083
1102
|
const f = path2.resolve(filePath);
|
|
1084
1103
|
const r = path2.resolve(root);
|
|
@@ -1117,7 +1136,7 @@ function ensureDashboardProtocolHandler(uiRoot) {
|
|
|
1117
1136
|
}
|
|
1118
1137
|
handlerRegistered = true;
|
|
1119
1138
|
const base = path2.resolve(uiRoot);
|
|
1120
|
-
protocol.handle(SCHEME, (request) => {
|
|
1139
|
+
protocol.handle(SCHEME, async (request) => {
|
|
1121
1140
|
try {
|
|
1122
1141
|
const { pathname } = new URL(request.url);
|
|
1123
1142
|
let rel = pathname.startsWith("/") ? pathname.slice(1) : pathname;
|
|
@@ -1128,9 +1147,19 @@ function ensureDashboardProtocolHandler(uiRoot) {
|
|
|
1128
1147
|
if (!isPathInsideRoot(filePath, base)) {
|
|
1129
1148
|
return new Response("Forbidden", { status: 403 });
|
|
1130
1149
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1150
|
+
const body = await readFile(filePath);
|
|
1151
|
+
const ext = path2.extname(filePath).toLowerCase();
|
|
1152
|
+
const mime = MIME_BY_EXT[ext] || "application/octet-stream";
|
|
1153
|
+
return new Response(body, {
|
|
1154
|
+
status: 200,
|
|
1155
|
+
headers: {
|
|
1156
|
+
"Content-Type": mime,
|
|
1157
|
+
"Cache-Control": "no-store"
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
} catch (err) {
|
|
1161
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1162
|
+
return new Response(msg, { status: 404 });
|
|
1134
1163
|
}
|
|
1135
1164
|
});
|
|
1136
1165
|
}
|
|
@@ -1138,6 +1167,51 @@ function getDashboardPageURL() {
|
|
|
1138
1167
|
return `${SCHEME}://electron/index.html`;
|
|
1139
1168
|
}
|
|
1140
1169
|
|
|
1170
|
+
// src/core/dashboard-window-hooks.ts
|
|
1171
|
+
function shouldOpenDevToolsShortcut(input) {
|
|
1172
|
+
if (input.type !== "keyDown") {
|
|
1173
|
+
return false;
|
|
1174
|
+
}
|
|
1175
|
+
if (input.key === "F12") {
|
|
1176
|
+
return true;
|
|
1177
|
+
}
|
|
1178
|
+
const k = input.key.toLowerCase();
|
|
1179
|
+
if (k !== "i") {
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
if (input.control && input.shift) {
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
if (process.platform === "darwin" && input.meta && input.alt) {
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
function attachDashboardWindowHooks(win, options) {
|
|
1191
|
+
const wc = win.webContents;
|
|
1192
|
+
wc.on("before-input-event", (event, input) => {
|
|
1193
|
+
if (!shouldOpenDevToolsShortcut(input)) {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
event.preventDefault();
|
|
1197
|
+
if (wc.isDevToolsOpened()) {
|
|
1198
|
+
wc.closeDevTools();
|
|
1199
|
+
} else {
|
|
1200
|
+
wc.openDevTools({ mode: "detach" });
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
wc.on("did-fail-load", (_e, code, desc, url) => {
|
|
1204
|
+
console.error("[@electron-memory/monitor] dashboard did-fail-load", code, desc, url);
|
|
1205
|
+
});
|
|
1206
|
+
let autoOpened = false;
|
|
1207
|
+
wc.on("did-finish-load", () => {
|
|
1208
|
+
if (options.openDevToolsOnStart && !autoOpened) {
|
|
1209
|
+
autoOpened = true;
|
|
1210
|
+
wc.openDevTools({ mode: "detach" });
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1141
1215
|
// src/core/dashboard.ts
|
|
1142
1216
|
var DashboardManager = class {
|
|
1143
1217
|
constructor(config) {
|
|
@@ -1170,9 +1244,13 @@ var DashboardManager = class {
|
|
|
1170
1244
|
webPreferences: {
|
|
1171
1245
|
preload: preloadPath,
|
|
1172
1246
|
contextIsolation: true,
|
|
1173
|
-
nodeIntegration: false
|
|
1247
|
+
nodeIntegration: false,
|
|
1248
|
+
devTools: true
|
|
1174
1249
|
}
|
|
1175
1250
|
});
|
|
1251
|
+
attachDashboardWindowHooks(this.window, {
|
|
1252
|
+
openDevToolsOnStart: this.config.dashboard.openDevToolsOnStart
|
|
1253
|
+
});
|
|
1176
1254
|
const uiRoot = path3.join(__dirname, "ui");
|
|
1177
1255
|
ensureDashboardProtocolHandler(uiRoot);
|
|
1178
1256
|
this.window.loadURL(getDashboardPageURL());
|
|
@@ -1326,7 +1404,8 @@ var DEFAULT_CONFIG = {
|
|
|
1326
1404
|
dashboard: {
|
|
1327
1405
|
width: 1400,
|
|
1328
1406
|
height: 900,
|
|
1329
|
-
alwaysOnTop: false
|
|
1407
|
+
alwaysOnTop: false,
|
|
1408
|
+
openDevToolsOnStart: false
|
|
1330
1409
|
},
|
|
1331
1410
|
processLabels: {}
|
|
1332
1411
|
};
|
|
@@ -1642,7 +1721,15 @@ var ElectronMemoryMonitor = class extends EventEmitter3 {
|
|
|
1642
1721
|
this.emit("snapshot", snapshot);
|
|
1643
1722
|
}
|
|
1644
1723
|
mergeConfig(userConfig) {
|
|
1645
|
-
if (!userConfig)
|
|
1724
|
+
if (!userConfig) {
|
|
1725
|
+
return {
|
|
1726
|
+
...DEFAULT_CONFIG,
|
|
1727
|
+
dashboard: {
|
|
1728
|
+
...DEFAULT_CONFIG.dashboard,
|
|
1729
|
+
openDevToolsOnStart: process.env.LAUNCHER_MEMORY_MONITOR_DEVTOOLS === "1"
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1646
1733
|
return {
|
|
1647
1734
|
...DEFAULT_CONFIG,
|
|
1648
1735
|
...userConfig,
|
|
@@ -1656,7 +1743,8 @@ var ElectronMemoryMonitor = class extends EventEmitter3 {
|
|
|
1656
1743
|
},
|
|
1657
1744
|
dashboard: {
|
|
1658
1745
|
...DEFAULT_CONFIG.dashboard,
|
|
1659
|
-
...userConfig.dashboard || {}
|
|
1746
|
+
...userConfig.dashboard || {},
|
|
1747
|
+
openDevToolsOnStart: userConfig.dashboard?.openDevToolsOnStart !== void 0 ? userConfig.dashboard.openDevToolsOnStart : process.env.LAUNCHER_MEMORY_MONITOR_DEVTOOLS === "1"
|
|
1660
1748
|
},
|
|
1661
1749
|
processLabels: {
|
|
1662
1750
|
...DEFAULT_CONFIG.processLabels,
|