@moonbase.sh/gorilla-engine 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 +77 -8
- package/dist/index.cjs +514 -122
- package/dist/index.d.cts +147 -12
- package/dist/index.d.ts +147 -12
- package/dist/index.js +508 -120
- package/dist/moonbase-gorilla-engine.js +801 -0
- package/package.json +7 -4
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// src/moonbase.ts
|
|
2
2
|
import { execFile, spawn } from "child_process";
|
|
3
|
+
import fsSync from "fs";
|
|
3
4
|
import fs2 from "fs/promises";
|
|
4
5
|
import os from "os";
|
|
5
6
|
import path2 from "path";
|
|
6
7
|
import process from "process";
|
|
7
|
-
import { ActivationController, ActivationError, ReleaseNotCoveredError } from "@moonbase.sh/licensing";
|
|
8
|
+
import { ActivationController, ActivationError, licensingVersion, MoonbaseError, ReleaseNotCoveredError } from "@moonbase.sh/licensing";
|
|
8
9
|
|
|
9
10
|
// package.json
|
|
10
|
-
var version = "0.
|
|
11
|
+
var version = "0.2.0";
|
|
11
12
|
|
|
12
13
|
// src/download.ts
|
|
13
14
|
import fs from "fs";
|
|
@@ -37,20 +38,6 @@ function runtime() {
|
|
|
37
38
|
var _a;
|
|
38
39
|
return (_a = globalThis.GorillaEngine) != null ? _a : null;
|
|
39
40
|
}
|
|
40
|
-
function defaultLicenseFile() {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
const ge = runtime();
|
|
43
|
-
const manufacturer = fileSafe(((_a = ge == null ? void 0 : ge.getManufacturerName) == null ? void 0 : _a.call(ge)) || "Moonbase");
|
|
44
|
-
const plugin = fileSafe(((_b = ge == null ? void 0 : ge.getPluginName) == null ? void 0 : _b.call(ge)) || "Plugin");
|
|
45
|
-
let base;
|
|
46
|
-
if (process.platform === "darwin")
|
|
47
|
-
base = path2.join(os.homedir(), "Library", "Application Support");
|
|
48
|
-
else if (process.platform === "win32")
|
|
49
|
-
base = process.env.APPDATA || path2.join(os.homedir(), "AppData", "Roaming");
|
|
50
|
-
else
|
|
51
|
-
base = process.env.XDG_CONFIG_HOME || path2.join(os.homedir(), ".config");
|
|
52
|
-
return path2.join(base, manufacturer, plugin, "license.mb");
|
|
53
|
-
}
|
|
54
41
|
function run(command, args, input) {
|
|
55
42
|
return new Promise((resolve, reject) => {
|
|
56
43
|
var _a;
|
|
@@ -64,21 +51,77 @@ function openWithSystem(url) {
|
|
|
64
51
|
const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
|
|
65
52
|
spawn(command, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
66
53
|
}
|
|
54
|
+
function gorillaEngineHost() {
|
|
55
|
+
const ge = runtime();
|
|
56
|
+
return {
|
|
57
|
+
pluginName: () => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
return (_b = (_a = ge == null ? void 0 : ge.getPluginName) == null ? void 0 : _a.call(ge)) != null ? _b : "";
|
|
60
|
+
},
|
|
61
|
+
manufacturerName: () => {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
return (_b = (_a = ge == null ? void 0 : ge.getManufacturerName) == null ? void 0 : _a.call(ge)) != null ? _b : "";
|
|
64
|
+
},
|
|
65
|
+
openUrl: (url) => (ge == null ? void 0 : ge.openURLinBrowser) ? ge.openURLinBrowser(url) : openWithSystem(url),
|
|
66
|
+
async copyText(text2) {
|
|
67
|
+
if (process.platform === "darwin")
|
|
68
|
+
await run("pbcopy", [], text2);
|
|
69
|
+
else if (process.platform === "win32")
|
|
70
|
+
await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "$input | Set-Clipboard"], text2);
|
|
71
|
+
else
|
|
72
|
+
await run("xclip", ["-selection", "clipboard"], text2);
|
|
73
|
+
},
|
|
74
|
+
chooseFile: (ge == null ? void 0 : ge.openFileChooser) && ((options) => ge.openFileChooser(options)),
|
|
75
|
+
async reveal(file) {
|
|
76
|
+
if (process.platform === "darwin")
|
|
77
|
+
await run("open", ["-R", file]);
|
|
78
|
+
else if (process.platform === "win32")
|
|
79
|
+
await run("explorer.exe", [`/select,${file}`]).catch(() => {
|
|
80
|
+
});
|
|
81
|
+
else
|
|
82
|
+
await run("xdg-open", [path2.dirname(file)]);
|
|
83
|
+
},
|
|
84
|
+
downloadsFolder: () => path2.join(os.homedir(), "Downloads"),
|
|
85
|
+
setAudioAndMidi: (ge == null ? void 0 : ge.getPluginMM) && ge.getPluginAE && ((enabled) => {
|
|
86
|
+
ge.getPluginMM(enabled);
|
|
87
|
+
ge.getPluginAE(enabled);
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function defaultLicenseFile(storage, host = gorillaEngineHost()) {
|
|
92
|
+
const manufacturerName = (storage == null ? void 0 : storage.manufacturer) || host.manufacturerName();
|
|
93
|
+
const pluginName = (storage == null ? void 0 : storage.plugin) || host.pluginName();
|
|
94
|
+
if (!manufacturerName && !pluginName)
|
|
95
|
+
throw new ActivationError("internal", "Can't tell where to keep the license: Gorilla Engine hasn't named the plugin. Pass `storage: { manufacturer, plugin }` or `licenseFile`.");
|
|
96
|
+
const manufacturer = fileSafe(manufacturerName || "Moonbase");
|
|
97
|
+
const plugin = fileSafe(pluginName || "Plugin");
|
|
98
|
+
let base;
|
|
99
|
+
if (process.platform === "darwin")
|
|
100
|
+
base = path2.join(os.homedir(), "Library", "Application Support");
|
|
101
|
+
else if (process.platform === "win32")
|
|
102
|
+
base = process.env.APPDATA || path2.join(os.homedir(), "AppData", "Roaming");
|
|
103
|
+
else
|
|
104
|
+
base = process.env.XDG_CONFIG_HOME || path2.join(os.homedir(), ".config");
|
|
105
|
+
return path2.join(base, manufacturer, plugin, "license.mb");
|
|
106
|
+
}
|
|
107
|
+
function errorKind(err) {
|
|
108
|
+
var _a;
|
|
109
|
+
if (err instanceof ActivationError)
|
|
110
|
+
return err.kind;
|
|
111
|
+
if (err instanceof MoonbaseError)
|
|
112
|
+
return (_a = err.type) != null ? _a : "internal";
|
|
113
|
+
return "internal";
|
|
114
|
+
}
|
|
67
115
|
var MoonbaseGorillaEngine = class extends ActivationController {
|
|
68
116
|
constructor(options) {
|
|
69
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
117
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
70
118
|
const ui = (_a = options.ui) != null ? _a : {};
|
|
71
|
-
const
|
|
119
|
+
const host = { ...gorillaEngineHost(), ...options.host, ...options.openUrl && { openUrl: options.openUrl } };
|
|
120
|
+
const productName = (_b = ui.productName) != null ? _b : host.pluginName() || "the plugin";
|
|
72
121
|
super({
|
|
73
122
|
...options,
|
|
74
|
-
licenseFile: (
|
|
75
|
-
openUrl:
|
|
76
|
-
const ge = runtime();
|
|
77
|
-
if (ge == null ? void 0 : ge.openURLinBrowser)
|
|
78
|
-
ge.openURLinBrowser(url);
|
|
79
|
-
else
|
|
80
|
-
openWithSystem(url);
|
|
81
|
-
},
|
|
123
|
+
licenseFile: (_c = options.licenseFile) != null ? _c : defaultLicenseFile(options.storage, host),
|
|
124
|
+
openUrl: host.openUrl,
|
|
82
125
|
// Ahead of the SDK's own token, so Moonbase knows the product uses this module.
|
|
83
126
|
clientInfo: [options.clientInfo, `@moonbase.sh/gorilla-engine/${version}`].filter(Boolean).join(" "),
|
|
84
127
|
productName,
|
|
@@ -88,24 +131,103 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
88
131
|
this.uiState = { visible: false, screen: null, request: 0, download: downloadState("idle") };
|
|
89
132
|
this.lastLicensed = null;
|
|
90
133
|
this.gated = null;
|
|
134
|
+
this.gateMissingReported = false;
|
|
91
135
|
this.downloaded = null;
|
|
92
136
|
this.name = "This computer";
|
|
137
|
+
this.hasStarted = false;
|
|
138
|
+
this.disposed = false;
|
|
139
|
+
this.stopFocus = null;
|
|
140
|
+
/** Aborts the update download when the instance is disposed. */
|
|
141
|
+
this.aborts = new AbortController();
|
|
93
142
|
this.ui = { ...ui, productName };
|
|
94
143
|
this.endpoint = options.endpoint;
|
|
95
|
-
this.
|
|
144
|
+
this.host = host;
|
|
145
|
+
this.lockAudioAndMidi = (_d = options.lockAudioAndMidi) != null ? _d : true;
|
|
146
|
+
this.previousLicenseFiles = (_e = options.previousLicenseFiles) != null ? _e : [];
|
|
147
|
+
const warn = (_g = (_f = options.log) == null ? void 0 : _f.warn) != null ? _g : (message) => console.warn(message);
|
|
148
|
+
this.onError = (_h = options.onError) != null ? _h : (failure) => warn(`moonbase: ${failure.action} failed: ${failure.message}`);
|
|
96
149
|
this.subscribe((state) => this.afterStateChange(state));
|
|
97
150
|
}
|
|
98
151
|
/**
|
|
99
152
|
* Validate the stored license, start watching it, and bring the overlay up
|
|
100
|
-
* when the plugin has no license. Call once per plugin instance
|
|
153
|
+
* when the plugin has no license. Call once per plugin instance; a disposed
|
|
154
|
+
* instance can't start again.
|
|
101
155
|
*/
|
|
102
156
|
start() {
|
|
157
|
+
if (this.disposed)
|
|
158
|
+
throw new ActivationError("internal", "This Moonbase instance was disposed: create a new one");
|
|
159
|
+
if (this.hasStarted)
|
|
160
|
+
return;
|
|
161
|
+
this.hasStarted = true;
|
|
162
|
+
this.importPreviousLicense();
|
|
163
|
+
if (this.lockAudioAndMidi)
|
|
164
|
+
this.gate(false);
|
|
165
|
+
if (this.host.onFocusChange)
|
|
166
|
+
this.stopFocus = this.host.onFocusChange((focused) => this.onFocusChanged(focused));
|
|
103
167
|
super.start();
|
|
104
168
|
this.device().then((device) => {
|
|
105
169
|
this.name = device.name;
|
|
106
170
|
}, () => {
|
|
107
171
|
});
|
|
108
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Stop watching the license and stop telling the overlay anything. For tests
|
|
175
|
+
* and development reloads: a plugin does not need it. Safe to call twice;
|
|
176
|
+
* afterwards the overlay calls do nothing and {@link start} throws.
|
|
177
|
+
*/
|
|
178
|
+
dispose() {
|
|
179
|
+
var _a;
|
|
180
|
+
if (this.disposed)
|
|
181
|
+
return;
|
|
182
|
+
this.disposed = true;
|
|
183
|
+
this.uiListeners.clear();
|
|
184
|
+
(_a = this.stopFocus) == null ? void 0 : _a.call(this);
|
|
185
|
+
this.stopFocus = null;
|
|
186
|
+
this.aborts.abort();
|
|
187
|
+
super.dispose();
|
|
188
|
+
}
|
|
189
|
+
/** When the license file is missing, take the one an earlier version kept. */
|
|
190
|
+
importPreviousLicense() {
|
|
191
|
+
if (fsSync.existsSync(this.licenseFile))
|
|
192
|
+
return;
|
|
193
|
+
const previous = this.previousLicenseFiles.find((file) => path2.resolve(file) !== path2.resolve(this.licenseFile) && fsSync.existsSync(file));
|
|
194
|
+
if (!previous)
|
|
195
|
+
return;
|
|
196
|
+
try {
|
|
197
|
+
fsSync.mkdirSync(path2.dirname(this.licenseFile), { recursive: true });
|
|
198
|
+
fsSync.copyFileSync(previous, this.licenseFile);
|
|
199
|
+
} catch (err) {
|
|
200
|
+
this.reportError("previousLicense", err);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Hand a failure to `onError`: the overlay does with every action that
|
|
205
|
+
* fails, and the module with the host's.
|
|
206
|
+
*/
|
|
207
|
+
reportError(action, error) {
|
|
208
|
+
var _a;
|
|
209
|
+
if (this.disposed)
|
|
210
|
+
return;
|
|
211
|
+
const message = error instanceof Error ? error.message : (_a = error == null ? void 0 : error.message) != null ? _a : String(error);
|
|
212
|
+
const kind = error == null ? void 0 : error.kind;
|
|
213
|
+
this.onError({ action, kind: typeof kind === "string" ? kind : errorKind(error), message, error });
|
|
214
|
+
}
|
|
215
|
+
/** A report for support: versions, where the license is kept and what the host can do, but nothing personal. */
|
|
216
|
+
diagnostics() {
|
|
217
|
+
const state = this.state();
|
|
218
|
+
const home = os.homedir();
|
|
219
|
+
return {
|
|
220
|
+
module: version,
|
|
221
|
+
licensing: licensingVersion,
|
|
222
|
+
platform: `${process.platform}-${process.arch}`,
|
|
223
|
+
licenseFile: home && this.licenseFile.startsWith(home) ? `~${this.licenseFile.slice(home.length)}` : this.licenseFile,
|
|
224
|
+
status: state.status,
|
|
225
|
+
licensed: state.licensed,
|
|
226
|
+
host: { gorillaEngine: !!runtime(), fileDialog: !!this.host.chooseFile, audioAndMidi: !!this.host.setAudioAndMidi, focus: !!this.host.onFocusChange },
|
|
227
|
+
audioAndMidi: { gated: this.lockAudioAndMidi, enabled: this.gated },
|
|
228
|
+
overlayVisible: this.uiState.visible
|
|
229
|
+
};
|
|
230
|
+
}
|
|
109
231
|
/** This computer's name, as the activation screen shows it. */
|
|
110
232
|
get deviceName() {
|
|
111
233
|
return this.name;
|
|
@@ -116,29 +238,30 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
116
238
|
}
|
|
117
239
|
/** Called whenever {@link uiSnapshot} changes. Returns a function that stops it. */
|
|
118
240
|
subscribeUi(listener) {
|
|
241
|
+
if (this.disposed)
|
|
242
|
+
return () => {
|
|
243
|
+
};
|
|
119
244
|
this.uiListeners.add(listener);
|
|
120
245
|
return () => this.uiListeners.delete(listener);
|
|
121
246
|
}
|
|
122
247
|
setUi(next) {
|
|
248
|
+
if (this.disposed)
|
|
249
|
+
return;
|
|
123
250
|
this.uiState = { ...this.uiState, ...next };
|
|
124
251
|
for (const listener of [...this.uiListeners])
|
|
125
252
|
listener();
|
|
126
253
|
}
|
|
127
254
|
afterStateChange(state) {
|
|
128
|
-
var _a, _b
|
|
255
|
+
var _a, _b;
|
|
129
256
|
if (state.status === "loading")
|
|
130
257
|
return;
|
|
131
|
-
if (this.lockAudioAndMidi
|
|
132
|
-
this.
|
|
133
|
-
const ge = runtime();
|
|
134
|
-
(_a = ge == null ? void 0 : ge.getPluginMM) == null ? void 0 : _a.call(ge, state.licensed);
|
|
135
|
-
(_b = ge == null ? void 0 : ge.getPluginAE) == null ? void 0 : _b.call(ge, state.licensed);
|
|
136
|
-
}
|
|
258
|
+
if (this.lockAudioAndMidi)
|
|
259
|
+
this.gate(state.licensed);
|
|
137
260
|
const previous = this.lastLicensed;
|
|
138
261
|
this.lastLicensed = state.licensed;
|
|
139
|
-
if (!state.licensed && previous !== false && ((
|
|
262
|
+
if (!state.licensed && previous !== false && ((_a = this.ui.autoPresentOnLock) != null ? _a : true)) {
|
|
140
263
|
this.present();
|
|
141
|
-
} else if (previous === null && state.licensed && ((
|
|
264
|
+
} else if (previous === null && state.licensed && ((_b = this.ui.autoPresentUpdate) != null ? _b : true) && state.update) {
|
|
142
265
|
const latest = state.update.latestVersion;
|
|
143
266
|
void this.isUpdateSkipped(latest).then((skipped) => {
|
|
144
267
|
if (!skipped)
|
|
@@ -146,6 +269,25 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
146
269
|
});
|
|
147
270
|
}
|
|
148
271
|
}
|
|
272
|
+
/** Turn MIDI and audio on or off, saying so when the host can't. */
|
|
273
|
+
gate(enabled) {
|
|
274
|
+
if (this.gated === enabled)
|
|
275
|
+
return;
|
|
276
|
+
const set = this.host.setAudioAndMidi;
|
|
277
|
+
if (!set) {
|
|
278
|
+
if (!this.gateMissingReported) {
|
|
279
|
+
this.gateMissingReported = true;
|
|
280
|
+
this.reportError("audioAndMidi", new ActivationError("internal", "Gorilla Engine's getPluginMM and getPluginAE are not there, so the module can't turn MIDI and audio on or off. Pass lockAudioAndMidi: false to gate them yourself."));
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
set(enabled);
|
|
286
|
+
this.gated = enabled;
|
|
287
|
+
} catch (err) {
|
|
288
|
+
this.reportError("audioAndMidi", err);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
149
291
|
/**
|
|
150
292
|
* Show the activation overlay, optionally on a particular screen. Without one
|
|
151
293
|
* it shows whatever the license state calls for.
|
|
@@ -160,25 +302,14 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
160
302
|
}
|
|
161
303
|
/** Copy text to the clipboard, for the activation link and the license id. */
|
|
162
304
|
async copyText(text2) {
|
|
163
|
-
|
|
164
|
-
await run("pbcopy", [], text2);
|
|
165
|
-
else if (process.platform === "win32")
|
|
166
|
-
await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "$input | Set-Clipboard"], text2);
|
|
167
|
-
else
|
|
168
|
-
await run("xclip", ["-selection", "clipboard"], text2);
|
|
305
|
+
await this.host.copyText(text2);
|
|
169
306
|
}
|
|
170
307
|
/** Show a file in the file manager. */
|
|
171
308
|
async reveal(file) {
|
|
172
|
-
|
|
173
|
-
await run("open", ["-R", file]);
|
|
174
|
-
else if (process.platform === "win32")
|
|
175
|
-
await run("explorer.exe", [`/select,${file}`]).catch(() => {
|
|
176
|
-
});
|
|
177
|
-
else
|
|
178
|
-
await run("xdg-open", [path2.dirname(file)]);
|
|
309
|
+
await this.host.reveal(file);
|
|
179
310
|
}
|
|
180
311
|
downloadsFolder() {
|
|
181
|
-
return
|
|
312
|
+
return this.host.downloadsFolder();
|
|
182
313
|
}
|
|
183
314
|
/**
|
|
184
315
|
* Save the machine file for offline activation: through Gorilla Engine's save
|
|
@@ -186,10 +317,10 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
186
317
|
* cancels.
|
|
187
318
|
*/
|
|
188
319
|
async saveMachineFile() {
|
|
189
|
-
var _a
|
|
320
|
+
var _a;
|
|
190
321
|
const token = await this.deviceToken();
|
|
191
322
|
const name = `${fileSafe((_a = this.ui.productName) != null ? _a : "license")}.dt`;
|
|
192
|
-
const chooser =
|
|
323
|
+
const chooser = this.host.chooseFile;
|
|
193
324
|
if (chooser) {
|
|
194
325
|
const picked = await chooser({ saveDialog: true, warnOnOverwrite: true, hint: "Save machine file", allowedExtensions: "*.dt", defaultLocation: path2.join(this.downloadsFolder(), name) });
|
|
195
326
|
const file2 = picked == null ? void 0 : picked[0];
|
|
@@ -206,8 +337,7 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
206
337
|
}
|
|
207
338
|
/** Pick the license file the customer got back for offline activation. Null when they cancel. */
|
|
208
339
|
async chooseLicenseFile() {
|
|
209
|
-
|
|
210
|
-
const chooser = (_a = runtime()) == null ? void 0 : _a.openFileChooser;
|
|
340
|
+
const chooser = this.host.chooseFile;
|
|
211
341
|
if (!chooser)
|
|
212
342
|
throw new ActivationError("internal", "This plugin can't open a file dialog");
|
|
213
343
|
const picked = await chooser({ hint: "Choose your license file", allowedExtensions: "*.mb;*.jwt;*.txt;*.lic" });
|
|
@@ -230,7 +360,8 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
230
360
|
try {
|
|
231
361
|
const file = await this.downloadInstaller({
|
|
232
362
|
directory: this.downloadsFolder(),
|
|
233
|
-
onProgress: (progress) => this.setUi({ download: downloadState("downloading", { progress }) })
|
|
363
|
+
onProgress: (progress) => this.setUi({ download: downloadState("downloading", { progress }) }),
|
|
364
|
+
fetch: (url) => fetch(url, { signal: this.aborts.signal })
|
|
234
365
|
});
|
|
235
366
|
this.downloaded = file;
|
|
236
367
|
await this.reveal(file).catch(() => {
|
|
@@ -264,11 +395,7 @@ var MoonbaseGorillaEngine = class extends ActivationController {
|
|
|
264
395
|
const pending = ((_a = this.state().activation) == null ? void 0 : _a.browserUrl) === url;
|
|
265
396
|
if (!sameOrigin && !pending && url !== "https://moonbase.sh")
|
|
266
397
|
throw new ActivationError("internal", "That link can't be opened from here");
|
|
267
|
-
|
|
268
|
-
if (ge == null ? void 0 : ge.openURLinBrowser)
|
|
269
|
-
ge.openURLinBrowser(url);
|
|
270
|
-
else
|
|
271
|
-
openWithSystem(url);
|
|
398
|
+
await this.host.openUrl(url);
|
|
272
399
|
}
|
|
273
400
|
};
|
|
274
401
|
function createMoonbase(options) {
|
|
@@ -277,7 +404,7 @@ function createMoonbase(options) {
|
|
|
277
404
|
|
|
278
405
|
// src/MoonbaseActivation.ts
|
|
279
406
|
import process2 from "process";
|
|
280
|
-
import * as
|
|
407
|
+
import * as React3 from "react";
|
|
281
408
|
|
|
282
409
|
// src/copy.ts
|
|
283
410
|
var DAY = 864e5;
|
|
@@ -431,8 +558,111 @@ function describeAddOn(entry, license, state) {
|
|
|
431
558
|
}
|
|
432
559
|
|
|
433
560
|
// src/elements.ts
|
|
561
|
+
import * as React2 from "react";
|
|
562
|
+
|
|
563
|
+
// src/motion.ts
|
|
434
564
|
import * as React from "react";
|
|
435
|
-
var
|
|
565
|
+
var FRAME = 16;
|
|
566
|
+
function cubicBezier(x1, y1, x2, y2) {
|
|
567
|
+
const at = (a, b, t) => ((1 - 3 * b + 3 * a) * t + (3 * b - 6 * a)) * t * t + 3 * a * t;
|
|
568
|
+
const slope = (a, b, t) => 3 * (1 - 3 * b + 3 * a) * t * t + 2 * (3 * b - 6 * a) * t + 3 * a;
|
|
569
|
+
return (x) => {
|
|
570
|
+
if (x <= 0)
|
|
571
|
+
return 0;
|
|
572
|
+
if (x >= 1)
|
|
573
|
+
return 1;
|
|
574
|
+
let t = x;
|
|
575
|
+
for (let i = 0; i < 8; i++) {
|
|
576
|
+
const error = at(x1, x2, t) - x;
|
|
577
|
+
if (Math.abs(error) < 1e-6)
|
|
578
|
+
return at(y1, y2, t);
|
|
579
|
+
const d = slope(x1, x2, t);
|
|
580
|
+
if (Math.abs(d) < 1e-6)
|
|
581
|
+
break;
|
|
582
|
+
t -= error / d;
|
|
583
|
+
}
|
|
584
|
+
let low = 0;
|
|
585
|
+
let high = 1;
|
|
586
|
+
t = x;
|
|
587
|
+
for (let i = 0; i < 30 && high - low > 1e-6; i++) {
|
|
588
|
+
if (at(x1, x2, t) < x)
|
|
589
|
+
low = t;
|
|
590
|
+
else
|
|
591
|
+
high = t;
|
|
592
|
+
t = (low + high) / 2;
|
|
593
|
+
}
|
|
594
|
+
return at(y1, y2, t);
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
var EASE = cubicBezier(0.22, 1, 0.36, 1);
|
|
598
|
+
var EASE_CSS = cubicBezier(0.25, 0.1, 0.25, 1);
|
|
599
|
+
function same(a, b) {
|
|
600
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
601
|
+
}
|
|
602
|
+
function useTween(channels, still = false, initial) {
|
|
603
|
+
const targets = channels.map((channel) => channel.to);
|
|
604
|
+
const [values, setValues] = React.useState(() => initial != null ? initial : targets);
|
|
605
|
+
const latest = React.useRef(values);
|
|
606
|
+
latest.current = values;
|
|
607
|
+
const spec = React.useRef(channels);
|
|
608
|
+
spec.current = channels;
|
|
609
|
+
const key = targets.join(",");
|
|
610
|
+
React.useEffect(() => {
|
|
611
|
+
const from = latest.current;
|
|
612
|
+
const to = spec.current.map((channel) => channel.to);
|
|
613
|
+
if (still || same(from, to)) {
|
|
614
|
+
if (!same(from, to))
|
|
615
|
+
setValues(to);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const timing = spec.current;
|
|
619
|
+
const start = Date.now();
|
|
620
|
+
let timer;
|
|
621
|
+
const step = () => {
|
|
622
|
+
const elapsed = Date.now() - start;
|
|
623
|
+
let running = false;
|
|
624
|
+
setValues(to.map((target, index) => {
|
|
625
|
+
const { duration, ease } = timing[index];
|
|
626
|
+
const t = duration > 0 ? Math.min(1, elapsed / duration) : 1;
|
|
627
|
+
if (t < 1)
|
|
628
|
+
running = true;
|
|
629
|
+
return t >= 1 ? target : from[index] + (target - from[index]) * ease(t);
|
|
630
|
+
}));
|
|
631
|
+
if (running)
|
|
632
|
+
timer = setTimeout(step, FRAME);
|
|
633
|
+
};
|
|
634
|
+
timer = setTimeout(step, FRAME);
|
|
635
|
+
return () => clearTimeout(timer);
|
|
636
|
+
}, [key, still]);
|
|
637
|
+
return still ? targets : values;
|
|
638
|
+
}
|
|
639
|
+
function useEntrance(key, duration, still = false) {
|
|
640
|
+
const [shown, setShown] = React.useState(() => ({ key, progress: still ? 1 : 0 }));
|
|
641
|
+
if (shown.key !== key)
|
|
642
|
+
setShown({ key, progress: still ? 1 : 0 });
|
|
643
|
+
React.useEffect(() => {
|
|
644
|
+
if (still) {
|
|
645
|
+
setShown((current) => current.progress === 1 ? current : { key, progress: 1 });
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const start = Date.now();
|
|
649
|
+
let timer;
|
|
650
|
+
const step = () => {
|
|
651
|
+
const progress = Math.min(1, (Date.now() - start) / duration);
|
|
652
|
+
setShown({ key, progress });
|
|
653
|
+
if (progress < 1)
|
|
654
|
+
timer = setTimeout(step, FRAME);
|
|
655
|
+
};
|
|
656
|
+
timer = setTimeout(step, FRAME);
|
|
657
|
+
return () => clearTimeout(timer);
|
|
658
|
+
}, [key, still]);
|
|
659
|
+
if (still)
|
|
660
|
+
return 1;
|
|
661
|
+
return shown.key === key ? shown.progress : 0;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/elements.ts
|
|
665
|
+
var h = React2.createElement;
|
|
436
666
|
function color(hex, alpha = 1) {
|
|
437
667
|
let value = hex.trim().replace(/^#/, "");
|
|
438
668
|
if (value.length === 3)
|
|
@@ -499,10 +729,11 @@ function textHeight(text2, size, width, lineHeight = 1.5) {
|
|
|
499
729
|
}
|
|
500
730
|
return Math.ceil(lines * size * lineHeight);
|
|
501
731
|
}
|
|
502
|
-
var keys = 0;
|
|
503
732
|
function label(props, ...children) {
|
|
504
|
-
|
|
505
|
-
|
|
733
|
+
return h("geLabel", { interceptsMouseClicks: false, ...props }, ...children);
|
|
734
|
+
}
|
|
735
|
+
function each(node) {
|
|
736
|
+
return Array.isArray(node) ? node : [node];
|
|
506
737
|
}
|
|
507
738
|
function text(theme, value, x, y, width, options = {}) {
|
|
508
739
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -529,12 +760,12 @@ function space(height) {
|
|
|
529
760
|
function stack(blocks, x, y, width) {
|
|
530
761
|
const nodes = [];
|
|
531
762
|
let top = y;
|
|
532
|
-
|
|
763
|
+
blocks.forEach((block, index) => {
|
|
533
764
|
if (!block)
|
|
534
|
-
|
|
535
|
-
nodes.push(block.render(x, top, width));
|
|
765
|
+
return;
|
|
766
|
+
nodes.push(h(React2.Fragment, { key: index }, ...each(block.render(x, top, width))));
|
|
536
767
|
top += block.height;
|
|
537
|
-
}
|
|
768
|
+
});
|
|
538
769
|
return { nodes, height: top - y };
|
|
539
770
|
}
|
|
540
771
|
function paragraph(theme, value, width, options = {}) {
|
|
@@ -555,7 +786,7 @@ function heading(theme, value, width, options = {}) {
|
|
|
555
786
|
}
|
|
556
787
|
function Button(props) {
|
|
557
788
|
var _a, _b, _c;
|
|
558
|
-
const [hovered, setHovered] =
|
|
789
|
+
const [hovered, setHovered] = React2.useState(false);
|
|
559
790
|
const kind = (_a = props.kind) != null ? _a : "primary";
|
|
560
791
|
const accent = props.theme.accent;
|
|
561
792
|
const looks = {
|
|
@@ -607,7 +838,7 @@ function buttonBlock(theme, value, onClick, options = {}) {
|
|
|
607
838
|
}
|
|
608
839
|
function Link(props) {
|
|
609
840
|
var _a, _b;
|
|
610
|
-
const [hovered, setHovered] =
|
|
841
|
+
const [hovered, setHovered] = React2.useState(false);
|
|
611
842
|
const size = (_a = props.size) != null ? _a : 12.5;
|
|
612
843
|
const width = (_b = props.width) != null ? _b : textWidth(props.label, size, 500) + 12;
|
|
613
844
|
const base = props.link ? palette.link : palette.textSecondary;
|
|
@@ -645,7 +876,7 @@ function linksBlock(theme, links, options = {}) {
|
|
|
645
876
|
height: marginTop + Math.ceil(size * 1.6),
|
|
646
877
|
render: (x, y, width) => {
|
|
647
878
|
const widths = items.map((item) => textWidth(item.label, size, 500) + 12);
|
|
648
|
-
const total = widths.reduce((sum,
|
|
879
|
+
const total = widths.reduce((sum, each2) => sum + each2, 0) + gap * (items.length - 1);
|
|
649
880
|
let left = options.align === "left" ? x : x + (width - total) / 2;
|
|
650
881
|
return items.map((item, index) => {
|
|
651
882
|
const node = h(Link, { key: `link-${item.label}`, theme, x: left, y: y + marginTop, label: item.label, link: item.link, disabled: item.disabled, width: widths[index], onClick: item.onClick });
|
|
@@ -719,13 +950,118 @@ function barBlock(fraction, fill, options = {}) {
|
|
|
719
950
|
};
|
|
720
951
|
}
|
|
721
952
|
function useTick(interval) {
|
|
722
|
-
const [tick, setTick] =
|
|
723
|
-
|
|
953
|
+
const [tick, setTick] = React2.useState(0);
|
|
954
|
+
React2.useEffect(() => {
|
|
955
|
+
if (interval === null)
|
|
956
|
+
return;
|
|
724
957
|
const timer = setInterval(() => setTick((value) => value + 1), interval);
|
|
725
958
|
return () => clearInterval(timer);
|
|
726
959
|
}, [interval]);
|
|
727
960
|
return tick;
|
|
728
961
|
}
|
|
962
|
+
var GLOW_STOPS = [
|
|
963
|
+
[0, [24, 108, 220, 0]],
|
|
964
|
+
[0.3, [24, 108, 220, 0.9]],
|
|
965
|
+
[0.5, [130, 206, 241, 1]],
|
|
966
|
+
[0.7, [24, 108, 220, 0.9]],
|
|
967
|
+
[1, [24, 108, 220, 0]]
|
|
968
|
+
];
|
|
969
|
+
function glowAt(at) {
|
|
970
|
+
let index = 1;
|
|
971
|
+
while (index < GLOW_STOPS.length - 1 && GLOW_STOPS[index][0] < at)
|
|
972
|
+
index++;
|
|
973
|
+
const [fromAt, from] = GLOW_STOPS[index - 1];
|
|
974
|
+
const [toAt, to] = GLOW_STOPS[index];
|
|
975
|
+
const f = Math.max(0, Math.min(1, (at - fromAt) / (toAt - fromAt)));
|
|
976
|
+
const alpha = from[3] + (to[3] - from[3]) * f;
|
|
977
|
+
const channel = (i) => {
|
|
978
|
+
if (alpha <= 0)
|
|
979
|
+
return from[i];
|
|
980
|
+
const premultiplied = from[i] * from[3] + (to[i] * to[3] - from[i] * from[3]) * f;
|
|
981
|
+
return Math.round(premultiplied / alpha);
|
|
982
|
+
};
|
|
983
|
+
const hex = [channel(0), channel(1), channel(2)].map((value) => value.toString(16).padStart(2, "0")).join("");
|
|
984
|
+
return { hex, alpha };
|
|
985
|
+
}
|
|
986
|
+
function glowStrips(width) {
|
|
987
|
+
const count = Math.max(1, Math.round(width / 5));
|
|
988
|
+
const edge = (index) => Math.round(index * width / count);
|
|
989
|
+
return Array.from({ length: count }, (_, index) => {
|
|
990
|
+
const x = edge(index);
|
|
991
|
+
const stripWidth = edge(index + 1) - x;
|
|
992
|
+
const { hex, alpha } = glowAt((x + stripWidth / 2) / width);
|
|
993
|
+
return label({ key: `glow-${index}`, x, y: 0, width: stripWidth, height: 1, backgroundColor: color(hex, alpha) });
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
var Glow = React2.memo((props) => {
|
|
997
|
+
useTick(props.still ? null : 100);
|
|
998
|
+
const width = Math.round(props.width * 0.64);
|
|
999
|
+
const strips = React2.useMemo(() => glowStrips(width), [width]);
|
|
1000
|
+
const alpha = props.still ? 1 : 0.925 - 0.075 * Math.cos(2 * Math.PI * (Date.now() % 5e3) / 5e3);
|
|
1001
|
+
return label({ x: Math.round(props.width * 0.18), y: 0, width, height: 1, alpha }, ...strips);
|
|
1002
|
+
});
|
|
1003
|
+
var CHECK_PATH = [[4.5, 12.75], [10.5, 18.75], [19.5, 5.25]];
|
|
1004
|
+
var CHECK_BOX = 34;
|
|
1005
|
+
var CHECK_STROKE = 4;
|
|
1006
|
+
var CHECK_CIRCLE = 66;
|
|
1007
|
+
var CHECK_ROOM = 3;
|
|
1008
|
+
var CHECK_DOTS = (() => {
|
|
1009
|
+
const scale = CHECK_BOX / 24;
|
|
1010
|
+
const dots = [];
|
|
1011
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1012
|
+
let travelled = 0;
|
|
1013
|
+
for (let index = 1; index < CHECK_PATH.length; index++) {
|
|
1014
|
+
const [x0, y0] = CHECK_PATH[index - 1].map((value) => value * scale);
|
|
1015
|
+
const [x1, y1] = CHECK_PATH[index].map((value) => value * scale);
|
|
1016
|
+
const length = Math.hypot(x1 - x0, y1 - y0);
|
|
1017
|
+
const steps = Math.ceil(length / 0.5);
|
|
1018
|
+
for (let step = 0; step <= steps; step++) {
|
|
1019
|
+
const f = step / steps;
|
|
1020
|
+
const x = Math.round(x0 + (x1 - x0) * f - CHECK_STROKE / 2);
|
|
1021
|
+
const y = Math.round(y0 + (y1 - y0) * f - CHECK_STROKE / 2);
|
|
1022
|
+
if (!seen.has(`${x},${y}`)) {
|
|
1023
|
+
seen.add(`${x},${y}`);
|
|
1024
|
+
dots.push({ x, y, at: travelled + length * f });
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
travelled += length;
|
|
1028
|
+
}
|
|
1029
|
+
return dots;
|
|
1030
|
+
})();
|
|
1031
|
+
var CHECK_LENGTH = CHECK_DOTS[CHECK_DOTS.length - 1].at;
|
|
1032
|
+
function SuccessCheck(props) {
|
|
1033
|
+
const elapsed = useEntrance("check", 700, props.still) * 700;
|
|
1034
|
+
const pop = Math.min(1, elapsed / 500);
|
|
1035
|
+
const scale = pop < 0.6 ? 0.4 + 0.68 * EASE(pop / 0.6) : 1.08 - 0.08 * EASE((pop - 0.6) / 0.4);
|
|
1036
|
+
const diameter = Math.round(CHECK_CIRCLE * scale);
|
|
1037
|
+
const drawn = Math.min(CHECK_LENGTH, 30 * (CHECK_BOX / 24) * EASE_CSS(Math.max(0, Math.min(1, (elapsed - 200) / 500))));
|
|
1038
|
+
const middle = CHECK_CIRCLE / 2 + CHECK_ROOM;
|
|
1039
|
+
return label({ x: props.x - CHECK_ROOM, y: props.y - CHECK_ROOM, width: CHECK_CIRCLE + CHECK_ROOM * 2, height: CHECK_CIRCLE + CHECK_ROOM * 2 }, label({
|
|
1040
|
+
key: "circle",
|
|
1041
|
+
x: Math.round(middle - diameter / 2),
|
|
1042
|
+
y: Math.round(middle - diameter / 2),
|
|
1043
|
+
width: diameter,
|
|
1044
|
+
height: diameter,
|
|
1045
|
+
cornerRadius: diameter / 2,
|
|
1046
|
+
backgroundColor: color(palette.successDeep, 0.14),
|
|
1047
|
+
border: { width: 1, color: color(palette.successDeep, 0.35) },
|
|
1048
|
+
alpha: EASE(pop)
|
|
1049
|
+
}), label({
|
|
1050
|
+
key: "tick",
|
|
1051
|
+
x: middle - CHECK_BOX / 2,
|
|
1052
|
+
y: middle - CHECK_BOX / 2,
|
|
1053
|
+
width: CHECK_BOX,
|
|
1054
|
+
height: CHECK_BOX
|
|
1055
|
+
}, ...CHECK_DOTS.filter((dot) => drawn > 0 && dot.at <= drawn).map((dot, index) => label({
|
|
1056
|
+
key: `dot-${index}`,
|
|
1057
|
+
x: dot.x,
|
|
1058
|
+
y: dot.y,
|
|
1059
|
+
width: CHECK_STROKE,
|
|
1060
|
+
height: CHECK_STROKE,
|
|
1061
|
+
cornerRadius: CHECK_STROKE / 2,
|
|
1062
|
+
backgroundColor: color(palette.success)
|
|
1063
|
+
}))));
|
|
1064
|
+
}
|
|
729
1065
|
function Spinner(props) {
|
|
730
1066
|
const tick = useTick(90);
|
|
731
1067
|
const dots = 10;
|
|
@@ -780,16 +1116,16 @@ var PAD_X = 40;
|
|
|
780
1116
|
var PAD_TOP = 34;
|
|
781
1117
|
var PAD_BOTTOM = 22;
|
|
782
1118
|
function useMoonbaseState(moonbase) {
|
|
783
|
-
const [state, setState] =
|
|
784
|
-
|
|
1119
|
+
const [state, setState] = React3.useState(() => moonbase.state());
|
|
1120
|
+
React3.useEffect(() => {
|
|
785
1121
|
setState(moonbase.state());
|
|
786
1122
|
return moonbase.subscribe(setState);
|
|
787
1123
|
}, [moonbase]);
|
|
788
1124
|
return state;
|
|
789
1125
|
}
|
|
790
1126
|
function useUiState(moonbase) {
|
|
791
|
-
const [ui, setUi] =
|
|
792
|
-
|
|
1127
|
+
const [ui, setUi] = React3.useState(() => moonbase.uiSnapshot());
|
|
1128
|
+
React3.useEffect(() => {
|
|
793
1129
|
setUi(moonbase.uiSnapshot());
|
|
794
1130
|
return moonbase.subscribeUi(() => setUi(moonbase.uiSnapshot()));
|
|
795
1131
|
}, [moonbase]);
|
|
@@ -830,15 +1166,15 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
830
1166
|
const strings = (_d = ui.strings) != null ? _d : {};
|
|
831
1167
|
const cardWidth = Math.min(CARD_WIDTH, areaWidth - 32);
|
|
832
1168
|
const width = cardWidth - PAD_X * 2;
|
|
833
|
-
const
|
|
834
|
-
const [
|
|
835
|
-
const [
|
|
836
|
-
const [
|
|
837
|
-
const [
|
|
838
|
-
const
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
|
|
1169
|
+
const still = !!ui.reduceMotion;
|
|
1170
|
+
const [view, setView] = React3.useState(null);
|
|
1171
|
+
const [update, setUpdate] = React3.useState(null);
|
|
1172
|
+
const [cameFromDetails, setCameFromDetails] = React3.useState(false);
|
|
1173
|
+
const [offline, setOffline] = React3.useState({ saved: null, file: null, busy: false, error: "" });
|
|
1174
|
+
const [copied, setCopied] = React3.useState(null);
|
|
1175
|
+
const previous = React3.useRef(null);
|
|
1176
|
+
const run2 = (name2, action) => {
|
|
1177
|
+
action().catch((err) => moonbase.reportError(name2, err));
|
|
842
1178
|
};
|
|
843
1179
|
const close = () => moonbase.closeUi();
|
|
844
1180
|
const canClose = state.status !== "activating" && state.status !== "loading" && state.licensed;
|
|
@@ -851,7 +1187,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
851
1187
|
if (next === "update")
|
|
852
1188
|
loadUpdate();
|
|
853
1189
|
if (next === "addons")
|
|
854
|
-
run2(() => moonbase.loadAddOns());
|
|
1190
|
+
run2("loadAddOns", () => moonbase.loadAddOns());
|
|
855
1191
|
};
|
|
856
1192
|
const openUpdate = (fromDetails) => {
|
|
857
1193
|
setCameFromDetails(fromDetails);
|
|
@@ -861,7 +1197,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
861
1197
|
setCopied(what);
|
|
862
1198
|
setTimeout(() => setCopied((current) => current === what ? null : current), 2e3);
|
|
863
1199
|
};
|
|
864
|
-
|
|
1200
|
+
React3.useEffect(() => {
|
|
865
1201
|
if (screen === "update")
|
|
866
1202
|
return openUpdate(false);
|
|
867
1203
|
let next = screen === "license" ? "details" : screen;
|
|
@@ -869,7 +1205,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
869
1205
|
next = null;
|
|
870
1206
|
go(next);
|
|
871
1207
|
}, [request]);
|
|
872
|
-
|
|
1208
|
+
React3.useEffect(() => {
|
|
873
1209
|
var _a2;
|
|
874
1210
|
const before = previous.current;
|
|
875
1211
|
previous.current = state;
|
|
@@ -886,7 +1222,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
886
1222
|
if (next === "success" && !state.license)
|
|
887
1223
|
next = null;
|
|
888
1224
|
if (next === "addons" && state.license && state.addOns.phase === "idle" && before && before.addOns.phase !== "idle")
|
|
889
|
-
run2(() => moonbase.loadAddOns());
|
|
1225
|
+
run2("loadAddOns", () => moonbase.loadAddOns());
|
|
890
1226
|
if (next !== view)
|
|
891
1227
|
setView(next);
|
|
892
1228
|
}, [state]);
|
|
@@ -903,10 +1239,10 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
903
1239
|
render: (x, y, available) => {
|
|
904
1240
|
const nodes = [lockup({ dim: options.dim }).render(x, y, available)];
|
|
905
1241
|
let right = x + available - (canClose ? 40 : 0);
|
|
906
|
-
for (const
|
|
907
|
-
const drawn = pill(theme,
|
|
1242
|
+
for (const each2 of [...pills].reverse()) {
|
|
1243
|
+
const drawn = pill(theme, each2.tone, each2.text, 0, 0, each2.onClick);
|
|
908
1244
|
right -= drawn.width;
|
|
909
|
-
nodes.push(pill(theme,
|
|
1245
|
+
nodes.push(pill(theme, each2.tone, each2.text, right, y + 5, each2.onClick).node);
|
|
910
1246
|
right -= 8;
|
|
911
1247
|
}
|
|
912
1248
|
return nodes;
|
|
@@ -941,7 +1277,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
941
1277
|
render: (x, y) => list.map((feature, index) => label({ key: `feature-${index}`, x, y: y + index * 30, width, height: 20 }, text(theme, feature.included ? "\u2713" : "\xD7", 0, 0, 20, { size: 14, weight: 700, textColor: feature.included ? color(palette.success) : palette.textMuted }), text(theme, feature.label, 28, 0, width - 28, { size: 13, textColor: feature.included ? palette.textBody : palette.textMuted })))
|
|
942
1278
|
};
|
|
943
1279
|
};
|
|
944
|
-
const unlock = () => buttonBlock(theme, "Unlock full version", () => run2(() => moonbase.activate()));
|
|
1280
|
+
const unlock = () => buttonBlock(theme, "Unlock full version", () => run2("activate", () => moonbase.activate()));
|
|
945
1281
|
const screens = {
|
|
946
1282
|
loading: () => [
|
|
947
1283
|
{ height: 34, render: (x, y, available) => h(Spinner, { key: "spinner", x: x + available / 2 - 17, y, size: 34, tint: "#82cef1" }) },
|
|
@@ -959,7 +1295,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
959
1295
|
space(8),
|
|
960
1296
|
paragraph(theme, body, width, { maxWidth: 430 }),
|
|
961
1297
|
space(28),
|
|
962
|
-
buttonBlock(theme, strings.activateOnline || "Activate online", () => run2(() => moonbase.activate()), { width: 340, height: 44 }),
|
|
1298
|
+
buttonBlock(theme, strings.activateOnline || "Activate online", () => run2("activate", () => moonbase.activate()), { width: 340, height: 44 }),
|
|
963
1299
|
errorLine((_a2 = state.error) == null ? void 0 : _a2.message),
|
|
964
1300
|
linksBlock(theme, [{ label: strings.activateOffline || "No internet? Activate offline", onClick: () => go("offline") }], { align: "left", marginTop: 24 })
|
|
965
1301
|
];
|
|
@@ -977,8 +1313,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
977
1313
|
const copyLink = () => {
|
|
978
1314
|
if (!url)
|
|
979
1315
|
return;
|
|
980
|
-
moonbase.copyText(url).then(() => flashCopied(url), () =>
|
|
981
|
-
});
|
|
1316
|
+
moonbase.copyText(url).then(() => flashCopied(url), (err) => moonbase.reportError("copyText", err));
|
|
982
1317
|
};
|
|
983
1318
|
const body = !url ? "Creating a secure activation request with your store." : failed ? "We couldn't open your browser. Copy the activation link, open it in any browser on this computer or another, then sign in and confirm this device." : `We opened ${host} in your browser. Sign in and confirm this device; we'll pick it up automatically.`;
|
|
984
1319
|
return [
|
|
@@ -1000,7 +1335,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1000
1335
|
},
|
|
1001
1336
|
buttonBlock(theme, "Cancel activation", () => moonbase.cancelActivation(), { kind: "ghost", width: 300, height: 44, align: "center" }),
|
|
1002
1337
|
!!url && !failed && linksBlock(theme, [
|
|
1003
|
-
{ label: "Open the page again", onClick: () => run2(() => moonbase.openLink(url)) },
|
|
1338
|
+
{ label: "Open the page again", onClick: () => run2("openLink", () => moonbase.openLink(url)) },
|
|
1004
1339
|
{ label: linkCopied ? "\u2713 Link copied" : "Browser didn't open? Copy the link", link: true, onClick: copyLink }
|
|
1005
1340
|
]),
|
|
1006
1341
|
errorLine((_d2 = state.error) == null ? void 0 : _d2.message)
|
|
@@ -1014,7 +1349,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1014
1349
|
return [
|
|
1015
1350
|
{
|
|
1016
1351
|
height: 66 + 6,
|
|
1017
|
-
render: (x, y, available) =>
|
|
1352
|
+
render: (x, y, available) => h(SuccessCheck, { key: "check", x: Math.round(x + available / 2 - 33), y: y + 6, still })
|
|
1018
1353
|
},
|
|
1019
1354
|
space(22),
|
|
1020
1355
|
heading(theme, license.trial ? "Your trial has started" : "You're all set", width, { align: "center" }),
|
|
@@ -1039,13 +1374,19 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1039
1374
|
setOffline((current) => ({ ...current, error: "" }));
|
|
1040
1375
|
moonbase.saveMachineFile().then(
|
|
1041
1376
|
(saved) => setOffline((current) => ({ ...current, saved: saved != null ? saved : current.saved })),
|
|
1042
|
-
(err) =>
|
|
1377
|
+
(err) => {
|
|
1378
|
+
moonbase.reportError("saveMachineFile", err);
|
|
1379
|
+
setOffline((current) => ({ ...current, error: err instanceof Error ? err.message : String(err) }));
|
|
1380
|
+
}
|
|
1043
1381
|
);
|
|
1044
1382
|
};
|
|
1045
1383
|
const useFile = (pick) => {
|
|
1046
1384
|
pick.then(
|
|
1047
1385
|
(file) => file && setOffline((current) => ({ ...current, file, error: "" })),
|
|
1048
|
-
() =>
|
|
1386
|
+
(err) => {
|
|
1387
|
+
moonbase.reportError("readLicenseFile", err);
|
|
1388
|
+
setOffline((current) => ({ ...current, error: "Couldn't read that file." }));
|
|
1389
|
+
}
|
|
1049
1390
|
);
|
|
1050
1391
|
};
|
|
1051
1392
|
const activateOffline = () => {
|
|
@@ -1151,9 +1492,9 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1151
1492
|
paragraph(theme, body, width),
|
|
1152
1493
|
space(22),
|
|
1153
1494
|
notice(`${product} is locked. Your license still works with the versions it covers, so you can go back to one of those, or upgrade to use this one.`, "upgrade"),
|
|
1154
|
-
buttonBlock(theme, upgradeLabel(access), () => run2(() => moonbase.upgradeLicense())),
|
|
1495
|
+
buttonBlock(theme, upgradeLabel(access), () => run2("upgradeLicense", () => moonbase.upgradeLicense())),
|
|
1155
1496
|
errorLine((_a2 = state.error) == null ? void 0 : _a2.message),
|
|
1156
|
-
linksBlock(theme, [offlineLicense ? { label: "Load an upgraded license file", onClick: () => go("offline") } : { label: state.refreshing ? "Checking your license\u2026" : renewal ? "Already renewed? Check again" : "Already upgraded? Check again", disabled: state.refreshing, onClick: () => run2(() => moonbase.refresh()) }])
|
|
1497
|
+
linksBlock(theme, [offlineLicense ? { label: "Load an upgraded license file", onClick: () => go("offline") } : { label: state.refreshing ? "Checking your license\u2026" : renewal ? "Already renewed? Check again" : "Already upgraded? Check again", disabled: state.refreshing, onClick: () => run2("refresh", () => moonbase.refresh()) }])
|
|
1157
1498
|
];
|
|
1158
1499
|
},
|
|
1159
1500
|
details: () => {
|
|
@@ -1179,8 +1520,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1179
1520
|
]),
|
|
1180
1521
|
{
|
|
1181
1522
|
height: (rows.length + 1) * rowHeight + 2 + 18,
|
|
1182
|
-
render: (x, y) => card({ x, y, width, height: (rows.length + 1) * rowHeight + 2 }, ...rows.map(([key, value], index) => label({ key, x: 16, y: 1 + index * rowHeight, width: width - 32, height: rowHeight }, text(theme, key, 0, 0, 140, { size: 12.5, height: rowHeight }), text(theme, value, 140, 0, width - 172, { size: 13, weight: 500, textColor: index === 1 ? palette.textBody : palette.textPrimary, align: "right", height: rowHeight }), label({ x: 0, y: rowHeight - 1, width: width - 32, height: 1, backgroundColor: palette.divider }))), label({ key: "id", x: 16, y: 1 + rows.length * rowHeight, width: width - 32, height: rowHeight }, text(theme, "License ID", 0, 0, 100, { size: 12.5, height: rowHeight }), text(theme, license.id, 100, 0, width - 32 - 100 - 84, { size: 12, mono: true, textColor: palette.glow, align: "right", height: rowHeight }), h(Button, { key: "copy", theme, x: width - 32 - 74, y: 7, width: 74, height: 30, label: idCopied ? "\u2713 Copied" : "Copy", kind: "quiet", size: 11.5, onClick: () => moonbase.copyText(license.id).then(() => flashCopied(license.id), () =>
|
|
1183
|
-
}) })))
|
|
1523
|
+
render: (x, y) => card({ x, y, width, height: (rows.length + 1) * rowHeight + 2 }, ...rows.map(([key, value], index) => label({ key, x: 16, y: 1 + index * rowHeight, width: width - 32, height: rowHeight }, text(theme, key, 0, 0, 140, { size: 12.5, height: rowHeight }), text(theme, value, 140, 0, width - 172, { size: 13, weight: 500, textColor: index === 1 ? palette.textBody : palette.textPrimary, align: "right", height: rowHeight }), label({ x: 0, y: rowHeight - 1, width: width - 32, height: 1, backgroundColor: palette.divider }))), label({ key: "id", x: 16, y: 1 + rows.length * rowHeight, width: width - 32, height: rowHeight }, text(theme, "License ID", 0, 0, 100, { size: 12.5, height: rowHeight }), text(theme, license.id, 100, 0, width - 32 - 100 - 84, { size: 12, mono: true, textColor: palette.glow, align: "right", height: rowHeight }), h(Button, { key: "copy", theme, x: width - 32 - 74, y: 7, width: 74, height: 30, label: idCopied ? "\u2713 Copied" : "Copy", kind: "quiet", size: 11.5, onClick: () => moonbase.copyText(license.id).then(() => flashCopied(license.id), (err) => moonbase.reportError("copyText", err)) })))
|
|
1184
1524
|
},
|
|
1185
1525
|
{
|
|
1186
1526
|
height: 64 + 22,
|
|
@@ -1194,7 +1534,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1194
1534
|
kind: "danger",
|
|
1195
1535
|
disabled: state.busy,
|
|
1196
1536
|
label: state.busy ? "Deactivating\u2026" : license.trial || license.activationMethod === "Offline" ? "Remove from this device" : "Deactivate this device",
|
|
1197
|
-
onClick: () => run2(() => moonbase.deactivate())
|
|
1537
|
+
onClick: () => run2("deactivate", () => moonbase.deactivate())
|
|
1198
1538
|
}))
|
|
1199
1539
|
},
|
|
1200
1540
|
errorLine((_a2 = state.error) == null ? void 0 : _a2.message),
|
|
@@ -1246,7 +1586,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1246
1586
|
label: loading ? "Checking\u2026" : failed ? "Try again" : "Bought an add-on? Refresh",
|
|
1247
1587
|
link: true,
|
|
1248
1588
|
disabled: loading || waiting,
|
|
1249
|
-
onClick: () => run2(() => failed ? moonbase.loadAddOns() : moonbase.refreshAddOns())
|
|
1589
|
+
onClick: () => run2(failed ? "loadAddOns" : "refreshAddOns", () => failed ? moonbase.loadAddOns() : moonbase.refreshAddOns())
|
|
1250
1590
|
}], { align: "left" })
|
|
1251
1591
|
];
|
|
1252
1592
|
},
|
|
@@ -1279,11 +1619,11 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1279
1619
|
const notesHeight = noteBlocks.reduce((sum, block) => sum + block.height + 8, 0) + 30 + 20;
|
|
1280
1620
|
let action;
|
|
1281
1621
|
if (download.phase === "done")
|
|
1282
|
-
action = buttonBlock(theme, "Show in folder", () => run2(() => moonbase.revealUpdate()));
|
|
1622
|
+
action = buttonBlock(theme, "Show in folder", () => run2("revealUpdate", () => moonbase.revealUpdate()));
|
|
1283
1623
|
else if (notCovered)
|
|
1284
|
-
action = upgradeUrl ? buttonBlock(theme, upgradeLabel(access), () => run2(() => moonbase.upgradeLicense())) : null;
|
|
1624
|
+
action = upgradeUrl ? buttonBlock(theme, upgradeLabel(access), () => run2("upgradeLicense", () => moonbase.upgradeLicense())) : null;
|
|
1285
1625
|
else if (update.canDownload)
|
|
1286
|
-
action = buttonBlock(theme, downloading ? percent !== null ? `Downloading\u2026 ${percent}%` : "Downloading\u2026" : `Download ${update.latestVersion}`, () => run2(() => moonbase.downloadUpdate()), { disabled: downloading });
|
|
1626
|
+
action = buttonBlock(theme, downloading ? percent !== null ? `Downloading\u2026 ${percent}%` : "Downloading\u2026" : `Download ${update.latestVersion}`, () => run2("downloadUpdate", () => moonbase.downloadUpdate()), { disabled: downloading });
|
|
1287
1627
|
else
|
|
1288
1628
|
action = update.hasDownloads ? unlock() : null;
|
|
1289
1629
|
const standing = notCovered ? ", which your license doesn't cover." : !update.hasDownloads ? ", which has no download for this computer yet." : update.canDownload ? ", included in your license." : ", which your license doesn't include yet.";
|
|
@@ -1315,8 +1655,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1315
1655
|
{ label: "Remind me later", onClick: back },
|
|
1316
1656
|
{ label: "Skip this version", onClick: () => {
|
|
1317
1657
|
var _a3;
|
|
1318
|
-
moonbase.skipUpdate((_a3 = update.latestVersion) != null ? _a3 : "").catch(() =>
|
|
1319
|
-
}).then(back);
|
|
1658
|
+
moonbase.skipUpdate((_a3 = update.latestVersion) != null ? _a3 : "").catch((err) => moonbase.reportError("skipUpdate", err)).then(back);
|
|
1320
1659
|
} }
|
|
1321
1660
|
])
|
|
1322
1661
|
];
|
|
@@ -1338,7 +1677,7 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1338
1677
|
const value = primary && busyId === row.id ? "\u2026" : addOnActions[action].label;
|
|
1339
1678
|
const buttonWidth = Math.max(76, textWidth(value, 13, 600) + 32);
|
|
1340
1679
|
right -= buttonWidth;
|
|
1341
|
-
const node = h(Button, { key: action, theme, x: right, y: (rowHeight - 34) / 2, width: buttonWidth, height: 34, size: 13, label: value, kind: primary ? "small-primary" : "small-ghost", disabled: anyBusy, onClick: () => run2(() => addOnActions[action].run(row.id)) });
|
|
1680
|
+
const node = h(Button, { key: action, theme, x: right, y: (rowHeight - 34) / 2, width: buttonWidth, height: 34, size: 13, label: value, kind: primary ? "small-primary" : "small-ghost", disabled: anyBusy, onClick: () => run2(action, () => addOnActions[action].run(row.id)) });
|
|
1342
1681
|
right -= 8;
|
|
1343
1682
|
return node;
|
|
1344
1683
|
});
|
|
@@ -1360,11 +1699,47 @@ function Panel({ moonbase, state, screen, request, download, width: areaWidth, h
|
|
|
1360
1699
|
const cardHeight = PAD_TOP + content.height + footer + PAD_BOTTOM;
|
|
1361
1700
|
const top = Math.max(12, Math.round((areaHeight - cardHeight) / 2));
|
|
1362
1701
|
const left = Math.round((areaWidth - cardWidth) / 2);
|
|
1363
|
-
return
|
|
1702
|
+
return h(PanelCard, {
|
|
1703
|
+
key: "card",
|
|
1704
|
+
left,
|
|
1705
|
+
top,
|
|
1706
|
+
width: cardWidth,
|
|
1707
|
+
height: cardHeight,
|
|
1708
|
+
screen: name,
|
|
1709
|
+
contentHeight: content.height,
|
|
1710
|
+
content: content.nodes,
|
|
1711
|
+
closeButton: canClose && h(Button, { key: "close", theme, x: cardWidth - 46, y: 14, width: 32, height: 32, label: "\xD7", size: 20, kind: "quiet", onClick: close }),
|
|
1712
|
+
// Kept to the card's bottom edge as it resizes.
|
|
1713
|
+
footer: showBadge ? (height) => {
|
|
1714
|
+
const divider = height - footer - PAD_BOTTOM + 30;
|
|
1715
|
+
return [
|
|
1716
|
+
label({ key: "divider", x: PAD_X, y: divider, width, height: 1, backgroundColor: color("#ffffff", 0.06) }),
|
|
1717
|
+
h(LinkNode, { key: "badge", theme, x: PAD_X, y: divider + 14, width, value: "Licensing secured by moonbase", center: true, muted: true, onClick: () => run2("openLink", () => moonbase.openLink("https://moonbase.sh")) })
|
|
1718
|
+
];
|
|
1719
|
+
} : null,
|
|
1720
|
+
still
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
var PanelView = React3.memo(Panel);
|
|
1724
|
+
function PanelCard(props) {
|
|
1725
|
+
var _a, _b;
|
|
1726
|
+
const [top, height] = useTween([
|
|
1727
|
+
{ to: props.top, duration: 300, ease: EASE },
|
|
1728
|
+
{ to: props.height, duration: 300, ease: EASE }
|
|
1729
|
+
], props.still);
|
|
1730
|
+
const entered = EASE(useEntrance(props.screen, 400, props.still));
|
|
1731
|
+
const cardHeight = Math.round(height);
|
|
1732
|
+
return card(
|
|
1733
|
+
{ x: props.left, y: Math.round(top), width: props.width, height: cardHeight, background: palette.panel, border: color("#ffffff", 0.08), radius: 16 },
|
|
1734
|
+
h(Glow, { key: "glow", width: props.width, still: props.still }),
|
|
1735
|
+
label({ key: "screen", x: 0, y: Math.round(8 * (1 - entered)), width: props.width, height: PAD_TOP + props.contentHeight, alpha: entered }, ...props.content),
|
|
1736
|
+
props.closeButton,
|
|
1737
|
+
...(_b = (_a = props.footer) == null ? void 0 : _a.call(props, cardHeight)) != null ? _b : []
|
|
1738
|
+
);
|
|
1364
1739
|
}
|
|
1365
1740
|
function LinkNode(props) {
|
|
1366
1741
|
var _a;
|
|
1367
|
-
const [hovered, setHovered] =
|
|
1742
|
+
const [hovered, setHovered] = React3.useState(false);
|
|
1368
1743
|
const width = (_a = props.width) != null ? _a : textWidth(props.value, 12.5, 500) + 8;
|
|
1369
1744
|
return label({
|
|
1370
1745
|
x: props.x,
|
|
@@ -1406,7 +1781,12 @@ function MoonbaseActivation(props) {
|
|
|
1406
1781
|
const { moonbase, width, height } = props;
|
|
1407
1782
|
const state = useMoonbaseState(moonbase);
|
|
1408
1783
|
const ui = useUiState(moonbase);
|
|
1409
|
-
|
|
1784
|
+
const shown = ui.visible ? 1 : 0;
|
|
1785
|
+
const [scrim, rise] = useTween([
|
|
1786
|
+
{ to: shown, duration: 250, ease: EASE_CSS },
|
|
1787
|
+
{ to: shown, duration: ui.visible ? 350 : 250, ease: ui.visible ? EASE : EASE_CSS }
|
|
1788
|
+
], !!moonbase.ui.reduceMotion, [0, 0]);
|
|
1789
|
+
if (!ui.visible && scrim === 0 && rise === 0)
|
|
1410
1790
|
return null;
|
|
1411
1791
|
return label({
|
|
1412
1792
|
key: "moonbase-activation",
|
|
@@ -1414,7 +1794,8 @@ function MoonbaseActivation(props) {
|
|
|
1414
1794
|
y: (_b = props.y) != null ? _b : 0,
|
|
1415
1795
|
width,
|
|
1416
1796
|
height,
|
|
1417
|
-
|
|
1797
|
+
// Never quite clear while it is there, coming or going.
|
|
1798
|
+
backgroundColor: color("#04060b", Math.max(1 / 255, 0.62 * scrim)),
|
|
1418
1799
|
alwaysOnTop: true,
|
|
1419
1800
|
// Takes every click, so the plugin underneath is locked while it is up.
|
|
1420
1801
|
interceptsMouseClicks: true,
|
|
@@ -1422,12 +1803,19 @@ function MoonbaseActivation(props) {
|
|
|
1422
1803
|
// the front, after the customer bought an add-on in the browser.
|
|
1423
1804
|
onMouseEnter: () => moonbase.onFocusChanged(true),
|
|
1424
1805
|
onMouseExit: () => moonbase.onFocusChanged(false)
|
|
1425
|
-
}, h(
|
|
1806
|
+
}, label({ key: "rise", x: 0, y: Math.round(12 * (1 - rise)), width, height, alpha: rise }, h(PanelView, { moonbase, state, screen: ui.screen, request: ui.request, download: ui.download, width, height })));
|
|
1426
1807
|
}
|
|
1808
|
+
|
|
1809
|
+
// src/index.ts
|
|
1810
|
+
import { ActivationError as ActivationError2, MoonbaseError as MoonbaseError2, ReleaseNotCoveredError as ReleaseNotCoveredError2 } from "@moonbase.sh/licensing";
|
|
1427
1811
|
export {
|
|
1812
|
+
ActivationError2 as ActivationError,
|
|
1428
1813
|
MoonbaseActivation,
|
|
1814
|
+
MoonbaseError2 as MoonbaseError,
|
|
1429
1815
|
MoonbaseGorillaEngine,
|
|
1816
|
+
ReleaseNotCoveredError2 as ReleaseNotCoveredError,
|
|
1430
1817
|
createMoonbase,
|
|
1431
1818
|
defaultLicenseFile,
|
|
1819
|
+
gorillaEngineHost,
|
|
1432
1820
|
useMoonbaseState
|
|
1433
1821
|
};
|