@thirty-coder/electron-base-kit 0.2.0 → 0.2.2
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.md +1 -1
- package/dist/index.js +35 -13
- package/package.json +2 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -104,13 +104,15 @@ function initSettings() {
|
|
|
104
104
|
filePath = (0, import_node_path.join)(import_electron.app.getPath("userData"), "settings.json");
|
|
105
105
|
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(filePath), { recursive: true });
|
|
106
106
|
store = load();
|
|
107
|
-
|
|
107
|
+
const flushNow = () => {
|
|
108
108
|
if (timer) {
|
|
109
109
|
clearTimeout(timer);
|
|
110
110
|
timer = null;
|
|
111
111
|
}
|
|
112
112
|
writeNow();
|
|
113
|
-
}
|
|
113
|
+
};
|
|
114
|
+
import_electron.app.on("before-quit", flushNow);
|
|
115
|
+
import_electron.app.on("will-quit", flushNow);
|
|
114
116
|
}
|
|
115
117
|
var settings = {
|
|
116
118
|
get(key, fallback) {
|
|
@@ -274,22 +276,33 @@ function attachPersistence(win, key) {
|
|
|
274
276
|
timer2 = null;
|
|
275
277
|
}
|
|
276
278
|
save();
|
|
279
|
+
void settings.flush();
|
|
277
280
|
});
|
|
278
281
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
282
|
+
var guarded = /* @__PURE__ */ new Set();
|
|
283
|
+
var screenHooked = false;
|
|
284
|
+
function guardAll() {
|
|
285
|
+
for (const win of guarded) {
|
|
286
|
+
if (win.isDestroyed()) {
|
|
287
|
+
guarded.delete(win);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (win.isMaximized() || win.isMinimized() || win.isFullScreen()) continue;
|
|
283
291
|
const current = win.getBounds();
|
|
284
292
|
const area = bestWorkArea(current);
|
|
285
|
-
if (intersectArea(current, area) / (current.width * current.height) >= VISIBLE_RATIO)
|
|
293
|
+
if (intersectArea(current, area) / (current.width * current.height) >= VISIBLE_RATIO) continue;
|
|
286
294
|
win.setBounds(centerOnPrimary(current));
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function attachDisplayGuard(win) {
|
|
298
|
+
guarded.add(win);
|
|
299
|
+
if (!screenHooked) {
|
|
300
|
+
screenHooked = true;
|
|
301
|
+
import_electron2.screen.on("display-removed", guardAll);
|
|
302
|
+
import_electron2.screen.on("display-metrics-changed", guardAll);
|
|
303
|
+
}
|
|
290
304
|
win.once("closed", () => {
|
|
291
|
-
|
|
292
|
-
import_electron2.screen.removeListener("display-metrics-changed", handle);
|
|
305
|
+
guarded.delete(win);
|
|
293
306
|
});
|
|
294
307
|
}
|
|
295
308
|
function createWindow(options) {
|
|
@@ -305,6 +318,10 @@ function createWindow(options) {
|
|
|
305
318
|
const key = `window.${id}`;
|
|
306
319
|
const saved = remember ? settings.get(`${key}.bounds`, void 0) : void 0;
|
|
307
320
|
const maximized = remember ? settings.get(`${key}.maximized`, false) : false;
|
|
321
|
+
if (!remember) {
|
|
322
|
+
settings.remove(`${key}.bounds`);
|
|
323
|
+
settings.remove(`${key}.maximized`);
|
|
324
|
+
}
|
|
308
325
|
const { bounds, center } = resolveBounds(isBounds(saved) ? saved : void 0, size, ensureVisible);
|
|
309
326
|
const win = new import_electron2.BrowserWindow({
|
|
310
327
|
...bounds,
|
|
@@ -321,7 +338,12 @@ function createWindow(options) {
|
|
|
321
338
|
}
|
|
322
339
|
});
|
|
323
340
|
if (maximized) win.maximize();
|
|
324
|
-
win.once("ready-to-show", () =>
|
|
341
|
+
win.once("ready-to-show", () => {
|
|
342
|
+
win.show();
|
|
343
|
+
if (!remember) return;
|
|
344
|
+
if (win.isMaximized() || win.isMinimized() || win.isFullScreen()) return;
|
|
345
|
+
settings.set(`${key}.bounds`, win.getBounds());
|
|
346
|
+
});
|
|
325
347
|
if (process.env.ELECTRON_RENDERER_URL) {
|
|
326
348
|
win.loadURL(process.env.ELECTRON_RENDERER_URL);
|
|
327
349
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thirty-coder/electron-base-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Electron 桌面应用基础能力",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsup",
|
|
24
24
|
"dev": "tsup --watch",
|
|
25
|
+
"test": "tsup && node --test test/*.test.cjs",
|
|
25
26
|
"typecheck": "tsc --noEmit",
|
|
26
27
|
"release": "node scripts/release.mjs"
|
|
27
28
|
},
|