@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,171 @@
1
+ import { ActivationUiOptions, ActivationControllerOptions, ActivationController, ActivationScreen } from '@moonbase.sh/licensing';
2
+ export { ActivationScreen, ActivationState, ActivationStrings, ActivationUiOptions, TrialFeature } from '@moonbase.sh/licensing';
3
+ import { BrowserWindow, WebContents } from 'electron';
4
+
5
+ /**
6
+ * What a renderer other than the module's own UI may do: everything a UI of your
7
+ * own needs (`full`), only read the license and open the activation UI
8
+ * (`read-only`), or nothing.
9
+ */
10
+ type RendererAccess = 'full' | 'read-only' | 'none';
11
+ /** Branding and behaviour of the built-in activation UI. */
12
+ interface ElectronUiOptions extends ActivationUiOptions {
13
+ /** The product mark in the header, as SVG markup. Without one, a sun mark is drawn in the accent colour. */
14
+ logoSvg?: string;
15
+ /** The product mark in the header, as PNG bytes or the path to a PNG. Supply at least 76 px square. */
16
+ logoPng?: Uint8Array | string;
17
+ /** The activation window's title. Defaults to the product name. */
18
+ windowTitle?: string;
19
+ /**
20
+ * `window` (the default) shows the UI in its own window beside the app, which
21
+ * stays usable. `overlay` shows it over one of the app's windows, which is
22
+ * blurred and takes no input until the app is licensed.
23
+ */
24
+ presentation?: 'window' | 'overlay';
25
+ /**
26
+ * The window the overlay locks, and the activation window's parent. Defaults to
27
+ * the app's first window.
28
+ */
29
+ window?: BrowserWindow | (() => BrowserWindow | null | undefined);
30
+ }
31
+ /** What {@link MoonbaseElectron} is built from. */
32
+ interface MoonbaseElectronOptions extends Omit<ActivationControllerOptions, 'licenseFile' | 'openUrl' | 'productName' | 'accountName'> {
33
+ /** Where the license is kept. Defaults to `license.mb` in the app's user data folder. */
34
+ licenseFile?: string;
35
+ /**
36
+ * Opens a link in the browser. Defaults to `shell.openExternal`.
37
+ */
38
+ openUrl?: (url: string) => void | Promise<void>;
39
+ /** The built-in activation UI, on by default. `false` turns it off, for a UI of your own. */
40
+ ui?: ElectronUiOptions | false;
41
+ /**
42
+ * What the app's renderers may do through `exposeMoonbase()`. Defaults to
43
+ * `full`. The module's own UI is always allowed what it needs.
44
+ */
45
+ rendererAccess?: RendererAccess | ((contents: WebContents) => RendererAccess);
46
+ }
47
+ /**
48
+ * Moonbase licensing for an Electron app: the {@link ActivationController}, with
49
+ * a finished activation UI the app does not have to build. It validates the
50
+ * stored license at startup, runs browser and offline activation, trials,
51
+ * deactivation, add-ons and update downloads, and presents the activation UI
52
+ * whenever the app is locked, in its own window or over the app's window.
53
+ *
54
+ * Construct it in the main process and call {@link start}. Gate what the
55
+ * customer pays for here, where a renderer cannot skip the check:
56
+ *
57
+ * ```ts
58
+ * if (!moonbase.isLicensed()) {
59
+ * moonbase.present()
60
+ * return
61
+ * }
62
+ * ```
63
+ */
64
+ declare class MoonbaseElectron extends ActivationController {
65
+ private readonly ui;
66
+ private readonly rendererAccess;
67
+ private readonly endpoint;
68
+ private readonly subscribers;
69
+ private readonly folder;
70
+ private window;
71
+ private overlay;
72
+ /** Waiting for a window to lay the overlay over, when the app has none. */
73
+ private waitingForWindow;
74
+ private pendingScreen;
75
+ private lastLicensed;
76
+ private download;
77
+ private downloaded;
78
+ private running;
79
+ constructor(options: MoonbaseElectronOptions);
80
+ /**
81
+ * Validate the stored license, start watching it, and answer the app's
82
+ * renderers. Call once, before or after the app is ready.
83
+ */
84
+ start(): void;
85
+ /** Stop watching, close the UI and stop answering renderers. */
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;
93
+ private readonly onSubscribe;
94
+ private readonly onWindowFocus;
95
+ private readonly onWindowBlur;
96
+ private isOwnUi;
97
+ private accessOf;
98
+ private handleRenderer;
99
+ private run;
100
+ /** The built-in UI's own commands, which only its window or overlay may call. */
101
+ private handleUi;
102
+ private runUi;
103
+ private pageConfig;
104
+ /** The window `ui.window` names, if it is open. */
105
+ private chosenWindow;
106
+ /** The app's window the overlay locks, and the activation window's parent. */
107
+ private targetWindow;
108
+ /** Hand the UI something new, wherever it is showing. */
109
+ private push;
110
+ private afterStateChange;
111
+ private presentQuietly;
112
+ /**
113
+ * Show the activation UI and bring it to the front, creating it when needed:
114
+ * its own window, or the overlay over the app's window. `screen` opens it on a
115
+ * particular screen; without one it shows whatever the license state calls for.
116
+ */
117
+ present(screen?: ActivationScreen): Promise<void>;
118
+ private webPreferences;
119
+ /** The UI's pages load nothing but their own files, and open nothing themselves. */
120
+ private lockDown;
121
+ private createWindow;
122
+ private uiReady;
123
+ private uiResize;
124
+ /** Lay the overlay over the app's window, or bring it to `screen` if it is up. */
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;
131
+ /** Close the activation window, or take the overlay down, if it is showing. */
132
+ closeUi(): void;
133
+ /**
134
+ * Open a link from the UI in the browser: the pending activation, the store, or
135
+ * Moonbase's site from the footer. Nothing else, so the UI cannot be used to
136
+ * open arbitrary links.
137
+ */
138
+ private openLink;
139
+ /**
140
+ * Save the machine file for offline activation through a save dialog. Null when
141
+ * the customer cancels.
142
+ */
143
+ saveMachineFile(parent?: BrowserWindow | null): Promise<string | null>;
144
+ private setDownload;
145
+ /**
146
+ * Download the latest installer for this platform into Downloads, reporting
147
+ * progress to the UI, then show it in the file manager.
148
+ */
149
+ downloadUpdate(): Promise<void>;
150
+ /** Show the downloaded installer in the file manager again. */
151
+ revealUpdate(): void;
152
+ }
153
+ /**
154
+ * Moonbase licensing with a built-in activation UI, for an Electron app's main
155
+ * process:
156
+ *
157
+ * ```ts
158
+ * import { createMoonbase } from '@moonbase.sh/electron'
159
+ *
160
+ * const moonbase = createMoonbase({
161
+ * endpoint: 'https://your-store.moonbase.sh',
162
+ * productId: 'your-product',
163
+ * publicKey: MOONBASE_PUBLIC_KEY,
164
+ * ui: { productName: 'Solstice', manufacturerName: 'Helio Audio' },
165
+ * })
166
+ * moonbase.start()
167
+ * ```
168
+ */
169
+ declare function createMoonbase(options: MoonbaseElectronOptions): MoonbaseElectron;
170
+
171
+ export { type ElectronUiOptions, MoonbaseElectron, type MoonbaseElectronOptions, type RendererAccess, createMoonbase };
@@ -0,0 +1,171 @@
1
+ import { ActivationUiOptions, ActivationControllerOptions, ActivationController, ActivationScreen } from '@moonbase.sh/licensing';
2
+ export { ActivationScreen, ActivationState, ActivationStrings, ActivationUiOptions, TrialFeature } from '@moonbase.sh/licensing';
3
+ import { BrowserWindow, WebContents } from 'electron';
4
+
5
+ /**
6
+ * What a renderer other than the module's own UI may do: everything a UI of your
7
+ * own needs (`full`), only read the license and open the activation UI
8
+ * (`read-only`), or nothing.
9
+ */
10
+ type RendererAccess = 'full' | 'read-only' | 'none';
11
+ /** Branding and behaviour of the built-in activation UI. */
12
+ interface ElectronUiOptions extends ActivationUiOptions {
13
+ /** The product mark in the header, as SVG markup. Without one, a sun mark is drawn in the accent colour. */
14
+ logoSvg?: string;
15
+ /** The product mark in the header, as PNG bytes or the path to a PNG. Supply at least 76 px square. */
16
+ logoPng?: Uint8Array | string;
17
+ /** The activation window's title. Defaults to the product name. */
18
+ windowTitle?: string;
19
+ /**
20
+ * `window` (the default) shows the UI in its own window beside the app, which
21
+ * stays usable. `overlay` shows it over one of the app's windows, which is
22
+ * blurred and takes no input until the app is licensed.
23
+ */
24
+ presentation?: 'window' | 'overlay';
25
+ /**
26
+ * The window the overlay locks, and the activation window's parent. Defaults to
27
+ * the app's first window.
28
+ */
29
+ window?: BrowserWindow | (() => BrowserWindow | null | undefined);
30
+ }
31
+ /** What {@link MoonbaseElectron} is built from. */
32
+ interface MoonbaseElectronOptions extends Omit<ActivationControllerOptions, 'licenseFile' | 'openUrl' | 'productName' | 'accountName'> {
33
+ /** Where the license is kept. Defaults to `license.mb` in the app's user data folder. */
34
+ licenseFile?: string;
35
+ /**
36
+ * Opens a link in the browser. Defaults to `shell.openExternal`.
37
+ */
38
+ openUrl?: (url: string) => void | Promise<void>;
39
+ /** The built-in activation UI, on by default. `false` turns it off, for a UI of your own. */
40
+ ui?: ElectronUiOptions | false;
41
+ /**
42
+ * What the app's renderers may do through `exposeMoonbase()`. Defaults to
43
+ * `full`. The module's own UI is always allowed what it needs.
44
+ */
45
+ rendererAccess?: RendererAccess | ((contents: WebContents) => RendererAccess);
46
+ }
47
+ /**
48
+ * Moonbase licensing for an Electron app: the {@link ActivationController}, with
49
+ * a finished activation UI the app does not have to build. It validates the
50
+ * stored license at startup, runs browser and offline activation, trials,
51
+ * deactivation, add-ons and update downloads, and presents the activation UI
52
+ * whenever the app is locked, in its own window or over the app's window.
53
+ *
54
+ * Construct it in the main process and call {@link start}. Gate what the
55
+ * customer pays for here, where a renderer cannot skip the check:
56
+ *
57
+ * ```ts
58
+ * if (!moonbase.isLicensed()) {
59
+ * moonbase.present()
60
+ * return
61
+ * }
62
+ * ```
63
+ */
64
+ declare class MoonbaseElectron extends ActivationController {
65
+ private readonly ui;
66
+ private readonly rendererAccess;
67
+ private readonly endpoint;
68
+ private readonly subscribers;
69
+ private readonly folder;
70
+ private window;
71
+ private overlay;
72
+ /** Waiting for a window to lay the overlay over, when the app has none. */
73
+ private waitingForWindow;
74
+ private pendingScreen;
75
+ private lastLicensed;
76
+ private download;
77
+ private downloaded;
78
+ private running;
79
+ constructor(options: MoonbaseElectronOptions);
80
+ /**
81
+ * Validate the stored license, start watching it, and answer the app's
82
+ * renderers. Call once, before or after the app is ready.
83
+ */
84
+ start(): void;
85
+ /** Stop watching, close the UI and stop answering renderers. */
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;
93
+ private readonly onSubscribe;
94
+ private readonly onWindowFocus;
95
+ private readonly onWindowBlur;
96
+ private isOwnUi;
97
+ private accessOf;
98
+ private handleRenderer;
99
+ private run;
100
+ /** The built-in UI's own commands, which only its window or overlay may call. */
101
+ private handleUi;
102
+ private runUi;
103
+ private pageConfig;
104
+ /** The window `ui.window` names, if it is open. */
105
+ private chosenWindow;
106
+ /** The app's window the overlay locks, and the activation window's parent. */
107
+ private targetWindow;
108
+ /** Hand the UI something new, wherever it is showing. */
109
+ private push;
110
+ private afterStateChange;
111
+ private presentQuietly;
112
+ /**
113
+ * Show the activation UI and bring it to the front, creating it when needed:
114
+ * its own window, or the overlay over the app's window. `screen` opens it on a
115
+ * particular screen; without one it shows whatever the license state calls for.
116
+ */
117
+ present(screen?: ActivationScreen): Promise<void>;
118
+ private webPreferences;
119
+ /** The UI's pages load nothing but their own files, and open nothing themselves. */
120
+ private lockDown;
121
+ private createWindow;
122
+ private uiReady;
123
+ private uiResize;
124
+ /** Lay the overlay over the app's window, or bring it to `screen` if it is up. */
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;
131
+ /** Close the activation window, or take the overlay down, if it is showing. */
132
+ closeUi(): void;
133
+ /**
134
+ * Open a link from the UI in the browser: the pending activation, the store, or
135
+ * Moonbase's site from the footer. Nothing else, so the UI cannot be used to
136
+ * open arbitrary links.
137
+ */
138
+ private openLink;
139
+ /**
140
+ * Save the machine file for offline activation through a save dialog. Null when
141
+ * the customer cancels.
142
+ */
143
+ saveMachineFile(parent?: BrowserWindow | null): Promise<string | null>;
144
+ private setDownload;
145
+ /**
146
+ * Download the latest installer for this platform into Downloads, reporting
147
+ * progress to the UI, then show it in the file manager.
148
+ */
149
+ downloadUpdate(): Promise<void>;
150
+ /** Show the downloaded installer in the file manager again. */
151
+ revealUpdate(): void;
152
+ }
153
+ /**
154
+ * Moonbase licensing with a built-in activation UI, for an Electron app's main
155
+ * process:
156
+ *
157
+ * ```ts
158
+ * import { createMoonbase } from '@moonbase.sh/electron'
159
+ *
160
+ * const moonbase = createMoonbase({
161
+ * endpoint: 'https://your-store.moonbase.sh',
162
+ * productId: 'your-product',
163
+ * publicKey: MOONBASE_PUBLIC_KEY,
164
+ * ui: { productName: 'Solstice', manufacturerName: 'Helio Audio' },
165
+ * })
166
+ * moonbase.start()
167
+ * ```
168
+ */
169
+ declare function createMoonbase(options: MoonbaseElectronOptions): MoonbaseElectron;
170
+
171
+ export { type ElectronUiOptions, MoonbaseElectron, type MoonbaseElectronOptions, type RendererAccess, createMoonbase };