@moonbase.sh/electron 0.0.0 → 0.2.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.
@@ -0,0 +1,29 @@
1
+ // Boots the activation UI as the module's own window: the page is the panel, and
2
+ // the window is resized to fit each screen.
3
+ ;(async () => {
4
+ const bridge = window.moonbaseUi
5
+ const invoke = (command, args = {}) => bridge.invoke(command, args)
6
+ const config = await invoke('ui_config')
7
+ document.title = config.windowTitle || config.productName
8
+ if (config.reduceMotion) document.body.classList.add('reduce-motion')
9
+
10
+ let ready = false
11
+ const ui = createActivationUI({
12
+ root: document.getElementById('app'),
13
+ config,
14
+ invoke,
15
+ mode: 'window',
16
+ async onHeight(height) {
17
+ if (ready) return invoke('ui_resize', { height })
18
+ ready = true
19
+ const opened = await invoke('ui_ready', { height })
20
+ if (opened?.screen) ui.show(opened.screen)
21
+ },
22
+ })
23
+ bridge.onPush((name, payload) => ui[name]?.(payload))
24
+
25
+ document.addEventListener('keydown', (event) => {
26
+ if (event.key === 'Escape' && ui.canClose()) invoke('close_ui')
27
+ })
28
+ ui.start()
29
+ })()
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ // src/uiPreload.ts
4
+ var import_electron = require("electron");
5
+ import_electron.contextBridge.exposeInMainWorld("moonbaseUi", {
6
+ async invoke(command, args = {}) {
7
+ const outcome = await import_electron.ipcRenderer.invoke("moonbase:ui", command, args);
8
+ if (!outcome.ok)
9
+ throw outcome.error;
10
+ return outcome.value;
11
+ },
12
+ onPush(callback) {
13
+ import_electron.ipcRenderer.on("moonbase:push", (_event, name, payload) => callback(name, payload));
14
+ }
15
+ });
package/dist/vite.cjs ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/vite.ts
31
+ var vite_exports = {};
32
+ __export(vite_exports, {
33
+ moonbase: () => moonbase
34
+ });
35
+ module.exports = __toCommonJS(vite_exports);
36
+ var import_promises = __toESM(require("fs/promises"), 1);
37
+ var import_node_path = __toESM(require("path"), 1);
38
+ async function filesIn(folder, prefix) {
39
+ const entries = await import_promises.default.readdir(import_node_path.default.join(folder, prefix), { withFileTypes: true });
40
+ const nested = await Promise.all(entries.map((entry) => {
41
+ const file = import_node_path.default.posix.join(prefix, entry.name);
42
+ return entry.isDirectory() ? filesIn(folder, file) : [file];
43
+ }));
44
+ return nested.flat();
45
+ }
46
+ function slashes(file) {
47
+ return file.replace(/\\/g, "/");
48
+ }
49
+ function moonbase() {
50
+ const folder = slashes(__dirname);
51
+ const entries = /* @__PURE__ */ new Set([`${folder}/index.js`, `${folder}/index.cjs`]);
52
+ const isModule = (id) => entries.has(slashes(id.replace(/^\0/, "").replace(/\?.*$/, "")));
53
+ return {
54
+ name: "@moonbase.sh/electron",
55
+ apply: "build",
56
+ async generateBundle(_options, bundle) {
57
+ const targets = /* @__PURE__ */ new Set();
58
+ for (const output of Object.values(bundle)) {
59
+ if (output.type === "chunk" && output.moduleIds.some(isModule))
60
+ targets.add(import_node_path.default.posix.dirname(output.fileName));
61
+ }
62
+ if (targets.size === 0)
63
+ return;
64
+ const files = ["ui-preload.cjs", ...await filesIn(folder, "ui")];
65
+ const sources = await Promise.all(files.map((file) => import_promises.default.readFile(import_node_path.default.join(folder, file))));
66
+ for (const target of targets) {
67
+ files.forEach((file, i) => this.emitFile({
68
+ type: "asset",
69
+ fileName: target === "." ? file : `${target}/${file}`,
70
+ source: sources[i]
71
+ }));
72
+ }
73
+ }
74
+ };
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ moonbase
79
+ });
@@ -0,0 +1,24 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * A Vite plugin for an app that bundles `@moonbase.sh/electron` into its main
5
+ * process, as Electron Forge's Vite template does. The module loads its
6
+ * activation UI from the folder it runs from, so the plugin copies the UI beside
7
+ * the output file the module ends up in:
8
+ *
9
+ * ```ts
10
+ * // vite.main.config.ts
11
+ * import { moonbase } from '@moonbase.sh/electron/vite'
12
+ * import { defineConfig } from 'vite'
13
+ *
14
+ * export default defineConfig({
15
+ * plugins: [moonbase()],
16
+ * })
17
+ * ```
18
+ *
19
+ * It copies nothing when the module is left out of the bundle, since it then
20
+ * loads the UI from `node_modules`.
21
+ */
22
+ declare function moonbase(): Plugin;
23
+
24
+ export { moonbase };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * A Vite plugin for an app that bundles `@moonbase.sh/electron` into its main
5
+ * process, as Electron Forge's Vite template does. The module loads its
6
+ * activation UI from the folder it runs from, so the plugin copies the UI beside
7
+ * the output file the module ends up in:
8
+ *
9
+ * ```ts
10
+ * // vite.main.config.ts
11
+ * import { moonbase } from '@moonbase.sh/electron/vite'
12
+ * import { defineConfig } from 'vite'
13
+ *
14
+ * export default defineConfig({
15
+ * plugins: [moonbase()],
16
+ * })
17
+ * ```
18
+ *
19
+ * It copies nothing when the module is left out of the bundle, since it then
20
+ * loads the UI from `node_modules`.
21
+ */
22
+ declare function moonbase(): Plugin;
23
+
24
+ export { moonbase };
package/dist/vite.js ADDED
@@ -0,0 +1,51 @@
1
+ // ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.8_@types+node@18.19.64__jiti@2.7.0_postcss@8.5_fd9278b0af519e5ced4e697ff9c2675a/node_modules/tsup/assets/esm_shims.js
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ var getFilename = () => fileURLToPath(import.meta.url);
5
+ var getDirname = () => path.dirname(getFilename());
6
+ var __dirname = /* @__PURE__ */ getDirname();
7
+
8
+ // src/vite.ts
9
+ import fs from "fs/promises";
10
+ import path2 from "path";
11
+ async function filesIn(folder, prefix) {
12
+ const entries = await fs.readdir(path2.join(folder, prefix), { withFileTypes: true });
13
+ const nested = await Promise.all(entries.map((entry) => {
14
+ const file = path2.posix.join(prefix, entry.name);
15
+ return entry.isDirectory() ? filesIn(folder, file) : [file];
16
+ }));
17
+ return nested.flat();
18
+ }
19
+ function slashes(file) {
20
+ return file.replace(/\\/g, "/");
21
+ }
22
+ function moonbase() {
23
+ const folder = slashes(__dirname);
24
+ const entries = /* @__PURE__ */ new Set([`${folder}/index.js`, `${folder}/index.cjs`]);
25
+ const isModule = (id) => entries.has(slashes(id.replace(/^\0/, "").replace(/\?.*$/, "")));
26
+ return {
27
+ name: "@moonbase.sh/electron",
28
+ apply: "build",
29
+ async generateBundle(_options, bundle) {
30
+ const targets = /* @__PURE__ */ new Set();
31
+ for (const output of Object.values(bundle)) {
32
+ if (output.type === "chunk" && output.moduleIds.some(isModule))
33
+ targets.add(path2.posix.dirname(output.fileName));
34
+ }
35
+ if (targets.size === 0)
36
+ return;
37
+ const files = ["ui-preload.cjs", ...await filesIn(folder, "ui")];
38
+ const sources = await Promise.all(files.map((file) => fs.readFile(path2.join(folder, file))));
39
+ for (const target of targets) {
40
+ files.forEach((file, i) => this.emitFile({
41
+ type: "asset",
42
+ fileName: target === "." ? file : `${target}/${file}`,
43
+ source: sources[i]
44
+ }));
45
+ }
46
+ }
47
+ };
48
+ }
49
+ export {
50
+ moonbase
51
+ };
package/package.json CHANGED
@@ -1,7 +1,111 @@
1
1
  {
2
2
  "name": "@moonbase.sh/electron",
3
- "version": "0.0.0",
4
- "description": "Placeholder for Moonbase licensing for Electron apps. The first release is 0.1.0.",
3
+ "type": "module",
4
+ "version": "0.2.0",
5
+ "description": "Moonbase.sh licensing for Electron apps, with a finished activation UI",
5
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
6
- "license": "MIT"
7
- }
7
+ "license": "MIT",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./preload": {
21
+ "import": {
22
+ "types": "./dist/preload.d.ts",
23
+ "default": "./dist/preload.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/preload.d.cts",
27
+ "default": "./dist/preload.cjs"
28
+ }
29
+ },
30
+ "./renderer": {
31
+ "import": {
32
+ "types": "./dist/renderer.d.ts",
33
+ "default": "./dist/renderer.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/renderer.d.cts",
37
+ "default": "./dist/renderer.cjs"
38
+ }
39
+ },
40
+ "./vite": {
41
+ "import": {
42
+ "types": "./dist/vite.d.ts",
43
+ "default": "./dist/vite.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/vite.d.cts",
47
+ "default": "./dist/vite.cjs"
48
+ }
49
+ },
50
+ "./package.json": "./package.json"
51
+ },
52
+ "main": "./dist/index.cjs",
53
+ "module": "./dist/index.js",
54
+ "types": "./dist/index.d.ts",
55
+ "typesVersions": {
56
+ "*": {
57
+ "preload": [
58
+ "./dist/preload.d.ts"
59
+ ],
60
+ "renderer": [
61
+ "./dist/renderer.d.ts"
62
+ ],
63
+ "vite": [
64
+ "./dist/vite.d.ts"
65
+ ]
66
+ }
67
+ },
68
+ "files": [
69
+ "dist/**",
70
+ "preload",
71
+ "renderer",
72
+ "vite"
73
+ ],
74
+ "engines": {
75
+ "node": ">=18.0.0"
76
+ },
77
+ "peerDependencies": {
78
+ "electron": ">=30",
79
+ "vite": ">=5"
80
+ },
81
+ "peerDependenciesMeta": {
82
+ "vite": {
83
+ "optional": true
84
+ }
85
+ },
86
+ "dependencies": {
87
+ "@moonbase.sh/licensing": "3.5.0"
88
+ },
89
+ "devDependencies": {
90
+ "@types/jsonwebtoken": "^9.0.9",
91
+ "@types/node": "^18.19.50",
92
+ "cross-fetch": "^3.1.5",
93
+ "electron": "^39.8.10",
94
+ "jsonwebtoken": "^9.0.2",
95
+ "rimraf": "^5.0.10",
96
+ "tsup": "^8.5.0",
97
+ "typescript": "~5.8.3",
98
+ "vite": "^5.4.19",
99
+ "vitest": "^2.1.4"
100
+ },
101
+ "scripts": {
102
+ "build": "rimraf dist && tsup",
103
+ "dev": "tsup --watch",
104
+ "type-check": "tsc --noEmit -p tsconfig.typecheck.json",
105
+ "lint": "eslint . --cache --cache-location node_modules/.cache/eslint/ --cache-strategy content",
106
+ "lint:fix": "eslint . --cache --cache-location node_modules/.cache/eslint/ --cache-strategy content --fix",
107
+ "test": "vitest run",
108
+ "test:watch": "vitest",
109
+ "test:integration": "TEST_INTEGRATION=true vitest run"
110
+ }
111
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/preload.cjs",
3
+ "module": "../dist/preload.js",
4
+ "types": "../dist/preload.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/renderer.cjs",
3
+ "module": "../dist/renderer.js",
4
+ "types": "../dist/renderer.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/vite.cjs",
3
+ "module": "../dist/vite.js",
4
+ "types": "../dist/vite.d.ts"
5
+ }