electron-incremental-update 2.0.0 → 2.1.0

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/utils.cjs CHANGED
@@ -34,10 +34,18 @@ function getEntryVersion() {
34
34
  return electron__default.default.app.getVersion();
35
35
  }
36
36
  function requireNative(moduleName) {
37
+ const m = getPathFromEntryAsar(moduleName);
37
38
  if (__EIU_IS_ESM__) {
38
- throw new Error(`Cannot require "${path__default.default.join(__EIU_ENTRY_DIST_PATH__, moduleName)}", \`requireNative\` only support CommonJS`);
39
+ throw new Error(`Cannot require "${m}", \`requireNative\` only support CommonJS, use \`importNative\` instead`);
39
40
  }
40
- return __require(path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
41
+ return __require(m);
42
+ }
43
+ async function importNative(moduleName) {
44
+ const m = getPathFromEntryAsar(moduleName);
45
+ if (!__EIU_IS_ESM__) {
46
+ throw new Error(`Cannot import "${m}", \`importNative\` only support ESModule, use \`requireNative\` instead`);
47
+ }
48
+ return await import(`file://${m}.js`);
41
49
  }
42
50
  function restartApp() {
43
51
  electron__default.default.app.relaunch();
@@ -84,6 +92,17 @@ function loadPage(win, htmlFilePath = "index.html") {
84
92
  win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
85
93
  }
86
94
  }
95
+ function beautifyDevTools(win, options) {
96
+ const { mono, sans, scrollbar = true } = options;
97
+ win.webContents.on("devtools-opened", () => {
98
+ 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}`;
99
+ if (scrollbar) {
100
+ css += ":root{--scrollbar-width: max(.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}}";
101
+ }
102
+ const js = `let overriddenStyle=document.createElement('style');overriddenStyle.innerHTML='${css}';document.body.append(overriddenStyle);document.body.classList.remove('platform-windows','platform-mac','platform-linux');`;
103
+ win?.webContents.devToolsWebContents?.executeJavaScript(js);
104
+ });
105
+ }
87
106
  function getPathFromMain(...paths) {
88
107
  return isDev ? path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
89
108
  }
@@ -214,6 +233,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
214
233
 
215
234
  exports.aesDecrypt = aesDecrypt;
216
235
  exports.aesEncrypt = aesEncrypt;
236
+ exports.beautifyDevTools = beautifyDevTools;
217
237
  exports.defaultIsLowerVersion = defaultIsLowerVersion;
218
238
  exports.defaultSignature = defaultSignature;
219
239
  exports.defaultUnzipFile = defaultUnzipFile;
@@ -230,6 +250,7 @@ exports.getPathFromPreload = getPathFromPreload;
230
250
  exports.getPathFromPublic = getPathFromPublic;
231
251
  exports.handleUnexpectedErrors = handleUnexpectedErrors;
232
252
  exports.hashBuffer = hashBuffer;
253
+ exports.importNative = importNative;
233
254
  exports.isDev = isDev;
234
255
  exports.isLinux = isLinux;
235
256
  exports.isMac = isMac;
package/dist/utils.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BrowserWindow } from 'electron';
2
2
  export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-rm9ED9nU.cjs';
3
- export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-BYVQ367i.cjs';
3
+ export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-DcFMG3pT.cjs';
4
4
 
5
5
  /**
6
6
  * Compile time dev check
@@ -30,6 +30,13 @@ declare function getEntryVersion(): string;
30
30
  * requireNative<typeof import('../native/db')>('db')
31
31
  */
32
32
  declare function requireNative<T = any>(moduleName: string): T;
33
+ /**
34
+ * Use `import` to load native module from entry asar
35
+ * @param moduleName file name in entry
36
+ * @example
37
+ * await importNative<typeof import('../native/db')>('db')
38
+ */
39
+ declare function importNative<T = any>(moduleName: string): Promise<T>;
33
40
  /**
34
41
  * Restarts the Electron app.
35
42
  */
@@ -64,6 +71,11 @@ declare function setPortableAppDataPath(dirName?: string): void;
64
71
  * @param htmlFilePath html file path, default is `index.html`
65
72
  */
66
73
  declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
74
+ declare function beautifyDevTools(win: BrowserWindow, options: {
75
+ sans: string;
76
+ mono: string;
77
+ scrollbar?: boolean;
78
+ }): void;
67
79
  /**
68
80
  * Get joined path from preload dir
69
81
  * @param paths rest paths
@@ -90,4 +102,4 @@ declare function getPathFromEntryAsar(...paths: string[]): string;
90
102
  */
91
103
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
92
104
 
93
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
105
+ export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BrowserWindow } from 'electron';
2
2
  export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-rm9ED9nU.js';
3
- export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-BYVQ367i.js';
3
+ export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-DcFMG3pT.js';
4
4
 
5
5
  /**
6
6
  * Compile time dev check
@@ -30,6 +30,13 @@ declare function getEntryVersion(): string;
30
30
  * requireNative<typeof import('../native/db')>('db')
31
31
  */
32
32
  declare function requireNative<T = any>(moduleName: string): T;
33
+ /**
34
+ * Use `import` to load native module from entry asar
35
+ * @param moduleName file name in entry
36
+ * @example
37
+ * await importNative<typeof import('../native/db')>('db')
38
+ */
39
+ declare function importNative<T = any>(moduleName: string): Promise<T>;
33
40
  /**
34
41
  * Restarts the Electron app.
35
42
  */
@@ -64,6 +71,11 @@ declare function setPortableAppDataPath(dirName?: string): void;
64
71
  * @param htmlFilePath html file path, default is `index.html`
65
72
  */
66
73
  declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
74
+ declare function beautifyDevTools(win: BrowserWindow, options: {
75
+ sans: string;
76
+ mono: string;
77
+ scrollbar?: boolean;
78
+ }): void;
67
79
  /**
68
80
  * Get joined path from preload dir
69
81
  * @param paths rest paths
@@ -90,4 +102,4 @@ declare function getPathFromEntryAsar(...paths: string[]): string;
90
102
  */
91
103
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
92
104
 
93
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
105
+ export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.js CHANGED
@@ -1,3 +1,3 @@
1
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-IABBXJFB.js';
1
+ export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-ZM5CIZ4L.js';
2
2
  export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-KZSYEXLO.js';
3
3
  export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-RCRKUKFX.js';
@@ -59,4 +59,4 @@ declare function isUpdateJSON(json: any): json is UpdateJSON;
59
59
  */
60
60
  declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
61
61
 
62
- export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
62
+ export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
@@ -59,4 +59,4 @@ declare function isUpdateJSON(json: any): json is UpdateJSON;
59
59
  */
60
60
  declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
61
61
 
62
- export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
62
+ export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
package/dist/vite.d.ts CHANGED
@@ -237,6 +237,10 @@ interface BytecodeOptions {
237
237
  * Enable in preload script. Remember to set `sandbox: false` when creating window
238
238
  */
239
239
  preload?: boolean;
240
+ /**
241
+ * Custom electron binary path
242
+ */
243
+ electronPath?: string;
240
244
  /**
241
245
  * Before transformed code compile function. If return `Falsy` value, it will be ignored
242
246
  * @param code transformed code