@witchcraft/nuxt-electron 0.0.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.
Files changed (82) hide show
  1. package/README.md +299 -0
  2. package/dist/module.d.mts +117 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +362 -0
  5. package/dist/runtime/components/ElectronWindowControls.d.vue.ts +31 -0
  6. package/dist/runtime/components/ElectronWindowControls.vue +67 -0
  7. package/dist/runtime/components/ElectronWindowControls.vue.d.ts +31 -0
  8. package/dist/runtime/components/WindowControls/CloseButton.d.vue.ts +16 -0
  9. package/dist/runtime/components/WindowControls/CloseButton.vue +54 -0
  10. package/dist/runtime/components/WindowControls/CloseButton.vue.d.ts +16 -0
  11. package/dist/runtime/components/WindowControls/MaximizeButton.d.vue.ts +16 -0
  12. package/dist/runtime/components/WindowControls/MaximizeButton.vue +33 -0
  13. package/dist/runtime/components/WindowControls/MaximizeButton.vue.d.ts +16 -0
  14. package/dist/runtime/components/WindowControls/MinimizeButton.d.vue.ts +16 -0
  15. package/dist/runtime/components/WindowControls/MinimizeButton.vue +40 -0
  16. package/dist/runtime/components/WindowControls/MinimizeButton.vue.d.ts +16 -0
  17. package/dist/runtime/components/WindowControls/PinButton.d.vue.ts +27 -0
  18. package/dist/runtime/components/WindowControls/PinButton.vue +51 -0
  19. package/dist/runtime/components/WindowControls/PinButton.vue.d.ts +27 -0
  20. package/dist/runtime/electron/apiBuilder.d.ts +8 -0
  21. package/dist/runtime/electron/apiBuilder.js +9 -0
  22. package/dist/runtime/electron/createBroadcastHandlers.d.ts +4 -0
  23. package/dist/runtime/electron/createBroadcastHandlers.js +30 -0
  24. package/dist/runtime/electron/createBroadcaster.d.ts +2 -0
  25. package/dist/runtime/electron/createBroadcaster.js +7 -0
  26. package/dist/runtime/electron/createNuxtFileProtocolHandler.d.ts +14 -0
  27. package/dist/runtime/electron/createNuxtFileProtocolHandler.js +20 -0
  28. package/dist/runtime/electron/createWindowControlsApi.d.ts +19 -0
  29. package/dist/runtime/electron/createWindowControlsApi.js +6 -0
  30. package/dist/runtime/electron/createWindowControlsApiHandler.d.ts +4 -0
  31. package/dist/runtime/electron/createWindowControlsApiHandler.js +24 -0
  32. package/dist/runtime/electron/getEventWindow.d.ts +11 -0
  33. package/dist/runtime/electron/getEventWindow.js +8 -0
  34. package/dist/runtime/electron/getPaths.d.ts +27 -0
  35. package/dist/runtime/electron/getPaths.js +33 -0
  36. package/dist/runtime/electron/getPreloadMeta.d.ts +25 -0
  37. package/dist/runtime/electron/getPreloadMeta.js +7 -0
  38. package/dist/runtime/electron/index.d.ts +16 -0
  39. package/dist/runtime/electron/index.js +16 -0
  40. package/dist/runtime/electron/promisifyApi.d.ts +40 -0
  41. package/dist/runtime/electron/promisifyApi.js +41 -0
  42. package/dist/runtime/electron/promisifyReply.d.ts +8 -0
  43. package/dist/runtime/electron/promisifyReply.js +27 -0
  44. package/dist/runtime/electron/registerDevtoolsShortcuts.d.ts +2 -0
  45. package/dist/runtime/electron/registerDevtoolsShortcuts.js +10 -0
  46. package/dist/runtime/electron/static.d.ts +12 -0
  47. package/dist/runtime/electron/static.js +8 -0
  48. package/dist/runtime/electron/types.d.ts +1 -0
  49. package/dist/runtime/electron/types.js +0 -0
  50. package/dist/runtime/electron/useDevDataDir.d.ts +1 -0
  51. package/dist/runtime/electron/useDevDataDir.js +8 -0
  52. package/dist/runtime/electron/useNuxtRuntimeConfig.d.ts +2 -0
  53. package/dist/runtime/electron/useNuxtRuntimeConfig.js +4 -0
  54. package/dist/runtime/utils/isElectron.d.ts +9 -0
  55. package/dist/runtime/utils/isElectron.js +3 -0
  56. package/dist/types.d.mts +3 -0
  57. package/genDevDesktop.js +47 -0
  58. package/package.json +93 -0
  59. package/src/module.ts +549 -0
  60. package/src/runtime/components/ElectronWindowControls.vue +94 -0
  61. package/src/runtime/components/WindowControls/CloseButton.vue +56 -0
  62. package/src/runtime/components/WindowControls/MaximizeButton.vue +35 -0
  63. package/src/runtime/components/WindowControls/MinimizeButton.vue +42 -0
  64. package/src/runtime/components/WindowControls/PinButton.vue +56 -0
  65. package/src/runtime/electron/apiBuilder.ts +27 -0
  66. package/src/runtime/electron/createBroadcastHandlers.ts +36 -0
  67. package/src/runtime/electron/createBroadcaster.ts +11 -0
  68. package/src/runtime/electron/createNuxtFileProtocolHandler.ts +42 -0
  69. package/src/runtime/electron/createWindowControlsApi.ts +27 -0
  70. package/src/runtime/electron/createWindowControlsApiHandler.ts +34 -0
  71. package/src/runtime/electron/getEventWindow.ts +19 -0
  72. package/src/runtime/electron/getPaths.ts +68 -0
  73. package/src/runtime/electron/getPreloadMeta.ts +36 -0
  74. package/src/runtime/electron/index.ts +17 -0
  75. package/src/runtime/electron/promisifyApi.ts +102 -0
  76. package/src/runtime/electron/promisifyReply.ts +49 -0
  77. package/src/runtime/electron/registerDevtoolsShortcuts.ts +12 -0
  78. package/src/runtime/electron/static.ts +14 -0
  79. package/src/runtime/electron/types.ts +1 -0
  80. package/src/runtime/electron/useDevDataDir.ts +8 -0
  81. package/src/runtime/electron/useNuxtRuntimeConfig.ts +7 -0
  82. package/src/runtime/utils/isElectron.ts +11 -0
