@witchcraft/nuxt-electron 0.4.2 → 0.4.4
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/module.json +1 -1
- package/dist/runtime/electron/preload/assertSecureContext.d.ts +19 -0
- package/dist/runtime/electron/preload/assertSecureContext.js +14 -0
- package/dist/runtime/electron/preload/index.d.ts +1 -0
- package/dist/runtime/electron/preload/index.js +1 -0
- package/dist/runtime/electron/types.d.ts +3 -0
- package/dist/runtime/electron/types.js +4 -0
- package/package.json +2 -2
- package/src/runtime/electron/preload/assertSecureContext.ts +34 -0
- package/src/runtime/electron/preload/index.ts +1 -0
- package/src/runtime/electron/types.ts +5 -0
package/dist/module.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an error named {@link NUXT_ELECTRON_ERROR.INSECURE_CONTEXT} when the window is not a secure context.
|
|
3
|
+
*
|
|
4
|
+
* ````ts [preload.ts]
|
|
5
|
+
* import { assertSecureContext } from "@witchcraft/nuxt-electron/electron/preload"
|
|
6
|
+
*
|
|
7
|
+
* assertSecureContext()
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* A throw in the preload is silent, so main reports it through `preload-error`:
|
|
11
|
+
*
|
|
12
|
+
* ````ts [main.ts]
|
|
13
|
+
* win.webContents.on("preload-error", (_event, path, error) => {
|
|
14
|
+
* logger.error({ ns: "electron:preload", path, error: error.message })
|
|
15
|
+
* if (error.name === NUXT_ELECTRON_ERROR.INSECURE_CONTEXT) app.exit(1)
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertSecureContext(): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NUXT_ELECTRON_ERROR } from "../types.js";
|
|
2
|
+
export function assertSecureContext() {
|
|
3
|
+
if (globalThis.isSecureContext) return;
|
|
4
|
+
const scheme = globalThis.location.protocol.replace(/:$/, "");
|
|
5
|
+
const error = new Error([
|
|
6
|
+
`[nuxt-electron] the window is not a secure context: the "${scheme}" scheme has no privileges.`,
|
|
7
|
+
"Check, in main that:",
|
|
8
|
+
`1. protocol.registerSchemesAsPrivileged registers "${scheme}" with { standard: true, secure: true, supportFetchAPI: true }.`,
|
|
9
|
+
"2. it is called before app.whenReady().",
|
|
10
|
+
"3. it is called once, a second call replaces the first (check other functions/dependencies aren't calling it after you if you only call once)."
|
|
11
|
+
].join("\n"));
|
|
12
|
+
error.name = NUXT_ELECTRON_ERROR.INSECURE_CONTEXT;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { AnyFunction, Flatten, OrToAnd } from "@alanscodelog/utils/types";
|
|
2
|
+
export declare const NUXT_ELECTRON_ERROR: {
|
|
3
|
+
INSECURE_CONTEXT: "NUXT_ELECTRON_ERROR.INSECURE_CONTEXT";
|
|
4
|
+
};
|
|
2
5
|
export type WindowControlsApi = (action: "close" | "minimize" | "toggleMaximize" | "togglePin") => Promise<void>;
|
|
3
6
|
export interface Register {
|
|
4
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/nuxt-electron",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Nuxt module for working with electron.",
|
|
5
5
|
"repository": "https://github.com/witchcraftjs/nuxt-electron",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@alanscodelog/utils": "^6.3.0",
|
|
45
45
|
"@nuxt/kit": "^4.3.1",
|
|
46
|
-
"@witchcraft/nuxt-utils": "^0.3.
|
|
46
|
+
"@witchcraft/nuxt-utils": "^0.3.18",
|
|
47
47
|
"@witchcraft/ui": "^0.5.12",
|
|
48
48
|
"defu": "^6.1.4",
|
|
49
49
|
"electron": "^37.10.3",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NUXT_ELECTRON_ERROR } from "../types.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Throws an error named {@link NUXT_ELECTRON_ERROR.INSECURE_CONTEXT} when the window is not a secure context.
|
|
5
|
+
*
|
|
6
|
+
* ````ts [preload.ts]
|
|
7
|
+
* import { assertSecureContext } from "@witchcraft/nuxt-electron/electron/preload"
|
|
8
|
+
*
|
|
9
|
+
* assertSecureContext()
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* A throw in the preload is silent, so main reports it through `preload-error`:
|
|
13
|
+
*
|
|
14
|
+
* ````ts [main.ts]
|
|
15
|
+
* win.webContents.on("preload-error", (_event, path, error) => {
|
|
16
|
+
* logger.error({ ns: "electron:preload", path, error: error.message })
|
|
17
|
+
* if (error.name === NUXT_ELECTRON_ERROR.INSECURE_CONTEXT) app.exit(1)
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function assertSecureContext(): void {
|
|
22
|
+
if (globalThis.isSecureContext) return
|
|
23
|
+
|
|
24
|
+
const scheme = globalThis.location.protocol.replace(/:$/, "")
|
|
25
|
+
const error = new Error([
|
|
26
|
+
`[nuxt-electron] the window is not a secure context: the "${scheme}" scheme has no privileges.`,
|
|
27
|
+
"Check, in main that:",
|
|
28
|
+
`1. protocol.registerSchemesAsPrivileged registers "${scheme}" with { standard: true, secure: true, supportFetchAPI: true }.`,
|
|
29
|
+
"2. it is called before app.whenReady().",
|
|
30
|
+
"3. it is called once, a second call replaces the first (check other functions/dependencies aren't calling it after you if you only call once)."
|
|
31
|
+
].join("\n"))
|
|
32
|
+
error.name = NUXT_ELECTRON_ERROR.INSECURE_CONTEXT
|
|
33
|
+
throw error
|
|
34
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { enumFromArray } from "@alanscodelog/utils/enumFromArray"
|
|
1
2
|
import type { AnyFunction, Flatten, OrToAnd } from "@alanscodelog/utils/types"
|
|
2
3
|
|
|
4
|
+
export const NUXT_ELECTRON_ERROR = enumFromArray([
|
|
5
|
+
"INSECURE_CONTEXT"
|
|
6
|
+
], "NUXT_ELECTRON_ERROR.")
|
|
7
|
+
|
|
3
8
|
export type WindowControlsApi = (action: "close" | "minimize" | "toggleMaximize" | "togglePin") => Promise<void>
|
|
4
9
|
|
|
5
10
|
export interface Register { }
|