@moonbase.sh/electron 0.0.0 → 0.1.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,83 @@
1
+ import { ActivationState, DeviceInfo, UpdateInfo, DownloadTarget, ActivationScreen } from '@moonbase.sh/licensing';
2
+ export { ActivationScreen, ActivationState } from '@moonbase.sh/licensing';
3
+
4
+ /**
5
+ * Why a call from the renderer failed: `kind` is the SDK's `ErrorType`
6
+ * (`ApiError`, `LicenseInvalid`, `ReleaseNotCovered`, ...), or `notLicensed`,
7
+ * `busy`, `internal`, or `forbidden` when the module's `rendererAccess` does not
8
+ * allow the call from this window.
9
+ */
10
+ interface MoonbaseRendererError {
11
+ kind: string;
12
+ message: string;
13
+ }
14
+ /**
15
+ * Moonbase in a renderer: the license state, and the calls a UI of your own
16
+ * needs. Every call goes to the main process, which holds the license.
17
+ */
18
+ interface MoonbaseRendererApi {
19
+ /** The current license state. */
20
+ state: () => Promise<ActivationState>;
21
+ /** Called with every new license state. Returns a function that stops it. */
22
+ onStateChanged: (listener: (state: ActivationState) => void) => () => void;
23
+ /** Start a browser activation; resolves once the request exists, then polls in the background. */
24
+ activate: () => Promise<ActivationState>;
25
+ /** Stop waiting; a license held from before stays. */
26
+ cancelActivation: () => Promise<ActivationState>;
27
+ /** Check the license with Moonbase now (after a purchase, say); `force` (default true) skips the throttle. */
28
+ refresh: (options?: {
29
+ force?: boolean;
30
+ }) => Promise<ActivationState>;
31
+ /** Free the seat and lock; trials and offline licenses are forgotten on this device. */
32
+ deactivate: () => Promise<ActivationState>;
33
+ /** Forget the license on this device only. */
34
+ forget: () => Promise<ActivationState>;
35
+ /** The machine file for offline activation. */
36
+ deviceToken: () => Promise<string>;
37
+ /** Activate from the contents of the license file the customer got back. */
38
+ activateOffline: (licenseFile: string) => Promise<ActivationState>;
39
+ /** Clear `state.error`. */
40
+ dismissError: () => Promise<ActivationState>;
41
+ /** Device name, platform, and how its id was derived. */
42
+ device: () => Promise<DeviceInfo>;
43
+ /** Whether a newer release is out, with its notes. */
44
+ checkUpdate: () => Promise<UpdateInfo>;
45
+ /** A short-lived link to the latest installer for this platform. */
46
+ updateDownloadUrl: () => Promise<DownloadTarget>;
47
+ /** Show the activation UI, optionally on a particular screen. */
48
+ present: (options?: {
49
+ screen?: ActivationScreen;
50
+ }) => Promise<void>;
51
+ /** Close the activation window, or take the overlay down. */
52
+ closeUi: () => Promise<void>;
53
+ /** Open the upgrade for a license that doesn't cover this version, or for a new version `checkUpdate` found it doesn't. */
54
+ upgradeLicense: () => Promise<ActivationState>;
55
+ /** List the product's add-ons into `state.addOns`. Can take a seat of one bought since the license was checked. */
56
+ loadAddOns: () => Promise<ActivationState>;
57
+ /** Check the license again, so an add-on bought since takes its seat, then list them again. */
58
+ refreshAddOns: () => Promise<ActivationState>;
59
+ /** Take a seat of an add-on the customer owns, here. */
60
+ activateSubProduct: (id: string) => Promise<ActivationState>;
61
+ /** Start an add-on's trial here. */
62
+ requestSubProductTrial: (id: string) => Promise<ActivationState>;
63
+ /** Open an add-on's buy link; the add-ons refresh when the app comes back to the front. */
64
+ buySubProduct: (id: string) => Promise<void>;
65
+ /** Whether `state` says to unlock an add-on, by its own id or its whole id. */
66
+ hasSubProduct: (state: ActivationState, id: string) => boolean;
67
+ }
68
+ /** The renderer API, for a preload that exposes it its own way. */
69
+ declare function createMoonbaseApi(): MoonbaseRendererApi;
70
+ /**
71
+ * Expose Moonbase to the page as `window.moonbase` (or another name), from a
72
+ * preload script with context isolation on:
73
+ *
74
+ * ```ts
75
+ * // preload.ts
76
+ * import { exposeMoonbase } from '@moonbase.sh/electron/preload'
77
+ *
78
+ * exposeMoonbase()
79
+ * ```
80
+ */
81
+ declare function exposeMoonbase(key?: string): void;
82
+
83
+ export { type MoonbaseRendererApi, type MoonbaseRendererError, createMoonbaseApi, exposeMoonbase };
@@ -0,0 +1,83 @@
1
+ import { ActivationState, DeviceInfo, UpdateInfo, DownloadTarget, ActivationScreen } from '@moonbase.sh/licensing';
2
+ export { ActivationScreen, ActivationState } from '@moonbase.sh/licensing';
3
+
4
+ /**
5
+ * Why a call from the renderer failed: `kind` is the SDK's `ErrorType`
6
+ * (`ApiError`, `LicenseInvalid`, `ReleaseNotCovered`, ...), or `notLicensed`,
7
+ * `busy`, `internal`, or `forbidden` when the module's `rendererAccess` does not
8
+ * allow the call from this window.
9
+ */
10
+ interface MoonbaseRendererError {
11
+ kind: string;
12
+ message: string;
13
+ }
14
+ /**
15
+ * Moonbase in a renderer: the license state, and the calls a UI of your own
16
+ * needs. Every call goes to the main process, which holds the license.
17
+ */
18
+ interface MoonbaseRendererApi {
19
+ /** The current license state. */
20
+ state: () => Promise<ActivationState>;
21
+ /** Called with every new license state. Returns a function that stops it. */
22
+ onStateChanged: (listener: (state: ActivationState) => void) => () => void;
23
+ /** Start a browser activation; resolves once the request exists, then polls in the background. */
24
+ activate: () => Promise<ActivationState>;
25
+ /** Stop waiting; a license held from before stays. */
26
+ cancelActivation: () => Promise<ActivationState>;
27
+ /** Check the license with Moonbase now (after a purchase, say); `force` (default true) skips the throttle. */
28
+ refresh: (options?: {
29
+ force?: boolean;
30
+ }) => Promise<ActivationState>;
31
+ /** Free the seat and lock; trials and offline licenses are forgotten on this device. */
32
+ deactivate: () => Promise<ActivationState>;
33
+ /** Forget the license on this device only. */
34
+ forget: () => Promise<ActivationState>;
35
+ /** The machine file for offline activation. */
36
+ deviceToken: () => Promise<string>;
37
+ /** Activate from the contents of the license file the customer got back. */
38
+ activateOffline: (licenseFile: string) => Promise<ActivationState>;
39
+ /** Clear `state.error`. */
40
+ dismissError: () => Promise<ActivationState>;
41
+ /** Device name, platform, and how its id was derived. */
42
+ device: () => Promise<DeviceInfo>;
43
+ /** Whether a newer release is out, with its notes. */
44
+ checkUpdate: () => Promise<UpdateInfo>;
45
+ /** A short-lived link to the latest installer for this platform. */
46
+ updateDownloadUrl: () => Promise<DownloadTarget>;
47
+ /** Show the activation UI, optionally on a particular screen. */
48
+ present: (options?: {
49
+ screen?: ActivationScreen;
50
+ }) => Promise<void>;
51
+ /** Close the activation window, or take the overlay down. */
52
+ closeUi: () => Promise<void>;
53
+ /** Open the upgrade for a license that doesn't cover this version, or for a new version `checkUpdate` found it doesn't. */
54
+ upgradeLicense: () => Promise<ActivationState>;
55
+ /** List the product's add-ons into `state.addOns`. Can take a seat of one bought since the license was checked. */
56
+ loadAddOns: () => Promise<ActivationState>;
57
+ /** Check the license again, so an add-on bought since takes its seat, then list them again. */
58
+ refreshAddOns: () => Promise<ActivationState>;
59
+ /** Take a seat of an add-on the customer owns, here. */
60
+ activateSubProduct: (id: string) => Promise<ActivationState>;
61
+ /** Start an add-on's trial here. */
62
+ requestSubProductTrial: (id: string) => Promise<ActivationState>;
63
+ /** Open an add-on's buy link; the add-ons refresh when the app comes back to the front. */
64
+ buySubProduct: (id: string) => Promise<void>;
65
+ /** Whether `state` says to unlock an add-on, by its own id or its whole id. */
66
+ hasSubProduct: (state: ActivationState, id: string) => boolean;
67
+ }
68
+ /** The renderer API, for a preload that exposes it its own way. */
69
+ declare function createMoonbaseApi(): MoonbaseRendererApi;
70
+ /**
71
+ * Expose Moonbase to the page as `window.moonbase` (or another name), from a
72
+ * preload script with context isolation on:
73
+ *
74
+ * ```ts
75
+ * // preload.ts
76
+ * import { exposeMoonbase } from '@moonbase.sh/electron/preload'
77
+ *
78
+ * exposeMoonbase()
79
+ * ```
80
+ */
81
+ declare function exposeMoonbase(key?: string): void;
82
+
83
+ export { type MoonbaseRendererApi, type MoonbaseRendererError, createMoonbaseApi, exposeMoonbase };
@@ -0,0 +1,63 @@
1
+ // src/preload.ts
2
+ import { contextBridge, ipcRenderer } from "electron";
3
+ async function call(command, args = {}) {
4
+ const outcome = await ipcRenderer.invoke("moonbase:invoke", command, args);
5
+ if (!outcome.ok)
6
+ throw outcome.error;
7
+ return outcome.value;
8
+ }
9
+ function createMoonbaseApi() {
10
+ const listeners = /* @__PURE__ */ new Set();
11
+ let subscribed = false;
12
+ return {
13
+ state: () => call("state"),
14
+ onStateChanged(listener) {
15
+ listeners.add(listener);
16
+ if (!subscribed) {
17
+ subscribed = true;
18
+ ipcRenderer.on("moonbase:state-changed", (_event, state) => {
19
+ for (const each of [...listeners])
20
+ each(state);
21
+ });
22
+ ipcRenderer.send("moonbase:subscribe");
23
+ }
24
+ return () => {
25
+ listeners.delete(listener);
26
+ };
27
+ },
28
+ activate: () => call("activate"),
29
+ cancelActivation: () => call("cancelActivation"),
30
+ refresh: (options) => call("refresh", { force: options?.force ?? true }),
31
+ deactivate: () => call("deactivate"),
32
+ forget: () => call("forget"),
33
+ deviceToken: () => call("deviceToken"),
34
+ activateOffline: (licenseFile) => call("activateOffline", { licenseFile }),
35
+ dismissError: () => call("dismissError"),
36
+ device: () => call("device"),
37
+ checkUpdate: () => call("checkUpdate"),
38
+ updateDownloadUrl: () => call("updateDownloadUrl"),
39
+ present: (options) => call("present", { screen: options?.screen ?? null }),
40
+ closeUi: () => call("closeUi"),
41
+ upgradeLicense: () => call("upgradeLicense"),
42
+ loadAddOns: () => call("loadAddOns"),
43
+ refreshAddOns: () => call("refreshAddOns"),
44
+ activateSubProduct: (id) => call("activateSubProduct", { id }),
45
+ requestSubProductTrial: (id) => call("requestSubProductTrial", { id }),
46
+ buySubProduct: (id) => call("buySubProduct", { id }),
47
+ hasSubProduct(state, id) {
48
+ const license = state.license;
49
+ if (!license)
50
+ return false;
51
+ const prefix = `${license.product.id}.`;
52
+ const own = id.startsWith(prefix) ? id.slice(prefix.length) : id;
53
+ return state.activeSubProducts.includes(own);
54
+ }
55
+ };
56
+ }
57
+ function exposeMoonbase(key = "moonbase") {
58
+ contextBridge.exposeInMainWorld(key, createMoonbaseApi());
59
+ }
60
+ export {
61
+ createMoonbaseApi,
62
+ exposeMoonbase
63
+ };
@@ -0,0 +1,18 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" />
7
+ <title>Activation</title>
8
+ <link rel="stylesheet" href="ui.css" />
9
+ <script src="ui.js" defer></script>
10
+ <script src="window.js" defer></script>
11
+ </head>
12
+ <body>
13
+ <div class="drag"></div>
14
+ <div class="glow" aria-hidden="true"></div>
15
+ <div class="glow-bloom" aria-hidden="true"></div>
16
+ <div id="app"></div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en" class="overlay">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" />
7
+ <title>Activation</title>
8
+ <link rel="stylesheet" href="ui.css" />
9
+ <script src="ui.js" defer></script>
10
+ <script src="overlay.js" defer></script>
11
+ </head>
12
+ <body></body>
13
+ </html>
@@ -0,0 +1,34 @@
1
+ // Boots the activation UI as an overlay over one of the app's windows: a view
2
+ // laid over its content, with the app blurred and dimmed behind it. The view
3
+ // takes every click and key while it is up, so the app is locked until there is
4
+ // a license.
5
+ ;(async () => {
6
+ const bridge = window.moonbaseUi
7
+ const invoke = (command, args = {}) => bridge.invoke(command, args)
8
+ const config = await invoke('ui_config')
9
+
10
+ function element(tag, className) {
11
+ const node = document.createElement(tag)
12
+ if (className) node.className = className
13
+ return node
14
+ }
15
+
16
+ const scrim = element('div', config.reduceMotion ? 'mb-scrim reduce-motion' : 'mb-scrim')
17
+ const frame = element('div', 'mb-frame')
18
+ const card = element('div', 'mb-card')
19
+ const root = element('div')
20
+ card.append(root)
21
+ frame.append(element('div', 'mb-glow'), element('div', 'mb-bloom'), card)
22
+ scrim.append(frame)
23
+ document.body.append(scrim)
24
+
25
+ const ui = createActivationUI({ root, config, invoke, mode: 'overlay' })
26
+ bridge.onPush((name, payload) => ui[name]?.(payload))
27
+
28
+ document.addEventListener('keydown', (event) => {
29
+ if (event.key === 'Escape' && ui.canClose()) invoke('close_ui')
30
+ })
31
+ const opened = await invoke('ui_ready', { height: 0 })
32
+ await ui.start(undefined, opened?.screen)
33
+ ui.focus()
34
+ })()