electron-incremental-update 2.4.2 → 3.0.0-beta.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 +72 -43
- package/dist/download-BN4uMS4_.d.mts +39 -0
- package/dist/download-DO7iuxEJ.d.cts +39 -0
- package/dist/electron-BFoZUBhU.cjs +320 -0
- package/dist/electron-CJIoO4ny.mjs +180 -0
- package/dist/index.cjs +259 -331
- package/dist/index.d.cts +179 -169
- package/dist/index.d.mts +204 -0
- package/dist/index.mjs +271 -0
- package/dist/provider.cjs +142 -356
- package/dist/provider.d.cts +116 -117
- package/dist/provider.d.mts +133 -0
- package/dist/provider.mjs +152 -0
- package/dist/types-BM9Jfu7q.d.cts +154 -0
- package/dist/types-DASqEPXE.d.mts +154 -0
- package/dist/utils.cjs +43 -381
- package/dist/utils.d.cts +117 -85
- package/dist/utils.d.mts +161 -0
- package/dist/utils.mjs +5 -0
- package/dist/version--eVB2A7n.mjs +72 -0
- package/dist/version-aPrLuz_-.cjs +129 -0
- package/dist/vite.d.mts +565 -0
- package/dist/vite.mjs +1222 -0
- package/dist/zip-BCC7FAQ_.cjs +264 -0
- package/dist/zip-Dwm7s1C9.mjs +185 -0
- package/package.json +65 -65
- package/dist/chunk-AAAM44NW.js +0 -70
- package/dist/chunk-IVHNGRZY.js +0 -122
- package/dist/chunk-PD4EV4MM.js +0 -147
- package/dist/index.d.ts +0 -194
- package/dist/index.js +0 -309
- package/dist/provider.d.ts +0 -134
- package/dist/provider.js +0 -178
- package/dist/types-CU7GyVez.d.cts +0 -151
- package/dist/types-CU7GyVez.d.ts +0 -151
- package/dist/utils.d.ts +0 -129
- package/dist/utils.js +0 -3
- package/dist/vite.d.ts +0 -533
- package/dist/vite.js +0 -945
- package/dist/zip-Blmn2vzE.d.cts +0 -71
- package/dist/zip-CnSv_Njj.d.ts +0 -71
- package/provider.d.ts +0 -1
- package/provider.js +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
- package/vite.d.ts +0 -1
- package/vite.js +0 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { BrowserWindow, app } from "electron";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/electron.ts
|
|
6
|
+
/**
|
|
7
|
+
* Compile time dev check
|
|
8
|
+
*/
|
|
9
|
+
const isDev = __EIU_IS_DEV__;
|
|
10
|
+
const isWin = process.platform === "win32";
|
|
11
|
+
const isMac = process.platform === "darwin";
|
|
12
|
+
const isLinux = process.platform === "linux";
|
|
13
|
+
/**
|
|
14
|
+
* Get joined path of `${electron.app.name}.asar` (not `app.asar`)
|
|
15
|
+
*
|
|
16
|
+
* If is in dev, **always** return `'DEV.asar'`
|
|
17
|
+
*/
|
|
18
|
+
function getPathFromAppNameAsar(...paths) {
|
|
19
|
+
return isDev ? "DEV.asar" : path.join(path.dirname(app.getAppPath()), `${app.name}.asar`, ...paths);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get app version, if is in dev, return `getEntryVersion()`
|
|
23
|
+
*/
|
|
24
|
+
function getAppVersion() {
|
|
25
|
+
return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get entry version
|
|
29
|
+
*/
|
|
30
|
+
function getEntryVersion() {
|
|
31
|
+
return app.getVersion();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Use `require` to load native module from entry asar
|
|
35
|
+
* @param moduleName file name in entry
|
|
36
|
+
* @example
|
|
37
|
+
* requireNative<typeof import('../native/db')>('db')
|
|
38
|
+
*/
|
|
39
|
+
function requireNative(moduleName) {
|
|
40
|
+
const m = getPathFromEntryAsar(moduleName);
|
|
41
|
+
if (__EIU_IS_ESM__) throw new Error(`Cannot require "${m}", \`requireNative\` only support CommonJS, use \`importNative\` instead`);
|
|
42
|
+
return require(m);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Use `import` to load native module from entry asar
|
|
46
|
+
* @param moduleName file name in entry
|
|
47
|
+
* @example
|
|
48
|
+
* await importNative<typeof import('../native/db')>('db')
|
|
49
|
+
*/
|
|
50
|
+
async function importNative(moduleName) {
|
|
51
|
+
const m = getPathFromEntryAsar(moduleName);
|
|
52
|
+
if (!__EIU_IS_ESM__) throw new Error(`Cannot import "${m}", \`importNative\` only support ESModule, use \`requireNative\` instead`);
|
|
53
|
+
return await import(`file://${m}.js`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Restarts the Electron app.
|
|
57
|
+
*/
|
|
58
|
+
function restartApp() {
|
|
59
|
+
app.relaunch();
|
|
60
|
+
app.quit();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Fix app use model id, only for Windows
|
|
64
|
+
* @param id app id, default is `org.${electron.app.name}`
|
|
65
|
+
*/
|
|
66
|
+
function setAppUserModelId(id) {
|
|
67
|
+
if (isWin) app.setAppUserModelId(id ?? `org.${app.name}`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Disable hardware acceleration for Windows 7
|
|
71
|
+
*
|
|
72
|
+
* Only support CommonJS
|
|
73
|
+
*/
|
|
74
|
+
function disableHWAccForWin7() {
|
|
75
|
+
if (!__EIU_IS_ESM__ && require("node:os").release().startsWith("6.1")) app.disableHardwareAcceleration();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Keep single electron instance and auto restore window on `second-instance` event
|
|
79
|
+
* @param window brwoser window to show
|
|
80
|
+
*/
|
|
81
|
+
function singleInstance(window) {
|
|
82
|
+
app.on("second-instance", () => {
|
|
83
|
+
if (window) {
|
|
84
|
+
window.show();
|
|
85
|
+
if (window.isMinimized()) window.restore();
|
|
86
|
+
window.focus();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Set `userData` dir to the dir of .exe file
|
|
92
|
+
*
|
|
93
|
+
* Useful for portable Windows app
|
|
94
|
+
* @param dirName dir name, default to `data`
|
|
95
|
+
* @param create whether to create dir, default to `true`
|
|
96
|
+
*/
|
|
97
|
+
function setPortableDataPath(dirName = "data", create = true) {
|
|
98
|
+
if (app.isReady()) throw new Error("Portable app data dir must be setup before app is ready");
|
|
99
|
+
const portableDir = path.join(path.dirname(app.getPath("exe")), dirName);
|
|
100
|
+
if (create) {
|
|
101
|
+
if (!fs.existsSync(portableDir)) fs.mkdirSync(portableDir);
|
|
102
|
+
else if (!fs.statSync(portableDir).isDirectory()) {
|
|
103
|
+
fs.rmSync(portableDir);
|
|
104
|
+
fs.mkdirSync(portableDir);
|
|
105
|
+
}
|
|
106
|
+
} else if (!fs.existsSync(portableDir)) throw new Error("Portable app data dir does not exists");
|
|
107
|
+
app.setPath("userData", portableDir);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Use {@link setPortableDataPath} instead
|
|
111
|
+
*/
|
|
112
|
+
const setPortableAppDataPath = setPortableDataPath;
|
|
113
|
+
/**
|
|
114
|
+
* Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
|
|
115
|
+
* @param win window
|
|
116
|
+
* @param htmlFilePath html file path, default is `index.html`
|
|
117
|
+
*/
|
|
118
|
+
function loadPage(win, htmlFilePath = "index.html") {
|
|
119
|
+
if (isDev) win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
|
|
120
|
+
else win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Beautify devtools' font and scrollbar
|
|
124
|
+
* @param win target window
|
|
125
|
+
* @param options sans font family, mono font family and scrollbar
|
|
126
|
+
* @see https://github.com/electron/electron/issues/42055
|
|
127
|
+
*/
|
|
128
|
+
function beautifyDevTools(win, options) {
|
|
129
|
+
const { mono, sans, scrollbar = true } = options;
|
|
130
|
+
win.webContents.on("devtools-opened", async () => {
|
|
131
|
+
let css = `:root{--sans:${sans};--mono:${mono}}:root, body { --source-code-font-family: var(--mono) !important; --source-code-font-size: 12px !important; --monospace-font-family: var(--mono) !important; --monospace-font-size: 12px !important; --default-font-family: var(--sans), sans-serif !important; --default-font-size: 12px !important; } button, input, select, .undisplayable-text, .expandable-inline-button { font-family: var(--sans) !important; } `;
|
|
132
|
+
if (scrollbar) css += ":root { --scrollbar-width: max(0.85vw, 10px); } @media (prefers-color-scheme: light) { :root { --scrollbar-color-rgb: 0, 0, 0; } } @media (prefers-color-scheme: dark) { :root { --scrollbar-color-rgb: 255, 255, 255; } } *::-webkit-scrollbar { width: var(--scrollbar-width) !important; height: var(--scrollbar-width) !important; } *::-webkit-scrollbar-track { background-color: transparent !important; border-radius: var(--scrollbar-width) !important; box-shadow: none !important; } *::-webkit-scrollbar-thumb { box-shadow: inset 0 0 0 var(--scrollbar-width) !important; border-radius: var(--scrollbar-width) !important; border: calc(var(--scrollbar-width) * 2 / 9) solid transparent !important; background-clip: content-box; background-color: transparent !important; color: rgba(var(--scrollbar-color-rgb), 30%) !important; } *::-webkit-scrollbar-thumb:hover { color: rgba(var(--scrollbar-color-rgb), 45%) !important; } *::-webkit-scrollbar-thumb:active { color: rgba(var(--scrollbar-color-rgb), 60%) !important; } @supports not selector(::-webkit-scrollbar) { html { scrollbar-color: rgb(var(--scrollbar-color-rgb)); scrollbar-width: thin; } } ";
|
|
133
|
+
const js = `const __CSS__='${css}';function e(e){let t=document.createElement(\`style\`);t.innerHTML=e,document.body.append(t),[\`platform-windows\`,\`platform-mac\`,\`platform-linux\`].forEach(e=>document.querySelectorAll(\`.\${e}\`).forEach(t=>t.classList.remove(e))),r();let n=new MutationObserver(e=>{for(let t of e)if(t.type===\`childList\`)for(let e=0;e<t.addedNodes.length;e++)t.addedNodes[e].classList.contains(\`editor-tooltip-host\`)&&r()});n.observe(document.body,{childList:!0});function r(){document.querySelectorAll(\`.editor-tooltip-host\`).forEach(t=>{if(t?.shadowRoot?.querySelectorAll(\`[data-key="overridden-dev-tools-font"]\`).length===0){let n=document.createElement(\`style\`);n.dataset.key=\`overridden-dev-tools-font\`,n.innerHTML=\`\${e}.cm-tooltip-autocomplete ul[role=listbox]{font-family:var(--mono)!important;}\`,t.shadowRoot.append(n)}})}window.onbeforeunload=()=>n.disconnect()}e(__CSS__);`;
|
|
134
|
+
await win?.webContents.devToolsWebContents?.executeJavaScript(js);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get joined path from main dir
|
|
139
|
+
* @param paths rest paths
|
|
140
|
+
*/
|
|
141
|
+
function getPathFromMain(...paths) {
|
|
142
|
+
return isDev ? path.join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get joined path from preload dir
|
|
146
|
+
* @param paths rest paths
|
|
147
|
+
*/
|
|
148
|
+
function getPathFromPreload(...paths) {
|
|
149
|
+
return isDev ? path.join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get joined path from publich dir
|
|
153
|
+
* @param paths rest paths
|
|
154
|
+
*/
|
|
155
|
+
function getPathFromPublic(...paths) {
|
|
156
|
+
return isDev ? path.join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get joined path from entry asar
|
|
160
|
+
* @param paths rest paths
|
|
161
|
+
*/
|
|
162
|
+
function getPathFromEntryAsar(...paths) {
|
|
163
|
+
return path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Handle all unhandled error
|
|
167
|
+
* @param callback callback function
|
|
168
|
+
*/
|
|
169
|
+
function handleUnexpectedErrors(callback) {
|
|
170
|
+
process.on("uncaughtException", callback);
|
|
171
|
+
process.on("unhandledRejection", callback);
|
|
172
|
+
}
|
|
173
|
+
function reloadOnPreloadScriptChanged() {
|
|
174
|
+
if (isDev) process.on("message", (msg) => {
|
|
175
|
+
if (msg === "electron-vite&type=hot-reload") for (const window of BrowserWindow.getAllWindows()) window.reload();
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
export { singleInstance as C, setPortableDataPath as S, reloadOnPreloadScriptChanged as _, getPathFromAppNameAsar as a, setAppUserModelId as b, getPathFromPreload as c, importNative as d, isDev as f, loadPage as g, isWin as h, getEntryVersion as i, getPathFromPublic as l, isMac as m, disableHWAccForWin7 as n, getPathFromEntryAsar as o, isLinux as p, getAppVersion as r, getPathFromMain as s, beautifyDevTools as t, handleUnexpectedErrors as u, requireNative as v, setPortableAppDataPath as x, restartApp as y };
|