@@ -0,0 +1,8 @@
1
+ export function useDevDataDir() {
2
+ if (import.meta.dev) {
3
+ const index = process.argv.findIndex((arg) => arg.startsWith("--user-data-dir")) + 1;
4
+ if (index === -1) return void 0;
5
+ return process.argv[index + 1];
6
+ }
7
+ return void 0;
8
+ }
@@ -0,0 +1,2 @@
1
+ import type { PublicRuntimeConfig } from "nuxt/schema";
2
+ export declare function useNuxtRuntimeConfig(): PublicRuntimeConfig;
@@ -0,0 +1,4 @@
1
+ import { STATIC } from "./static.js";
2
+ export function useNuxtRuntimeConfig() {
3
+ return STATIC.ELECTRON_RUNTIME_CONFIG;
4
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This requires electron's preload script set the `electron` property on the window:
3
+ *
4
+ * ```ts
5
+ * // preload.ts
6
+ * contextBridge.exposeInMainWorld("electron", { })
7
+ * ```
8
+ */
9
+ export declare function isElectron(): boolean;
@@ -0,0 +1,3 @@
1
+ export function isElectron() {
2
+ return typeof window !== "undefined" && "electron" in window && typeof window.electron !== "undefined";
3
+ }
@@ -0,0 +1,3 @@
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions } from './module.mjs'
@@ -0,0 +1,47 @@
1
+ import { run } from "@alanscodelog/utils/run"
2
+ import JSON5 from "json5"
3
+ import fs from "node:fs/promises"
4
+ import path from "node:path"
5
+
6
+ if (["darwin", "linux"].includes(process.platform)) {
7
+ // eslint-disable-next-line no-console
8
+ console.log("Generating dev desktop file.")
9
+ } else {
10
+ process.exit(0)
11
+ }
12
+
13
+ const electronBuilderConfigPath = path.join(process.cwd(), "electron-builder.json5")
14
+ const electronBuilderConfig = JSON5.parse(await fs.readFile(electronBuilderConfigPath, "utf8"))
15
+
16
+ const desktopFile = electronBuilderConfig.linux?.desktop
17
+
18
+ desktopFile.Path = process.cwd()
19
+ desktopFile.Exec = process.argv[3] ?? `npm run launch:electron "%u"`
20
+ // desktopFile.Exec = `bash -c 'cd ${process.cwd()} && ${process.argv[3] ?? `npm run launch:electron %u'`}`
21
+ const contents = `[Desktop Entry]\n${
22
+ Object.entries(desktopFile).map(([key, value]) => `${key}=${value}`).join("\n")}`
23
+ const appName = process.argv[2]
24
+
25
+ if (!appName) {
26
+ throw new Error("You must pass the app name as the first argument.")
27
+ }
28
+ if (!process.env.HOME) {
29
+ throw new Error("HOME environment variable is not set.")
30
+ }
31
+
32
+ const filepath = path.resolve(process.env.HOME, `./.local/share/applications/dev-${appName}.desktop`)
33
+
34
+ await run(`xdg-desktop-menu uninstall ${filepath}`).promise
35
+ // eslint-disable-next-line no-console
36
+ .catch((err) => { console.log(err) })
37
+
38
+ await fs.writeFile(filepath, contents)
39
+ await fs.chmod(filepath, "755")
40
+
41
+ await run(`xdg-desktop-menu install ${filepath}`).promise
42
+
43
+ .catch((err) => {
44
+ // eslint-disable-next-line no-console
45
+ console.log(err)
46
+ process.exit(1)
47
+ })
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@witchcraft/nuxt-electron",
3
+ "version": "0.0.1",
4
+ "description": "Nuxt module for working with electron.",
5
+ "repository": "witchcraftjs/nuxt-electron",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types.d.mts",
12
+ "import": "./dist/module.mjs"
13
+ },
14
+ "./electron": {
15
+ "types": "./dist/runtime/electron/index.d.ts",
16
+ "import": "./dist/runtime/electron/index.js"
17
+ },
18
+ "./genDevDesktop": {
19
+ "import": "./genDevDesktop.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "src",
24
+ "dist",
25
+ "genDevDesktop.js"
26
+ ],
27
+ "scripts": {
28
+ "prepare": "husky && cd playground && pnpm i",
29
+ "build": "nuxt-module-build prepare && nuxt-module-build build && nuxi build playground",
30
+ "build:only": "nuxt-module-build build",
31
+ "dev": "nuxi dev playground",
32
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
33
+ "lint": "eslint \"{src,test,playground/app}/**/*.{ts,vue}\" \"*.{js,cjs,mjs,ts}\"",
34
+ "lint:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest watch"
37
+ },
38
+ "dependencies": {
39
+ "@alanscodelog/utils": "^6.0.1",
40
+ "@nuxt/kit": "^4.0.3",
41
+ "@witchcraft/nuxt-utils": "^0.2.1",
42
+ "defu": "^6.1.4",
43
+ "es-toolkit": "^1.39.10",
44
+ "vite-plugin-electron": "^0.29.0",
45
+ "vite-plugin-externalize-deps": "^0.9.0"
46
+ },
47
+ "peerDependencies": {
48
+ "@witchcraft/ui": "^0.2.1",
49
+ "unplugin-icons": "^22.1.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "unplugin-icons": {
53
+ "optional": true
54
+ },
55
+ "@witchcraft/ui": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "devDependencies": {
60
+ "@alanscodelog/eslint-config": "^6.3.0",
61
+ "@alanscodelog/semantic-release-config": "^5.0.4",
62
+ "@alanscodelog/tsconfigs": "^6.1.0",
63
+ "@nuxt/eslint-config": "^1.9.0",
64
+ "@nuxt/module-builder": "^1.0.2",
65
+ "@nuxt/schema": "^4.0.3",
66
+ "@nuxt/test-utils": "^3.19.2",
67
+ "@types/node": "latest",
68
+ "@witchcraft/ui": "^0.2.1",
69
+ "changelogen": "^0.6.2",
70
+ "electron": "^34.5.8",
71
+ "eslint": "^9.34.0",
72
+ "husky": "^9.1.7",
73
+ "json5": "^2.2.3",
74
+ "nuxt": "^4.0.3",
75
+ "typescript": "^5.8.3",
76
+ "unplugin-icons": "^22.2.0",
77
+ "vitest": "^3.2.4",
78
+ "vue-tsc": "^3.0.6"
79
+ },
80
+ "release": {
81
+ "extends": [
82
+ "@alanscodelog/semantic-release-config"
83
+ ]
84
+ },
85
+ "commitlint": {
86
+ "extends": [
87
+ "@alanscodelog"
88
+ ]
89
+ },
90
+ "publishConfig": {
91
+ "access": "public"
92
+ }
93
+ }