@moonbase.sh/electron 0.1.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.
- package/README.md +40 -3
- package/dist/index.cjs +51 -11
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +51 -11
- package/dist/renderer.cjs +18 -0
- package/dist/renderer.d.cts +12 -0
- package/dist/renderer.d.ts +12 -0
- package/dist/renderer.js +0 -0
- package/dist/vite.cjs +79 -0
- package/dist/vite.d.cts +24 -0
- package/dist/vite.d.ts +24 -0
- package/dist/vite.js +51 -0
- package/package.json +40 -4
- package/preload/package.json +5 -0
- package/renderer/package.json +5 -0
- package/vite/package.json +5 -0
package/README.md
CHANGED
|
@@ -38,8 +38,27 @@ moonbase.start()
|
|
|
38
38
|
|
|
39
39
|
The license is kept in `license.mb` in the app's user data folder, and the app's own version (`app.getVersion()`)
|
|
40
40
|
is the version reported to Moonbase and the one a [license that covers some versions](https://www.npmjs.com/package/@moonbase.sh/licensing#licenses-that-cover-some-versions)
|
|
41
|
-
has to cover.
|
|
42
|
-
|
|
41
|
+
has to cover.
|
|
42
|
+
|
|
43
|
+
### Bundling the main process
|
|
44
|
+
|
|
45
|
+
The module loads its activation UI from the folder it runs from. Left out of the main process's bundle, it finds
|
|
46
|
+
the UI in `node_modules`. Bundled, as Electron Forge's Vite template does with every dependency, it needs the UI
|
|
47
|
+
copied beside the bundle, which the module's Vite plugin does. Add it to the main process's Vite config:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// vite.main.config.ts
|
|
51
|
+
import { moonbase } from '@moonbase.sh/electron/vite'
|
|
52
|
+
import { defineConfig } from 'vite'
|
|
53
|
+
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [moonbase()],
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
With another bundler, leave the module out of the bundle, or copy the package's `dist/ui` folder and
|
|
60
|
+
`dist/ui-preload.cjs` to the folder the bundled module runs from. If they are not there, `start()` throws and names
|
|
61
|
+
the folder it looked in.
|
|
43
62
|
|
|
44
63
|
## The activation UI
|
|
45
64
|
|
|
@@ -84,7 +103,10 @@ float over the app's content, which is blurred behind them and takes no clicks o
|
|
|
84
103
|
the overlay cannot be dismissed; once it has one it gets a close button and closes on Escape.
|
|
85
104
|
|
|
86
105
|
The overlay is a view of the module's own laid over the window, so it works whatever the app's page does, and it
|
|
87
|
-
survives the page reloading.
|
|
106
|
+
survives the page reloading. It locks one window: the one `ui.window` names, or the app's first. When that window
|
|
107
|
+
closes while the app is locked, the overlay moves to the next window the app opens, such as the one a macOS app opens
|
|
108
|
+
again from the dock. The app's other windows stay usable, so keep gating in the main process either way: the overlay
|
|
109
|
+
is a lock on the interface.
|
|
88
110
|
|
|
89
111
|
## Gating
|
|
90
112
|
|
|
@@ -118,11 +140,26 @@ exposeMoonbase()
|
|
|
118
140
|
|
|
119
141
|
```ts
|
|
120
142
|
// renderer
|
|
143
|
+
import type { ActivationState } from '@moonbase.sh/electron/renderer'
|
|
144
|
+
|
|
145
|
+
function render(state: ActivationState) {
|
|
146
|
+
document.querySelector('#license')!.textContent = state.licensed ? `Licensed to ${state.license?.issuedTo.name}` : 'Not activated'
|
|
147
|
+
}
|
|
148
|
+
|
|
121
149
|
window.moonbase.onStateChanged(render)
|
|
122
150
|
render(await window.moonbase.state())
|
|
123
151
|
await window.moonbase.activate()
|
|
124
152
|
```
|
|
125
153
|
|
|
154
|
+
`@moonbase.sh/electron/renderer` has the types for renderer code, and importing from it types `window.moonbase`. To
|
|
155
|
+
type `window.moonbase` without importing anything, reference it once from a declaration file:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
/// <reference types="@moonbase.sh/electron/renderer" />
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Leave it out if you expose the API under another name with `exposeMoonbase(key)`.
|
|
162
|
+
|
|
126
163
|
A sandboxed preload can require nothing but Electron, so bundle it, as Electron Forge and electron-vite do. The API
|
|
127
164
|
has the same calls as tauri-plugin-moonbase's: `state`, `activate`, `cancelActivation`, `refresh`, `deactivate`,
|
|
128
165
|
`forget`, `deviceToken`, `activateOffline`, `dismissError`, `device`, `checkUpdate`, `updateDownloadUrl`, `present`,
|
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,7 @@ var import_licensing = require("@moonbase.sh/licensing");
|
|
|
43
43
|
var import_electron = require("electron");
|
|
44
44
|
|
|
45
45
|
// package.json
|
|
46
|
-
var version = "0.
|
|
46
|
+
var version = "0.2.0";
|
|
47
47
|
|
|
48
48
|
// src/download.ts
|
|
49
49
|
function downloadState(phase, rest = {}) {
|
|
@@ -67,6 +67,7 @@ function errorOutcome(err) {
|
|
|
67
67
|
function uiFolder() {
|
|
68
68
|
return __dirname;
|
|
69
69
|
}
|
|
70
|
+
var UI_FILES = ["ui-preload.cjs", import_node_path.default.join("ui", "index.html"), import_node_path.default.join("ui", "overlay.html")];
|
|
70
71
|
function platformOs() {
|
|
71
72
|
switch (import_node_process.default.platform) {
|
|
72
73
|
case "darwin":
|
|
@@ -95,6 +96,8 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
95
96
|
this.folder = uiFolder();
|
|
96
97
|
this.window = null;
|
|
97
98
|
this.overlay = null;
|
|
99
|
+
/** Waiting for a window to lay the overlay over, when the app has none. */
|
|
100
|
+
this.waitingForWindow = null;
|
|
98
101
|
this.pendingScreen = null;
|
|
99
102
|
this.lastLicensed = null;
|
|
100
103
|
this.download = downloadState("idle");
|
|
@@ -121,6 +124,8 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
121
124
|
start() {
|
|
122
125
|
if (this.running)
|
|
123
126
|
return;
|
|
127
|
+
if (this.ui)
|
|
128
|
+
this.checkUiFiles();
|
|
124
129
|
this.running = true;
|
|
125
130
|
import_electron.ipcMain.handle("moonbase:invoke", (event, command, args) => this.handleRenderer(event, command, args ?? {}));
|
|
126
131
|
import_electron.ipcMain.handle("moonbase:ui", (event, command, args) => this.handleUi(event, command, args ?? {}));
|
|
@@ -142,6 +147,17 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
142
147
|
this.closeUi();
|
|
143
148
|
super.dispose();
|
|
144
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Stop here, where the developer sees it, rather than open a blank window or
|
|
152
|
+
* lock the app behind an overlay that never loads. The files go missing when
|
|
153
|
+
* the module is bundled into the main process without them.
|
|
154
|
+
*/
|
|
155
|
+
checkUiFiles() {
|
|
156
|
+
const missing = UI_FILES.filter((file) => !import_node_fs.default.existsSync(import_node_path.default.join(this.folder, file)));
|
|
157
|
+
if (missing.length === 0)
|
|
158
|
+
return;
|
|
159
|
+
throw new import_licensing.ActivationError("internal", `@moonbase.sh/electron can't find its activation UI in ${this.folder} (missing ${missing.join(", ")}). This happens when the module is bundled into the main process: add moonbase() from '@moonbase.sh/electron/vite' to the plugins of the main process's Vite config, which copies the UI beside the bundle, or leave the module out of the bundle. Pass ui: false to use a UI of your own instead.`);
|
|
160
|
+
}
|
|
145
161
|
isOwnUi(contents) {
|
|
146
162
|
return !!this.window && !this.window.isDestroyed() && this.window.webContents === contents || !!this.overlay && this.overlay.view.webContents === contents;
|
|
147
163
|
}
|
|
@@ -293,12 +309,14 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
293
309
|
windowTitle: ui.windowTitle ?? productName
|
|
294
310
|
};
|
|
295
311
|
}
|
|
312
|
+
/** The window `ui.window` names, if it is open. */
|
|
313
|
+
chosenWindow() {
|
|
314
|
+
const chosen = typeof this.ui?.window === "function" ? this.ui.window() : this.ui?.window;
|
|
315
|
+
return chosen && !chosen.isDestroyed() ? chosen : null;
|
|
316
|
+
}
|
|
296
317
|
/** The app's window the overlay locks, and the activation window's parent. */
|
|
297
318
|
targetWindow() {
|
|
298
|
-
|
|
299
|
-
if (chosen && !chosen.isDestroyed())
|
|
300
|
-
return chosen;
|
|
301
|
-
return import_electron.BrowserWindow.getAllWindows().filter((candidate) => !candidate.isDestroyed() && candidate !== this.window).sort((a, b) => a.id - b.id)[0] ?? null;
|
|
319
|
+
return this.chosenWindow() ?? import_electron.BrowserWindow.getAllWindows().filter((candidate) => !candidate.isDestroyed() && candidate !== this.window).sort((a, b) => a.id - b.id)[0] ?? null;
|
|
302
320
|
}
|
|
303
321
|
/** Hand the UI something new, wherever it is showing. */
|
|
304
322
|
push(name, payload) {
|
|
@@ -417,7 +435,7 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
417
435
|
this.window.setContentSize(WIDTH, Math.round(Math.min(900, Math.max(240, height))));
|
|
418
436
|
}
|
|
419
437
|
/** Lay the overlay over the app's window, or bring it to `screen` if it is up. */
|
|
420
|
-
mountOverlay(screen) {
|
|
438
|
+
mountOverlay(screen, target = this.targetWindow()) {
|
|
421
439
|
if (this.overlay && !this.overlay.target.isDestroyed()) {
|
|
422
440
|
if (screen)
|
|
423
441
|
this.push("show", screen);
|
|
@@ -425,10 +443,8 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
425
443
|
this.overlay.view.webContents.focus();
|
|
426
444
|
return;
|
|
427
445
|
}
|
|
428
|
-
const target = this.targetWindow();
|
|
429
446
|
if (!target) {
|
|
430
|
-
this.
|
|
431
|
-
import_electron.app.once("browser-window-created", () => setImmediate(() => this.mountOverlay(this.pendingScreen)));
|
|
447
|
+
this.lockNextWindow(screen);
|
|
432
448
|
return;
|
|
433
449
|
}
|
|
434
450
|
if (typeof import_electron.WebContentsView !== "function")
|
|
@@ -462,15 +478,39 @@ var MoonbaseElectron = class extends import_licensing.ActivationController {
|
|
|
462
478
|
target.on("resize", overlay.fit);
|
|
463
479
|
target.webContents.on("did-finish-load", overlay.reinsert);
|
|
464
480
|
target.once("closed", () => {
|
|
465
|
-
if (this.overlay
|
|
466
|
-
|
|
481
|
+
if (this.overlay !== overlay)
|
|
482
|
+
return;
|
|
483
|
+
this.overlay = null;
|
|
484
|
+
if (!view.webContents.isDestroyed())
|
|
485
|
+
view.webContents.close();
|
|
486
|
+
if (!this.state().licensed && (this.ui?.autoPresentOnLock ?? true))
|
|
487
|
+
this.lockNextWindow(null);
|
|
467
488
|
});
|
|
468
489
|
void view.webContents.loadFile(import_node_path.default.join(this.folder, "ui", "overlay.html"));
|
|
469
490
|
view.webContents.once("did-finish-load", () => view.webContents.focus());
|
|
470
491
|
target.show();
|
|
471
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Lay the overlay over the next window the app opens, or over the one
|
|
495
|
+
* `ui.window` names by then. Waits for one window at a time.
|
|
496
|
+
*/
|
|
497
|
+
lockNextWindow(screen) {
|
|
498
|
+
this.pendingScreen = screen;
|
|
499
|
+
if (this.waitingForWindow)
|
|
500
|
+
return;
|
|
501
|
+
const listener = (_event, created) => {
|
|
502
|
+
this.waitingForWindow = null;
|
|
503
|
+
setImmediate(() => this.mountOverlay(this.pendingScreen, this.chosenWindow() ?? (created.isDestroyed() ? null : created)));
|
|
504
|
+
};
|
|
505
|
+
this.waitingForWindow = listener;
|
|
506
|
+
import_electron.app.once("browser-window-created", listener);
|
|
507
|
+
}
|
|
472
508
|
/** Close the activation window, or take the overlay down, if it is showing. */
|
|
473
509
|
closeUi() {
|
|
510
|
+
if (this.waitingForWindow) {
|
|
511
|
+
import_electron.app.off("browser-window-created", this.waitingForWindow);
|
|
512
|
+
this.waitingForWindow = null;
|
|
513
|
+
}
|
|
474
514
|
if (this.window && !this.window.isDestroyed())
|
|
475
515
|
this.window.close();
|
|
476
516
|
this.window = null;
|
package/dist/index.d.cts
CHANGED
|
@@ -69,6 +69,8 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
69
69
|
private readonly folder;
|
|
70
70
|
private window;
|
|
71
71
|
private overlay;
|
|
72
|
+
/** Waiting for a window to lay the overlay over, when the app has none. */
|
|
73
|
+
private waitingForWindow;
|
|
72
74
|
private pendingScreen;
|
|
73
75
|
private lastLicensed;
|
|
74
76
|
private download;
|
|
@@ -82,6 +84,12 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
82
84
|
start(): void;
|
|
83
85
|
/** Stop watching, close the UI and stop answering renderers. */
|
|
84
86
|
dispose(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Stop here, where the developer sees it, rather than open a blank window or
|
|
89
|
+
* lock the app behind an overlay that never loads. The files go missing when
|
|
90
|
+
* the module is bundled into the main process without them.
|
|
91
|
+
*/
|
|
92
|
+
private checkUiFiles;
|
|
85
93
|
private readonly onSubscribe;
|
|
86
94
|
private readonly onWindowFocus;
|
|
87
95
|
private readonly onWindowBlur;
|
|
@@ -93,6 +101,8 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
93
101
|
private handleUi;
|
|
94
102
|
private runUi;
|
|
95
103
|
private pageConfig;
|
|
104
|
+
/** The window `ui.window` names, if it is open. */
|
|
105
|
+
private chosenWindow;
|
|
96
106
|
/** The app's window the overlay locks, and the activation window's parent. */
|
|
97
107
|
private targetWindow;
|
|
98
108
|
/** Hand the UI something new, wherever it is showing. */
|
|
@@ -113,6 +123,11 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
113
123
|
private uiResize;
|
|
114
124
|
/** Lay the overlay over the app's window, or bring it to `screen` if it is up. */
|
|
115
125
|
private mountOverlay;
|
|
126
|
+
/**
|
|
127
|
+
* Lay the overlay over the next window the app opens, or over the one
|
|
128
|
+
* `ui.window` names by then. Waits for one window at a time.
|
|
129
|
+
*/
|
|
130
|
+
private lockNextWindow;
|
|
116
131
|
/** Close the activation window, or take the overlay down, if it is showing. */
|
|
117
132
|
closeUi(): void;
|
|
118
133
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
69
69
|
private readonly folder;
|
|
70
70
|
private window;
|
|
71
71
|
private overlay;
|
|
72
|
+
/** Waiting for a window to lay the overlay over, when the app has none. */
|
|
73
|
+
private waitingForWindow;
|
|
72
74
|
private pendingScreen;
|
|
73
75
|
private lastLicensed;
|
|
74
76
|
private download;
|
|
@@ -82,6 +84,12 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
82
84
|
start(): void;
|
|
83
85
|
/** Stop watching, close the UI and stop answering renderers. */
|
|
84
86
|
dispose(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Stop here, where the developer sees it, rather than open a blank window or
|
|
89
|
+
* lock the app behind an overlay that never loads. The files go missing when
|
|
90
|
+
* the module is bundled into the main process without them.
|
|
91
|
+
*/
|
|
92
|
+
private checkUiFiles;
|
|
85
93
|
private readonly onSubscribe;
|
|
86
94
|
private readonly onWindowFocus;
|
|
87
95
|
private readonly onWindowBlur;
|
|
@@ -93,6 +101,8 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
93
101
|
private handleUi;
|
|
94
102
|
private runUi;
|
|
95
103
|
private pageConfig;
|
|
104
|
+
/** The window `ui.window` names, if it is open. */
|
|
105
|
+
private chosenWindow;
|
|
96
106
|
/** The app's window the overlay locks, and the activation window's parent. */
|
|
97
107
|
private targetWindow;
|
|
98
108
|
/** Hand the UI something new, wherever it is showing. */
|
|
@@ -113,6 +123,11 @@ declare class MoonbaseElectron extends ActivationController {
|
|
|
113
123
|
private uiResize;
|
|
114
124
|
/** Lay the overlay over the app's window, or bring it to `screen` if it is up. */
|
|
115
125
|
private mountOverlay;
|
|
126
|
+
/**
|
|
127
|
+
* Lay the overlay over the next window the app opens, or over the one
|
|
128
|
+
* `ui.window` names by then. Waits for one window at a time.
|
|
129
|
+
*/
|
|
130
|
+
private lockNextWindow;
|
|
116
131
|
/** Close the activation window, or take the overlay down, if it is showing. */
|
|
117
132
|
closeUi(): void;
|
|
118
133
|
/**
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { ActivationController, ActivationError, ReleaseNotCoveredError } from "@
|
|
|
15
15
|
import { app, BrowserWindow, clipboard, dialog, ipcMain, net, shell, WebContentsView } from "electron";
|
|
16
16
|
|
|
17
17
|
// package.json
|
|
18
|
-
var version = "0.
|
|
18
|
+
var version = "0.2.0";
|
|
19
19
|
|
|
20
20
|
// src/download.ts
|
|
21
21
|
function downloadState(phase, rest = {}) {
|
|
@@ -39,6 +39,7 @@ function errorOutcome(err) {
|
|
|
39
39
|
function uiFolder() {
|
|
40
40
|
return __dirname;
|
|
41
41
|
}
|
|
42
|
+
var UI_FILES = ["ui-preload.cjs", path2.join("ui", "index.html"), path2.join("ui", "overlay.html")];
|
|
42
43
|
function platformOs() {
|
|
43
44
|
switch (process.platform) {
|
|
44
45
|
case "darwin":
|
|
@@ -67,6 +68,8 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
67
68
|
this.folder = uiFolder();
|
|
68
69
|
this.window = null;
|
|
69
70
|
this.overlay = null;
|
|
71
|
+
/** Waiting for a window to lay the overlay over, when the app has none. */
|
|
72
|
+
this.waitingForWindow = null;
|
|
70
73
|
this.pendingScreen = null;
|
|
71
74
|
this.lastLicensed = null;
|
|
72
75
|
this.download = downloadState("idle");
|
|
@@ -93,6 +96,8 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
93
96
|
start() {
|
|
94
97
|
if (this.running)
|
|
95
98
|
return;
|
|
99
|
+
if (this.ui)
|
|
100
|
+
this.checkUiFiles();
|
|
96
101
|
this.running = true;
|
|
97
102
|
ipcMain.handle("moonbase:invoke", (event, command, args) => this.handleRenderer(event, command, args ?? {}));
|
|
98
103
|
ipcMain.handle("moonbase:ui", (event, command, args) => this.handleUi(event, command, args ?? {}));
|
|
@@ -114,6 +119,17 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
114
119
|
this.closeUi();
|
|
115
120
|
super.dispose();
|
|
116
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Stop here, where the developer sees it, rather than open a blank window or
|
|
124
|
+
* lock the app behind an overlay that never loads. The files go missing when
|
|
125
|
+
* the module is bundled into the main process without them.
|
|
126
|
+
*/
|
|
127
|
+
checkUiFiles() {
|
|
128
|
+
const missing = UI_FILES.filter((file) => !fs.existsSync(path2.join(this.folder, file)));
|
|
129
|
+
if (missing.length === 0)
|
|
130
|
+
return;
|
|
131
|
+
throw new ActivationError("internal", `@moonbase.sh/electron can't find its activation UI in ${this.folder} (missing ${missing.join(", ")}). This happens when the module is bundled into the main process: add moonbase() from '@moonbase.sh/electron/vite' to the plugins of the main process's Vite config, which copies the UI beside the bundle, or leave the module out of the bundle. Pass ui: false to use a UI of your own instead.`);
|
|
132
|
+
}
|
|
117
133
|
isOwnUi(contents) {
|
|
118
134
|
return !!this.window && !this.window.isDestroyed() && this.window.webContents === contents || !!this.overlay && this.overlay.view.webContents === contents;
|
|
119
135
|
}
|
|
@@ -265,12 +281,14 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
265
281
|
windowTitle: ui.windowTitle ?? productName
|
|
266
282
|
};
|
|
267
283
|
}
|
|
284
|
+
/** The window `ui.window` names, if it is open. */
|
|
285
|
+
chosenWindow() {
|
|
286
|
+
const chosen = typeof this.ui?.window === "function" ? this.ui.window() : this.ui?.window;
|
|
287
|
+
return chosen && !chosen.isDestroyed() ? chosen : null;
|
|
288
|
+
}
|
|
268
289
|
/** The app's window the overlay locks, and the activation window's parent. */
|
|
269
290
|
targetWindow() {
|
|
270
|
-
|
|
271
|
-
if (chosen && !chosen.isDestroyed())
|
|
272
|
-
return chosen;
|
|
273
|
-
return BrowserWindow.getAllWindows().filter((candidate) => !candidate.isDestroyed() && candidate !== this.window).sort((a, b) => a.id - b.id)[0] ?? null;
|
|
291
|
+
return this.chosenWindow() ?? BrowserWindow.getAllWindows().filter((candidate) => !candidate.isDestroyed() && candidate !== this.window).sort((a, b) => a.id - b.id)[0] ?? null;
|
|
274
292
|
}
|
|
275
293
|
/** Hand the UI something new, wherever it is showing. */
|
|
276
294
|
push(name, payload) {
|
|
@@ -389,7 +407,7 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
389
407
|
this.window.setContentSize(WIDTH, Math.round(Math.min(900, Math.max(240, height))));
|
|
390
408
|
}
|
|
391
409
|
/** Lay the overlay over the app's window, or bring it to `screen` if it is up. */
|
|
392
|
-
mountOverlay(screen) {
|
|
410
|
+
mountOverlay(screen, target = this.targetWindow()) {
|
|
393
411
|
if (this.overlay && !this.overlay.target.isDestroyed()) {
|
|
394
412
|
if (screen)
|
|
395
413
|
this.push("show", screen);
|
|
@@ -397,10 +415,8 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
397
415
|
this.overlay.view.webContents.focus();
|
|
398
416
|
return;
|
|
399
417
|
}
|
|
400
|
-
const target = this.targetWindow();
|
|
401
418
|
if (!target) {
|
|
402
|
-
this.
|
|
403
|
-
app.once("browser-window-created", () => setImmediate(() => this.mountOverlay(this.pendingScreen)));
|
|
419
|
+
this.lockNextWindow(screen);
|
|
404
420
|
return;
|
|
405
421
|
}
|
|
406
422
|
if (typeof WebContentsView !== "function")
|
|
@@ -434,15 +450,39 @@ var MoonbaseElectron = class extends ActivationController {
|
|
|
434
450
|
target.on("resize", overlay.fit);
|
|
435
451
|
target.webContents.on("did-finish-load", overlay.reinsert);
|
|
436
452
|
target.once("closed", () => {
|
|
437
|
-
if (this.overlay
|
|
438
|
-
|
|
453
|
+
if (this.overlay !== overlay)
|
|
454
|
+
return;
|
|
455
|
+
this.overlay = null;
|
|
456
|
+
if (!view.webContents.isDestroyed())
|
|
457
|
+
view.webContents.close();
|
|
458
|
+
if (!this.state().licensed && (this.ui?.autoPresentOnLock ?? true))
|
|
459
|
+
this.lockNextWindow(null);
|
|
439
460
|
});
|
|
440
461
|
void view.webContents.loadFile(path2.join(this.folder, "ui", "overlay.html"));
|
|
441
462
|
view.webContents.once("did-finish-load", () => view.webContents.focus());
|
|
442
463
|
target.show();
|
|
443
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Lay the overlay over the next window the app opens, or over the one
|
|
467
|
+
* `ui.window` names by then. Waits for one window at a time.
|
|
468
|
+
*/
|
|
469
|
+
lockNextWindow(screen) {
|
|
470
|
+
this.pendingScreen = screen;
|
|
471
|
+
if (this.waitingForWindow)
|
|
472
|
+
return;
|
|
473
|
+
const listener = (_event, created) => {
|
|
474
|
+
this.waitingForWindow = null;
|
|
475
|
+
setImmediate(() => this.mountOverlay(this.pendingScreen, this.chosenWindow() ?? (created.isDestroyed() ? null : created)));
|
|
476
|
+
};
|
|
477
|
+
this.waitingForWindow = listener;
|
|
478
|
+
app.once("browser-window-created", listener);
|
|
479
|
+
}
|
|
444
480
|
/** Close the activation window, or take the overlay down, if it is showing. */
|
|
445
481
|
closeUi() {
|
|
482
|
+
if (this.waitingForWindow) {
|
|
483
|
+
app.off("browser-window-created", this.waitingForWindow);
|
|
484
|
+
this.waitingForWindow = null;
|
|
485
|
+
}
|
|
446
486
|
if (this.window && !this.window.isDestroyed())
|
|
447
487
|
this.window.close();
|
|
448
488
|
this.window = null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/renderer.ts
|
|
17
|
+
var renderer_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(renderer_exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MoonbaseRendererApi } from './preload.cjs';
|
|
2
|
+
export { MoonbaseRendererError } from './preload.cjs';
|
|
3
|
+
export { ActivationScreen, ActivationState, DeviceInfo, DownloadTarget, License, UpdateInfo } from '@moonbase.sh/licensing';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
/** Moonbase, as `exposeMoonbase()` exposed it from the window's preload. */
|
|
8
|
+
moonbase: MoonbaseRendererApi;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { MoonbaseRendererApi };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MoonbaseRendererApi } from './preload.js';
|
|
2
|
+
export { MoonbaseRendererError } from './preload.js';
|
|
3
|
+
export { ActivationScreen, ActivationState, DeviceInfo, DownloadTarget, License, UpdateInfo } from '@moonbase.sh/licensing';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
/** Moonbase, as `exposeMoonbase()` exposed it from the window's preload. */
|
|
8
|
+
moonbase: MoonbaseRendererApi;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { MoonbaseRendererApi };
|
package/dist/renderer.js
ADDED
|
File without changes
|
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
|
+
});
|
package/dist/vite.d.cts
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.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,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/electron",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "Moonbase.sh licensing for Electron apps, with a finished activation UI",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -27,6 +27,26 @@
|
|
|
27
27
|
"default": "./dist/preload.cjs"
|
|
28
28
|
}
|
|
29
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
|
+
},
|
|
30
50
|
"./package.json": "./package.json"
|
|
31
51
|
},
|
|
32
52
|
"main": "./dist/index.cjs",
|
|
@@ -36,20 +56,35 @@
|
|
|
36
56
|
"*": {
|
|
37
57
|
"preload": [
|
|
38
58
|
"./dist/preload.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"renderer": [
|
|
61
|
+
"./dist/renderer.d.ts"
|
|
62
|
+
],
|
|
63
|
+
"vite": [
|
|
64
|
+
"./dist/vite.d.ts"
|
|
39
65
|
]
|
|
40
66
|
}
|
|
41
67
|
},
|
|
42
68
|
"files": [
|
|
43
|
-
"dist/**"
|
|
69
|
+
"dist/**",
|
|
70
|
+
"preload",
|
|
71
|
+
"renderer",
|
|
72
|
+
"vite"
|
|
44
73
|
],
|
|
45
74
|
"engines": {
|
|
46
75
|
"node": ">=18.0.0"
|
|
47
76
|
},
|
|
48
77
|
"peerDependencies": {
|
|
49
|
-
"electron": ">=30"
|
|
78
|
+
"electron": ">=30",
|
|
79
|
+
"vite": ">=5"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"vite": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
50
85
|
},
|
|
51
86
|
"dependencies": {
|
|
52
|
-
"@moonbase.sh/licensing": "3.
|
|
87
|
+
"@moonbase.sh/licensing": "3.5.0"
|
|
53
88
|
},
|
|
54
89
|
"devDependencies": {
|
|
55
90
|
"@types/jsonwebtoken": "^9.0.9",
|
|
@@ -60,6 +95,7 @@
|
|
|
60
95
|
"rimraf": "^5.0.10",
|
|
61
96
|
"tsup": "^8.5.0",
|
|
62
97
|
"typescript": "~5.8.3",
|
|
98
|
+
"vite": "^5.4.19",
|
|
63
99
|
"vitest": "^2.1.4"
|
|
64
100
|
},
|
|
65
101
|
"scripts": {
|