@moonbase.sh/electron 0.0.0-stage → 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.
- package/README.md +140 -2
- package/dist/index.cjs +577 -0
- package/dist/index.d.cts +156 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.js +548 -0
- package/dist/preload.cjs +89 -0
- package/dist/preload.d.cts +83 -0
- package/dist/preload.d.ts +83 -0
- package/dist/preload.js +63 -0
- package/dist/ui/index.html +18 -0
- package/dist/ui/overlay.html +13 -0
- package/dist/ui/overlay.js +34 -0
- package/dist/ui/ui.css +1241 -0
- package/dist/ui/ui.js +1053 -0
- package/dist/ui/window.js +29 -0
- package/dist/ui-preload.cjs +15 -0
- package/package.json +72 -3
package/README.md
CHANGED
|
@@ -1,3 +1,141 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @moonbase.sh/electron
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Moonbase licensing for an Electron app, on top of
|
|
4
|
+
[`@moonbase.sh/licensing`](https://www.npmjs.com/package/@moonbase.sh/licensing): the counterpart of
|
|
5
|
+
moonbase-cpp's JUCE module and tauri-plugin-moonbase. It validates the stored license at startup, runs browser and
|
|
6
|
+
offline activation, trials, deactivation, add-ons and update downloads, and presents a finished activation UI
|
|
7
|
+
whenever the app is locked: no renderer code required. Create it in the main process. It needs Electron 30 or later.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @moonbase.sh/electron
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Set up
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// main.ts
|
|
19
|
+
import { createMoonbase } from '@moonbase.sh/electron'
|
|
20
|
+
|
|
21
|
+
const moonbase = createMoonbase({
|
|
22
|
+
endpoint: 'https://your-store.moonbase.sh',
|
|
23
|
+
productId: 'your-product',
|
|
24
|
+
publicKey: MOONBASE_PUBLIC_KEY,
|
|
25
|
+
ui: {
|
|
26
|
+
productName: 'Solstice',
|
|
27
|
+
manufacturerName: 'Helio Audio',
|
|
28
|
+
accent: '#186cdc',
|
|
29
|
+
logoSvg: SOLSTICE_LOGO_SVG,
|
|
30
|
+
trialFeatures: [
|
|
31
|
+
{ label: 'Full DSP engine, unrestricted', included: true },
|
|
32
|
+
{ label: 'Use in commercial releases', included: false },
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
moonbase.start()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The license is kept in `license.mb` in the app's user data folder, and the app's own version (`app.getVersion()`)
|
|
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. The module loads its UI from beside itself in `node_modules`, so leave it out of
|
|
42
|
+
a bundle of the main process, as Electron Forge, electron-vite and electron-builder do for dependencies by default.
|
|
43
|
+
|
|
44
|
+
## The activation UI
|
|
45
|
+
|
|
46
|
+
| `ui` option | Default | |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `productName` | `app.getName()` | Shown throughout |
|
|
49
|
+
| `manufacturerName` | none | Under the product name, and as the account the customer signs in to |
|
|
50
|
+
| `accent` | `#186cdc` (Moonbase blue) | The one brand colour: buttons, progress, step numbers. Any CSS colour |
|
|
51
|
+
| `logoSvg`, `logoPng` | a sun mark in the accent | The product mark in the header. `logoPng` takes bytes or a path |
|
|
52
|
+
| `trialFeatures` | none | The trial screen's included and excluded lines |
|
|
53
|
+
| `trialLengthDays` | 14 | Shown when the license does not say |
|
|
54
|
+
| `showAddOns` | off | An "Add-ons" row in the license details, to try, buy and activate the product's [add-ons](https://www.npmjs.com/package/@moonbase.sh/licensing#add-ons) |
|
|
55
|
+
| `strings` | built-in copy | Override any heading or body, including the copy for each reason the app locked |
|
|
56
|
+
| `showMoonbaseBadge` | on | The "Licensing secured by moonbase" footer |
|
|
57
|
+
| `autoPresentOnLock` | on | Present the UI when the app starts unlicensed, and whenever it loses its license |
|
|
58
|
+
| `autoPresentUpdate` | on | Present the update screen when the app starts with a newer release it was not told to skip |
|
|
59
|
+
| `reduceMotion` | off | Skip transitions; the system setting is honoured either way |
|
|
60
|
+
| `windowTitle` | the product name | |
|
|
61
|
+
| `presentation` | `window` | `window`, or `overlay` to lock one of the app's windows; [see below](#locking-the-app) |
|
|
62
|
+
| `window` | the app's first window | The window the overlay locks, and the activation window's parent |
|
|
63
|
+
|
|
64
|
+
Pass `ui: false` to turn the built-in UI off and build your own on the renderer API below.
|
|
65
|
+
|
|
66
|
+
The screens are the same in every Moonbase SDK: Welcome (activate online, or offline; once the app has lost its
|
|
67
|
+
license it says why), Waiting for activation (with the link to copy when the browser can't be opened), You're all
|
|
68
|
+
set, Offline activation (save the machine file, then drop or pick the license file), Trial and Trial expired,
|
|
69
|
+
Upgrade needed (for a license that doesn't cover this version), License details (with the license id to copy for
|
|
70
|
+
support, seats and Deactivate), Add-ons, and Update available (release notes, a download with progress, and Skip
|
|
71
|
+
this version).
|
|
72
|
+
|
|
73
|
+
Show it yourself, optionally on a screen (`license`, `update`, `offline` or `addons`):
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
moonbase.present('license')
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Locking the app
|
|
80
|
+
|
|
81
|
+
By default the UI is its own window, and the app stays usable beside it, which suits an app with free features. To
|
|
82
|
+
lock the app instead, present the UI over one of its windows with `presentation: 'overlay'`. The same screens then
|
|
83
|
+
float over the app's content, which is blurred behind them and takes no clicks or keys. While the app has no license
|
|
84
|
+
the overlay cannot be dismissed; once it has one it gets a close button and closes on Escape.
|
|
85
|
+
|
|
86
|
+
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. Keep gating in the main process either way: the overlay is a lock on the interface.
|
|
88
|
+
|
|
89
|
+
## Gating
|
|
90
|
+
|
|
91
|
+
Check the license in the main process, where a renderer cannot skip it:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
ipcMain.handle('export', async () => {
|
|
95
|
+
if (!moonbase.isLicensed()) {
|
|
96
|
+
void moonbase.present()
|
|
97
|
+
return { error: 'Exporting needs a license.' }
|
|
98
|
+
}
|
|
99
|
+
// ...
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`isLicensed()` is true with a license or a trial, and cheap enough to check anywhere. `hasSubProduct(id)` says
|
|
104
|
+
whether to unlock an add-on, and `license()` returns the full license for other checks. Every method of
|
|
105
|
+
[`ActivationController`](https://www.npmjs.com/package/@moonbase.sh/licensing#a-ui-of-your-own) is on `moonbase` too.
|
|
106
|
+
|
|
107
|
+
## The renderer API
|
|
108
|
+
|
|
109
|
+
To show the license state in the app's own windows, or to build your own UI, expose `window.moonbase` from the
|
|
110
|
+
window's preload script:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
// preload.ts
|
|
114
|
+
import { exposeMoonbase } from '@moonbase.sh/electron/preload'
|
|
115
|
+
|
|
116
|
+
exposeMoonbase()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// renderer
|
|
121
|
+
window.moonbase.onStateChanged(render)
|
|
122
|
+
render(await window.moonbase.state())
|
|
123
|
+
await window.moonbase.activate()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A sandboxed preload can require nothing but Electron, so bundle it, as Electron Forge and electron-vite do. The API
|
|
127
|
+
has the same calls as tauri-plugin-moonbase's: `state`, `activate`, `cancelActivation`, `refresh`, `deactivate`,
|
|
128
|
+
`forget`, `deviceToken`, `activateOffline`, `dismissError`, `device`, `checkUpdate`, `updateDownloadUrl`, `present`,
|
|
129
|
+
`closeUi`, `upgradeLicense`, `loadAddOns`, `refreshAddOns`, `activateSubProduct`, `requestSubProductTrial`,
|
|
130
|
+
`buySubProduct` and `hasSubProduct`. A failed call rejects with `{ kind, message }`, where `kind` is the SDK's
|
|
131
|
+
`ErrorType` (`ApiError`, `LicenseInvalid`, `ReleaseNotCovered`, ...) or `notLicensed`, `busy`, `internal` or
|
|
132
|
+
`forbidden`.
|
|
133
|
+
|
|
134
|
+
Every renderer the preload is in may call all of these. To limit them, pass `rendererAccess`: `read-only` allows
|
|
135
|
+
`state`, `device`, `checkUpdate` and `present`, `none` nothing, and a function decides per window. The built-in UI
|
|
136
|
+
always gets what it needs.
|
|
137
|
+
|
|
138
|
+
The Electron sample in the Moonbase repository (`samples/electron-licensing`) is Aurora, a small app whose export is
|
|
139
|
+
a paid feature, wired to Moonbase's public demo store so it activates out of the box.
|
|
140
|
+
|
|
141
|
+
License: MIT
|