@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.
- 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 -4
package/dist/ui/ui.js
ADDED
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// The activation UI, shared by the module's own window (window.js) and the
|
|
4
|
+
// overlay over one of the app's windows (overlay.js). Every screen renders from
|
|
5
|
+
// the license state the main process pushes in, and every action is a command
|
|
6
|
+
// sent to it. Server-provided text only ever goes into the page as text.
|
|
7
|
+
//
|
|
8
|
+
// The same UI as tauri-plugin-moonbase's, from the "Solstice Activation" design:
|
|
9
|
+
// keep the two in step.
|
|
10
|
+
//
|
|
11
|
+
// mode is 'window' or 'overlay'. In a window the page is the panel and reports its
|
|
12
|
+
// height so the window fits each screen; as an overlay the panel floats over the
|
|
13
|
+
// app, which it locks while there is no license.
|
|
14
|
+
// eslint-disable-next-line no-unused-vars
|
|
15
|
+
function createActivationUI({ root, config, invoke, mode, onHeight }) {
|
|
16
|
+
const product = config.productName
|
|
17
|
+
const account = config.manufacturerName || 'Moonbase'
|
|
18
|
+
const overlay = mode === 'overlay'
|
|
19
|
+
const MOONBASE_SITE = 'https://moonbase.sh'
|
|
20
|
+
|
|
21
|
+
// -- Building blocks ------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
function h(tag, props = {}, ...children) {
|
|
24
|
+
const el = document.createElement(tag)
|
|
25
|
+
for (const [key, value] of Object.entries(props)) {
|
|
26
|
+
if (value === undefined || value === null || value === false) continue
|
|
27
|
+
if (key.startsWith('on')) el.addEventListener(key.slice(2).toLowerCase(), value)
|
|
28
|
+
else if (key === 'class') el.className = value
|
|
29
|
+
else if (key === 'style') el.style.cssText = value
|
|
30
|
+
else el.setAttribute(key, value === true ? '' : value)
|
|
31
|
+
}
|
|
32
|
+
for (const child of children.flat(Infinity)) {
|
|
33
|
+
if (child === null || child === undefined || child === false) continue
|
|
34
|
+
el.append(child instanceof Node ? child : document.createTextNode(String(child)))
|
|
35
|
+
}
|
|
36
|
+
return el
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Static markup only: icons defined in this file.
|
|
40
|
+
function svg(markup) {
|
|
41
|
+
const template = document.createElement('template')
|
|
42
|
+
template.innerHTML = markup.trim()
|
|
43
|
+
return template.content.firstChild
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const icon = (path, { size = 16, stroke = 'currentColor', width = 1.8 } = {}) =>
|
|
47
|
+
svg(`<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="${stroke}" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round"><path d="${path}"></path></svg>`)
|
|
48
|
+
|
|
49
|
+
const paths = {
|
|
50
|
+
check: 'M4.5 12.75l6 6 9-13.5',
|
|
51
|
+
cross: 'M6 18 18 6M6 6l12 12',
|
|
52
|
+
lock: 'M16.5 10.5V6.75a4.5 4.5 0 1 0-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H6.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25z',
|
|
53
|
+
back: 'M15.75 19.5 8.25 12l7.5-7.5',
|
|
54
|
+
chevron: 'm8.25 4.5 7.5 7.5-7.5 7.5',
|
|
55
|
+
signal:
|
|
56
|
+
'M9.348 14.652a3.75 3.75 0 010-5.304m5.304 0a3.75 3.75 0 010 5.304m-7.425 2.121a6.75 6.75 0 010-9.546m9.546 0a6.75 6.75 0 010 9.546M5.106 18.894c-3.808-3.807-3.808-9.98 0-13.788m13.788 0c3.808 3.807 3.808 9.98 0 13.788M12 12h.008v.008H12V12z',
|
|
57
|
+
computer:
|
|
58
|
+
'M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25',
|
|
59
|
+
fileDown:
|
|
60
|
+
'M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m.75 12 3 3m0 0 3-3m-3 3v-6m-1.5-9H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9z',
|
|
61
|
+
upload:
|
|
62
|
+
'M7.5 7.5h-.75A2.25 2.25 0 0 0 4.5 9.75v7.5a2.25 2.25 0 0 0 2.25 2.25h7.5a2.25 2.25 0 0 0 2.25-2.25v-7.5a2.25 2.25 0 0 0-2.25-2.25h-.75m-6 3.75 3-3m0 0 3 3m-3-3v11.25m6-2.25h.75a2.25 2.25 0 0 0 2.25-2.25v-7.5a2.25 2.25 0 0 0-2.25-2.25h-.75',
|
|
63
|
+
okCircle: 'M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z',
|
|
64
|
+
warning:
|
|
65
|
+
'M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z',
|
|
66
|
+
blocked:
|
|
67
|
+
'M18.364 18.364A9 9 0 0 0 5.636 5.636m12.728 12.728A9 9 0 0 1 5.636 5.636m12.728 12.728L5.636 5.636',
|
|
68
|
+
copy: 'M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375',
|
|
69
|
+
download:
|
|
70
|
+
'M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3',
|
|
71
|
+
puzzle:
|
|
72
|
+
'M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959v0a.64.64 0 0 1-.657.643 48.4 48.4 0 0 1-4.163-.3c.186 1.613.293 3.25.315 4.907a.656.656 0 0 1-.658.663v0c-.355 0-.676-.186-.959-.401a1.647 1.647 0 0 0-1.003-.349c-1.036 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401v0c.31 0 .555.26.532.57a48.04 48.04 0 0 1-.642 5.056c1.518.19 3.058.309 4.616.354a.64.64 0 0 0 .657-.643v0c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.035 1.008-1.875 2.25-1.875 1.243 0 2.25.84 2.25 1.875 0 .369-.128.713-.349 1.003-.215.283-.4.604-.4.959v0c0 .333.277.599.61.58a48.1 48.1 0 0 0 5.427-.63 48.05 48.05 0 0 0 .582-4.717.532.532 0 0 0-.533-.57v0c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.035 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.37 0 .713.128 1.003.349.283.215.604.401.96.401v0a.656.656 0 0 0 .658-.663 48.4 48.4 0 0 0-.37-5.36c-1.886.342-3.81.574-5.766.689a.578.578 0 0 1-.61-.58v0z',
|
|
73
|
+
external:
|
|
74
|
+
'M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25',
|
|
75
|
+
sparkles:
|
|
76
|
+
'M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09Z',
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const spinner = (size = 17) =>
|
|
80
|
+
svg(`<svg class="spin" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="9" stroke="rgba(255,255,255,0.3)" stroke-width="3"></circle><path d="M21 12a9 9 0 0 0-9-9" stroke="#fff" stroke-width="3" stroke-linecap="round"></path></svg>`)
|
|
81
|
+
|
|
82
|
+
const bigSpinner = (small = false) =>
|
|
83
|
+
h(
|
|
84
|
+
'div',
|
|
85
|
+
{ class: small ? 'spinner small' : 'spinner' },
|
|
86
|
+
svg(
|
|
87
|
+
`<svg width="100%" height="100%" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="9.5" stroke="rgba(255,255,255,0.1)" stroke-width="1.6"></circle><path d="M21.5 12a9.5 9.5 0 0 0-9.5-9.5" stroke="#82cef1" stroke-width="1.6" stroke-linecap="round"></path></svg>`,
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
// The product mark: the app's own logo, or the design's sun in the accent.
|
|
92
|
+
function mark() {
|
|
93
|
+
if (config.logoSvg) {
|
|
94
|
+
// The app's own SVG, inlined: an overlay cannot load images from the plugin.
|
|
95
|
+
const template = document.createElement('template')
|
|
96
|
+
template.innerHTML = config.logoSvg
|
|
97
|
+
const logo = template.content.querySelector('svg')
|
|
98
|
+
if (logo) {
|
|
99
|
+
logo.classList.add('mark')
|
|
100
|
+
return logo
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (config.logo) return h('img', { class: 'mark', src: config.logo, alt: '' })
|
|
104
|
+
return svg(
|
|
105
|
+
`<svg class="mark" viewBox="0 0 38 38" fill="none"><circle cx="19" cy="19" r="13" stroke="var(--accent)" stroke-width="2" opacity="0.9"></circle><circle cx="19" cy="19" r="4.5" fill="var(--accent)"></circle><g stroke="var(--accent)" stroke-width="2" stroke-linecap="round"><line x1="19" y1="1.5" x2="19" y2="6"></line><line x1="19" y1="32" x2="19" y2="36.5"></line><line x1="1.5" y1="19" x2="6" y2="19"></line><line x1="32" y1="19" x2="36.5" y2="19"></line><line x1="6.6" y1="6.6" x2="9.8" y2="9.8"></line><line x1="28.2" y1="28.2" x2="31.4" y2="31.4"></line><line x1="31.4" y1="6.6" x2="28.2" y2="9.8"></line><line x1="9.8" y1="28.2" x2="6.6" y2="31.4"></line></g></svg>`,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const lockup = ({ large = false, dim = false } = {}) =>
|
|
110
|
+
h(
|
|
111
|
+
'div',
|
|
112
|
+
{ class: `lockup${large ? ' large' : ''}${dim ? ' dim' : ''}` },
|
|
113
|
+
mark(),
|
|
114
|
+
h('div', {}, h('div', { class: 'name' }, product), config.manufacturerName && h('div', { class: 'maker' }, config.manufacturerName)),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
const header = (pill, options) => h('div', { class: 'header' }, lockup(options), pill)
|
|
118
|
+
|
|
119
|
+
const button = (label, onClick, { kind = 'primary', iconPath, disabled, short } = {}) =>
|
|
120
|
+
h(
|
|
121
|
+
'button',
|
|
122
|
+
{ class: `btn ${kind}${short ? ' short' : ''}`, type: 'button', disabled, onClick },
|
|
123
|
+
iconPath && icon(iconPath, { width: 1.8 }),
|
|
124
|
+
label,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
const textButton = (label, onClick, { link = false, iconPath, disabled } = {}) =>
|
|
128
|
+
h('button', { class: `text-button${link ? ' link' : ''}`, type: 'button', disabled, onClick }, iconPath && icon(iconPath, { size: 14, width: 1.7 }), label)
|
|
129
|
+
|
|
130
|
+
const backButton = (label, onClick) =>
|
|
131
|
+
h('div', { class: 'back' }, textButton(label, onClick, { iconPath: paths.back }))
|
|
132
|
+
|
|
133
|
+
const errorLine = (message) =>
|
|
134
|
+
message && h('div', { class: 'error', role: 'alert' }, icon(paths.warning, { size: 15 }), h('span', {}, message))
|
|
135
|
+
|
|
136
|
+
const formatDate = (iso) => new Date(iso).toLocaleDateString(undefined, { dateStyle: 'long' })
|
|
137
|
+
const dayMs = 86400000
|
|
138
|
+
const daysUntil = (iso) => Math.max(0, Math.ceil((new Date(iso) - Date.now()) / dayMs))
|
|
139
|
+
const join = (a, b) => (!a ? b : !b ? a : `${a} · ${b}`)
|
|
140
|
+
const osLabel = { macos: 'macOS', windows: 'Windows', linux: 'Linux', ios: 'iOS', android: 'Android' }[config.os] || config.os
|
|
141
|
+
|
|
142
|
+
function trialLength(license) {
|
|
143
|
+
const days = license?.expiresAt && license?.issuedAt ? Math.round((new Date(license.expiresAt) - new Date(license.issuedAt)) / dayMs) : 0
|
|
144
|
+
return days >= 1 ? days : config.trialLengthDays
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function copyText(text) {
|
|
148
|
+
try {
|
|
149
|
+
await invoke('copy_text', { text })
|
|
150
|
+
return
|
|
151
|
+
} catch {
|
|
152
|
+
// Fall back to the page's own clipboard.
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
await navigator.clipboard.writeText(text)
|
|
156
|
+
return
|
|
157
|
+
} catch {
|
|
158
|
+
// Not always allowed from a file page; fall back to a selection.
|
|
159
|
+
}
|
|
160
|
+
const area = h('textarea', { style: 'position:fixed;opacity:0' })
|
|
161
|
+
area.value = text
|
|
162
|
+
root.append(area)
|
|
163
|
+
area.select()
|
|
164
|
+
document.execCommand('copy')
|
|
165
|
+
area.remove()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// -- Copy -------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
const strings = config.strings || {}
|
|
171
|
+
const pick = (custom, fallback) => (custom ? custom : fallback)
|
|
172
|
+
|
|
173
|
+
// What a license that covers only some versions covers, in a sentence or two:
|
|
174
|
+
// "Your updates ended on 1 June 2026. Your license covers releases up to 2.3.0."
|
|
175
|
+
function releaseAccessText(access) {
|
|
176
|
+
if (!access) return ''
|
|
177
|
+
const sentences = []
|
|
178
|
+
if (access.updatesUntil && new Date(access.updatesUntil) < new Date()) sentences.push(`Your updates ended on ${formatDate(access.updatesUntil)}.`)
|
|
179
|
+
const covers = []
|
|
180
|
+
if (access.upToMajor != null) covers.push(`versions up to ${access.upToMajor}.x`)
|
|
181
|
+
if (access.upToVersion) covers.push(`releases up to ${access.upToVersion}`)
|
|
182
|
+
if (covers.length) sentences.push(`Your license covers ${covers.join(' and ')}.`)
|
|
183
|
+
return sentences.join(' ')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// "Renew updates" for a license whose updates ran out, "Upgrade license" for one
|
|
187
|
+
// limited to some majors, as the customer portal words it.
|
|
188
|
+
const upgradeLabel = (access) => (access?.updatesUntil ? 'Renew updates' : 'Upgrade license')
|
|
189
|
+
|
|
190
|
+
function welcomeCopy(reason) {
|
|
191
|
+
switch (reason) {
|
|
192
|
+
case 'deactivated':
|
|
193
|
+
return [pick(strings.deactivatedTitle, 'Deactivated on this computer'), pick(strings.deactivatedBody, `${product} no longer has an active license here. Activate it again to keep using it.`)]
|
|
194
|
+
case 'expired':
|
|
195
|
+
return [pick(strings.licenseExpiredTitle, 'Your license has expired'), pick(strings.licenseExpiredBody, `Renew your ${product} license in your ${account} account, then activate it again.`)]
|
|
196
|
+
case 'invalid':
|
|
197
|
+
return [
|
|
198
|
+
pick(strings.licenseInvalidTitle, 'Your license is no longer valid'),
|
|
199
|
+
pick(strings.licenseInvalidBody, `${account} no longer accepts this license on this computer. Activate again, or contact ${account} if this seems wrong.`),
|
|
200
|
+
]
|
|
201
|
+
case 'unverified':
|
|
202
|
+
return [
|
|
203
|
+
pick(strings.licenseUnverifiedTitle, "Couldn't verify your license"),
|
|
204
|
+
pick(strings.licenseUnverifiedBody, `${product} has gone too long without checking its license online. Connect to the internet and activate again.`),
|
|
205
|
+
]
|
|
206
|
+
default:
|
|
207
|
+
return [pick(strings.welcomeTitle, `Activate ${product}`), pick(strings.welcomeBody, `Unlock ${product} through your ${account} account, or take it for a spin with a free trial.`)]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// -- State --------------------------------------------------------------------------
|
|
212
|
+
|
|
213
|
+
let state = null
|
|
214
|
+
let device = null
|
|
215
|
+
let view = null // a screen the user navigated to, over the one the status implies
|
|
216
|
+
let cameFromDetails = false
|
|
217
|
+
let update = null // release notes, fetched when the update screen opens
|
|
218
|
+
let download = { phase: 'idle' }
|
|
219
|
+
let idCopied = false
|
|
220
|
+
let copiedLink = null // the activation link just copied, while "Link copied" shows
|
|
221
|
+
let copyToken = 0
|
|
222
|
+
const offline = { saved: null, file: null, busy: false, error: '' }
|
|
223
|
+
|
|
224
|
+
function statusScreen() {
|
|
225
|
+
switch (state?.status) {
|
|
226
|
+
case 'unlicensed':
|
|
227
|
+
return 'welcome'
|
|
228
|
+
case 'activating':
|
|
229
|
+
return 'browser'
|
|
230
|
+
case 'licensed':
|
|
231
|
+
return 'details'
|
|
232
|
+
case 'trial':
|
|
233
|
+
return 'trial'
|
|
234
|
+
case 'trialExpired':
|
|
235
|
+
return 'expired'
|
|
236
|
+
case 'notCovered':
|
|
237
|
+
return 'notCovered'
|
|
238
|
+
default:
|
|
239
|
+
return 'loading'
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const screenName = () => view || statusScreen()
|
|
244
|
+
|
|
245
|
+
function go(name) {
|
|
246
|
+
view = name
|
|
247
|
+
if (name === 'update') loadUpdate()
|
|
248
|
+
if (name === 'addons') loadAddOns()
|
|
249
|
+
render()
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const loadAddOns = () => run(() => invoke('load_add_ons'))
|
|
253
|
+
|
|
254
|
+
async function run(action) {
|
|
255
|
+
try {
|
|
256
|
+
await action()
|
|
257
|
+
} catch (error) {
|
|
258
|
+
// The plugin puts the customer-facing reason in state.error and pushes it.
|
|
259
|
+
if (!state?.error) console.warn('moonbase:', error)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function loadUpdate() {
|
|
264
|
+
update = null
|
|
265
|
+
try {
|
|
266
|
+
update = await invoke('check_update')
|
|
267
|
+
} catch (error) {
|
|
268
|
+
update = { available: false, error: error?.message ?? String(error) }
|
|
269
|
+
}
|
|
270
|
+
render()
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// -- Screens ------------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
const screens = {
|
|
276
|
+
loading: () => h('div', { class: 'center' }, bigSpinner(true), h('p', {}, 'Checking your license…')),
|
|
277
|
+
|
|
278
|
+
welcome: () => {
|
|
279
|
+
const [title, body] = welcomeCopy(state.lockReason)
|
|
280
|
+
return h(
|
|
281
|
+
'div',
|
|
282
|
+
{},
|
|
283
|
+
h('div', { style: 'margin-bottom:30px' }, lockup({ large: true })),
|
|
284
|
+
h('h1', { class: 'large' }, title),
|
|
285
|
+
h('p', { style: 'margin-bottom:28px; max-width:430px' }, body),
|
|
286
|
+
h(
|
|
287
|
+
'div',
|
|
288
|
+
{ class: 'stack' },
|
|
289
|
+
button(pick(strings.activateOnline, 'Activate online'), () => run(() => invoke('activate', { offline: false })), { short: true }),
|
|
290
|
+
),
|
|
291
|
+
errorLine(state.error?.message),
|
|
292
|
+
h(
|
|
293
|
+
'div',
|
|
294
|
+
{ style: 'margin-top:24px' },
|
|
295
|
+
textButton(pick(strings.activateOffline, 'No internet? Activate offline'), () => go('offline'), { iconPath: paths.signal }),
|
|
296
|
+
),
|
|
297
|
+
)
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
browser: () => {
|
|
301
|
+
const url = state.activation?.browserUrl
|
|
302
|
+
const host = url ? new URL(url).host : null
|
|
303
|
+
// The way through when the browser didn't open: a quiet link while it
|
|
304
|
+
// probably did, the main action when it couldn't be opened at all (no
|
|
305
|
+
// default browser, say). Either copies the link for any browser, on this
|
|
306
|
+
// computer or another.
|
|
307
|
+
const failed = url && state.activation.browserOpenFailed
|
|
308
|
+
const copied = url && copiedLink === url
|
|
309
|
+
const copyLink = async () => {
|
|
310
|
+
await copyText(url)
|
|
311
|
+
copiedLink = url
|
|
312
|
+
render()
|
|
313
|
+
const token = ++copyToken
|
|
314
|
+
setTimeout(() => {
|
|
315
|
+
if (copyToken !== token) return
|
|
316
|
+
copiedLink = null
|
|
317
|
+
render()
|
|
318
|
+
}, 2000)
|
|
319
|
+
}
|
|
320
|
+
return h(
|
|
321
|
+
'div',
|
|
322
|
+
{ class: 'center' },
|
|
323
|
+
bigSpinner(),
|
|
324
|
+
h('h1', {}, url ? 'Waiting for activation' : 'Starting activation…'),
|
|
325
|
+
h(
|
|
326
|
+
'p',
|
|
327
|
+
{ style: 'margin:0 auto 22px; max-width:420px' },
|
|
328
|
+
!url
|
|
329
|
+
? 'Creating a secure activation request with your store.'
|
|
330
|
+
: failed
|
|
331
|
+
? "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."
|
|
332
|
+
: ['We opened ', h('span', { class: 'em' }, host), " in your browser. Sign in and confirm this device; we'll pick it up automatically."],
|
|
333
|
+
),
|
|
334
|
+
failed &&
|
|
335
|
+
h(
|
|
336
|
+
'div',
|
|
337
|
+
{ class: 'narrow', style: 'max-width:300px; margin-bottom:18px' },
|
|
338
|
+
button(copied ? 'Link copied' : 'Copy activation link', copyLink, { iconPath: copied ? paths.check : paths.copy, short: true }),
|
|
339
|
+
),
|
|
340
|
+
h('div', { class: 'chip' }, icon(paths.computer, { size: 15, stroke: '#768aa4', width: 1.6 }), h('span', {}, `${device?.name || 'This device'} · ${osLabel}`)),
|
|
341
|
+
h('div', { class: 'narrow', style: 'max-width:300px' }, button('Cancel activation', () => run(() => invoke('cancel_activation')), { kind: 'ghost', short: true })),
|
|
342
|
+
url &&
|
|
343
|
+
!failed &&
|
|
344
|
+
h(
|
|
345
|
+
'div',
|
|
346
|
+
{ class: 'links' },
|
|
347
|
+
textButton('Open the page again', () => run(() => invoke('open_link', { url })), {}),
|
|
348
|
+
textButton(copied ? 'Link copied' : "Browser didn't open? Copy the link", copyLink, { link: true, iconPath: copied ? paths.check : paths.copy }),
|
|
349
|
+
),
|
|
350
|
+
errorLine(state.error?.message),
|
|
351
|
+
)
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
success: () => {
|
|
355
|
+
const license = state.license
|
|
356
|
+
if (!license) return screens[statusScreen()]()
|
|
357
|
+
return h(
|
|
358
|
+
'div',
|
|
359
|
+
{ class: 'center' },
|
|
360
|
+
h('div', { class: 'check' }, icon(paths.check, { size: 34, stroke: '#34d27b', width: 2.4 })),
|
|
361
|
+
h('h1', {}, license.trial ? 'Your trial has started' : "You're all set"),
|
|
362
|
+
h(
|
|
363
|
+
'p',
|
|
364
|
+
{ style: 'margin:0 auto 24px; max-width:380px' },
|
|
365
|
+
license.trial
|
|
366
|
+
? `Enjoy ${product}${license.daysRemaining != null ? ` for the next ${license.daysRemaining} days` : ''}. Unlock the full version any time.`
|
|
367
|
+
: `${product} is activated on this machine. Your license is linked to your account.`,
|
|
368
|
+
),
|
|
369
|
+
h(
|
|
370
|
+
'div',
|
|
371
|
+
{ class: 'card mini' },
|
|
372
|
+
h('div', { class: 'row' }, h('span', { class: 'label' }, 'Plan'), h('span', { class: 'value' }, planName(license))),
|
|
373
|
+
h('div', { class: 'row' }, h('span', { class: 'label' }, 'Licensed to'), h('span', { class: 'value' }, license.issuedTo.email || license.issuedTo.name)),
|
|
374
|
+
),
|
|
375
|
+
h('div', { class: 'narrow' }, button(`Open ${product}`, () => invoke('close_ui'))),
|
|
376
|
+
h('div', { class: 'links' }, textButton('View license details', () => go('details'), { link: true })),
|
|
377
|
+
)
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
offline: () => {
|
|
381
|
+
const host = config.activationHost
|
|
382
|
+
const saveSub = offline.saved ? `Saved to ${offline.saved}` : 'Choose where to save it'
|
|
383
|
+
const input = h('input', { type: 'file', accept: '.mb,.jwt,.txt,.lic', onChange: (event) => pickFile(event.target.files?.[0]) })
|
|
384
|
+
const drop = h(
|
|
385
|
+
'label',
|
|
386
|
+
{
|
|
387
|
+
class: 'drop',
|
|
388
|
+
onDragover: (event) => {
|
|
389
|
+
event.preventDefault()
|
|
390
|
+
drop.classList.add('over')
|
|
391
|
+
},
|
|
392
|
+
onDragleave: () => drop.classList.remove('over'),
|
|
393
|
+
onDrop: (event) => {
|
|
394
|
+
event.preventDefault()
|
|
395
|
+
drop.classList.remove('over')
|
|
396
|
+
pickFile(event.dataTransfer?.files?.[0])
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
input,
|
|
400
|
+
offline.file
|
|
401
|
+
? [icon(paths.okCircle, { size: 24, stroke: '#34d27b', width: 1.7 }), h('span', { class: 'title mono' }, offline.file.name), h('span', { class: 'sub' }, 'Click to choose a different file')]
|
|
402
|
+
: [
|
|
403
|
+
icon(paths.upload, { size: 24, stroke: '#768aa4', width: 1.6 }),
|
|
404
|
+
// An app window usually takes dropped files itself, so the overlay only offers a picker.
|
|
405
|
+
h('span', { class: 'title' }, overlay ? 'Choose your license file' : 'Drop your license file here'),
|
|
406
|
+
h('span', { class: 'sub' }, overlay ? 'Click to browse · .mb' : 'or click to browse · .mb'),
|
|
407
|
+
],
|
|
408
|
+
)
|
|
409
|
+
return h(
|
|
410
|
+
'div',
|
|
411
|
+
{},
|
|
412
|
+
backButton('Back', () => go(null)),
|
|
413
|
+
h('h1', {}, 'Offline activation'),
|
|
414
|
+
h(
|
|
415
|
+
'p',
|
|
416
|
+
{ style: 'margin-bottom:24px' },
|
|
417
|
+
'For computers without internet. Save your request file, take it to ',
|
|
418
|
+
h('span', { class: 'em' }, `${host}/activate`),
|
|
419
|
+
' on a connected device, and bring back the license file.',
|
|
420
|
+
),
|
|
421
|
+
h('div', { class: 'step' }, h('span', { class: 'n' }, '1'), h('span', { class: 'label' }, 'Save your request file')),
|
|
422
|
+
h(
|
|
423
|
+
'button',
|
|
424
|
+
{ class: 'file', type: 'button', onClick: saveRequest },
|
|
425
|
+
icon(paths.fileDown, { size: 22, stroke: '#82cef1', width: 1.6 }),
|
|
426
|
+
h('span', { class: 'grow' }, h('span', { class: 'title' }, config.requestFileName), h('span', { class: 'sub' }, saveSub)),
|
|
427
|
+
offline.saved ? icon(paths.check, { size: 20, stroke: '#34d27b', width: 2 }) : h('span', { class: 'action' }, 'Save…'),
|
|
428
|
+
),
|
|
429
|
+
h('div', { class: 'step' }, h('span', { class: 'n' }, '2'), h('span', { class: 'label' }, 'Add the license file')),
|
|
430
|
+
drop,
|
|
431
|
+
errorLine(offline.error),
|
|
432
|
+
h(
|
|
433
|
+
'div',
|
|
434
|
+
{ class: 'offline-submit' },
|
|
435
|
+
button(offline.busy ? [spinner(), 'Verifying…'] : 'Activate offline', activateOffline, { disabled: offline.busy }),
|
|
436
|
+
),
|
|
437
|
+
)
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
trial: () => {
|
|
441
|
+
const license = state.license
|
|
442
|
+
const left = license.daysRemaining
|
|
443
|
+
const total = trialLength(license)
|
|
444
|
+
const endless = left == null
|
|
445
|
+
return h(
|
|
446
|
+
'div',
|
|
447
|
+
{},
|
|
448
|
+
header(h('span', { class: 'pill trial' }, endless ? 'Trial' : `Trial · ${left} ${left === 1 ? 'day' : 'days'} left`)),
|
|
449
|
+
h('h1', {}, "You're on a free trial"),
|
|
450
|
+
h(
|
|
451
|
+
'p',
|
|
452
|
+
{ style: 'margin-bottom:8px' },
|
|
453
|
+
endless ? 'Unlock the full version any time to keep everything.' : `${left} of ${total} days remaining. Unlock the full version any time to keep everything.`,
|
|
454
|
+
),
|
|
455
|
+
endless ? h('div', { style: 'height:18px' }) : h('div', { class: 'bar' }, h('div', { style: `width:${Math.min(100, Math.max(0, (left / total) * 100))}%` })),
|
|
456
|
+
features(),
|
|
457
|
+
button('Unlock full version', () => run(() => invoke('activate', { offline: false })), { iconPath: paths.lock }),
|
|
458
|
+
errorLine(state.error?.message),
|
|
459
|
+
h('div', { class: 'links' }, textButton('Continue trial', () => invoke('close_ui')), textButton('License details', () => go('details'))),
|
|
460
|
+
)
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
expired: () => {
|
|
464
|
+
const trial = state.expiredTrial
|
|
465
|
+
const days = trialLength(trial)
|
|
466
|
+
return h(
|
|
467
|
+
'div',
|
|
468
|
+
{},
|
|
469
|
+
header(h('span', { class: 'pill expired' }, h('span', { class: 'dot' }), 'Trial expired'), { dim: true }),
|
|
470
|
+
h('h1', {}, 'Your trial has ended'),
|
|
471
|
+
h(
|
|
472
|
+
'p',
|
|
473
|
+
{ style: 'margin-bottom:8px' },
|
|
474
|
+
trial?.expiresAt
|
|
475
|
+
? [`Your ${days}-day trial of ${product} ended on `, h('span', { class: 'em' }, formatDate(trial.expiresAt)), '. Unlock the full version to keep using it.']
|
|
476
|
+
: `Your trial of ${product} has ended. Unlock the full version to keep using it.`,
|
|
477
|
+
),
|
|
478
|
+
h('div', { class: 'bar expired', style: 'margin-bottom:22px' }, h('div', { style: 'width:100%' })),
|
|
479
|
+
h(
|
|
480
|
+
'div',
|
|
481
|
+
{ class: 'notice' },
|
|
482
|
+
icon(paths.blocked, { size: 18, stroke: '#f08a8a' }),
|
|
483
|
+
h('span', {}, pick(strings.expiredNotice, `${product}'s full features are locked until it is activated. Your work is safe and opens as usual.`)),
|
|
484
|
+
),
|
|
485
|
+
button('Unlock full version', () => run(() => invoke('activate', { offline: false })), { iconPath: paths.lock }),
|
|
486
|
+
errorLine(state.error?.message),
|
|
487
|
+
h('div', { class: 'links' }, textButton('Activate offline instead', () => go('offline'))),
|
|
488
|
+
)
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
// A valid license that doesn't cover this version of the app, such as one whose
|
|
492
|
+
// updates ended before it came out. Locked like an ended trial, but the license
|
|
493
|
+
// stays: an upgrade or renewal makes it cover this one.
|
|
494
|
+
notCovered: () => {
|
|
495
|
+
const info = state.notCovered
|
|
496
|
+
const access = info?.releaseAccess
|
|
497
|
+
const renewal = !!access?.updatesUntil
|
|
498
|
+
const offlineLicense = info?.license?.activationMethod === 'Offline'
|
|
499
|
+
const title = pick(strings.notCoveredTitle, info?.appVersion ? `Version ${info.appVersion} needs an upgrade` : 'This version needs an upgrade')
|
|
500
|
+
const body = pick(strings.notCoveredBody, releaseAccessText(access) || `Your ${product} license doesn't cover this version.`)
|
|
501
|
+
return h(
|
|
502
|
+
'div',
|
|
503
|
+
{},
|
|
504
|
+
header(h('span', { class: 'pill upgrade' }, h('span', { class: 'dot' }), 'Upgrade needed'), { dim: true }),
|
|
505
|
+
h('h1', {}, title),
|
|
506
|
+
h('p', { style: 'margin-bottom:22px' }, body),
|
|
507
|
+
h(
|
|
508
|
+
'div',
|
|
509
|
+
{ class: 'notice upgrade' },
|
|
510
|
+
icon(paths.warning, { size: 18, stroke: 'var(--trial)' }),
|
|
511
|
+
h('span', {}, `${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.`),
|
|
512
|
+
),
|
|
513
|
+
// Opens the browser either way: the upgrade page, or the activation page
|
|
514
|
+
// that offers it.
|
|
515
|
+
button(upgradeLabel(access), () => run(() => invoke('upgrade_license')), { iconPath: paths.external }),
|
|
516
|
+
errorLine(state.error?.message),
|
|
517
|
+
h(
|
|
518
|
+
'div',
|
|
519
|
+
{ class: 'links' },
|
|
520
|
+
// An offline license is never checked online: the upgraded one comes as a
|
|
521
|
+
// new license file.
|
|
522
|
+
offlineLicense
|
|
523
|
+
? textButton('Load an upgraded license file', () => go('offline'))
|
|
524
|
+
: textButton(state.refreshing ? 'Checking your license…' : renewal ? 'Already renewed? Check again' : 'Already upgraded? Check again', () => run(() => invoke('refresh', { force: true })), {
|
|
525
|
+
disabled: state.refreshing,
|
|
526
|
+
}),
|
|
527
|
+
),
|
|
528
|
+
)
|
|
529
|
+
},
|
|
530
|
+
|
|
531
|
+
details: () => {
|
|
532
|
+
const license = state.license
|
|
533
|
+
if (!license) return screens[statusScreen()]()
|
|
534
|
+
const pills = h(
|
|
535
|
+
'div',
|
|
536
|
+
{ class: 'pills' },
|
|
537
|
+
state.update && h('button', { class: 'pill update', type: 'button', onClick: () => openUpdate(true) }, icon(paths.download, { size: 13, stroke: 'var(--accent)', width: 1.9 }), 'Update'),
|
|
538
|
+
h('span', { class: 'pill active' }, h('span', { class: 'dot' }), license.trial ? 'Trial' : 'Active'),
|
|
539
|
+
)
|
|
540
|
+
const seatCount = license.seatCount
|
|
541
|
+
const used = license.seatsUsed
|
|
542
|
+
const pipCount = seatCount ? Math.min(seatCount, 8) : 0
|
|
543
|
+
return h(
|
|
544
|
+
'div',
|
|
545
|
+
{},
|
|
546
|
+
header(pills),
|
|
547
|
+
h(
|
|
548
|
+
'div',
|
|
549
|
+
{ class: 'card rows' },
|
|
550
|
+
h('div', { class: 'row' }, h('span', { class: 'label' }, 'Licensed to'), h('span', { class: 'value' }, license.issuedTo.name || license.issuedTo.email)),
|
|
551
|
+
h('div', { class: 'row' }, h('span', { class: 'label' }, 'Email'), h('span', { class: 'value soft' }, license.issuedTo.email)),
|
|
552
|
+
h('div', { class: 'row' }, h('span', { class: 'label' }, 'Plan'), h('span', { class: 'value' }, `${planName(license)} · ${license.expiresAt ? `until ${formatDate(license.expiresAt)}` : 'perpetual'}`)),
|
|
553
|
+
h(
|
|
554
|
+
'div',
|
|
555
|
+
{ class: 'row id' },
|
|
556
|
+
h('span', { class: 'label' }, 'License ID'),
|
|
557
|
+
h(
|
|
558
|
+
'span',
|
|
559
|
+
{ class: 'copy-group' },
|
|
560
|
+
h('span', { class: 'license-id' }, license.id),
|
|
561
|
+
h(
|
|
562
|
+
'button',
|
|
563
|
+
{
|
|
564
|
+
class: 'small-button',
|
|
565
|
+
type: 'button',
|
|
566
|
+
title: 'Copy license ID for support',
|
|
567
|
+
onClick: async () => {
|
|
568
|
+
await copyText(license.id)
|
|
569
|
+
idCopied = true
|
|
570
|
+
render()
|
|
571
|
+
setTimeout(() => {
|
|
572
|
+
idCopied = false
|
|
573
|
+
render()
|
|
574
|
+
}, 1800)
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
idCopied ? [icon(paths.check, { size: 14, stroke: '#34d27b', width: 2 }), 'Copied'] : [icon(paths.copy, { size: 14, width: 1.6 }), 'Copy'],
|
|
578
|
+
),
|
|
579
|
+
),
|
|
580
|
+
),
|
|
581
|
+
),
|
|
582
|
+
h(
|
|
583
|
+
'div',
|
|
584
|
+
{ class: 'card seats' },
|
|
585
|
+
h(
|
|
586
|
+
'div',
|
|
587
|
+
{},
|
|
588
|
+
h('div', { class: 'title' }, seatCount ? `Activations · ${used ?? '?'} of ${seatCount} ${seatCount === 1 ? 'device' : 'devices'}` : license.activationMethod === 'Offline' ? 'Activated offline on this device' : 'Activated on this device'),
|
|
589
|
+
pipCount > 0 && h('div', { class: 'pips' }, Array.from({ length: pipCount }, (_, index) => h('span', { class: `pip${index < (used ?? 0) ? ' used' : ''}` }))),
|
|
590
|
+
),
|
|
591
|
+
h(
|
|
592
|
+
'button',
|
|
593
|
+
{ class: 'danger-button', type: 'button', disabled: state.busy, onClick: () => run(() => invoke('deactivate')) },
|
|
594
|
+
state.busy ? [spinner(13), 'Deactivating…'] : license.trial || license.activationMethod === 'Offline' ? 'Remove from this device' : 'Deactivate this device',
|
|
595
|
+
),
|
|
596
|
+
),
|
|
597
|
+
errorLine(state.error?.message),
|
|
598
|
+
// Add-ons are activated and tried from a full license.
|
|
599
|
+
config.showAddOns &&
|
|
600
|
+
!license.trial &&
|
|
601
|
+
h(
|
|
602
|
+
'button',
|
|
603
|
+
{ class: 'card nav-card', type: 'button', onClick: () => go('addons') },
|
|
604
|
+
icon(paths.puzzle, { size: 20, stroke: 'var(--accent)', width: 1.7 }),
|
|
605
|
+
h(
|
|
606
|
+
'span',
|
|
607
|
+
{ class: 'grow' },
|
|
608
|
+
h('span', { class: 'title' }, 'Add-ons'),
|
|
609
|
+
h('span', { class: 'sub' }, state.activeSubProducts.length ? `${state.activeSubProducts.length} active on this computer` : 'See what you can add'),
|
|
610
|
+
),
|
|
611
|
+
icon(paths.chevron, { size: 18, stroke: '#768aa4', width: 2 }),
|
|
612
|
+
),
|
|
613
|
+
)
|
|
614
|
+
},
|
|
615
|
+
|
|
616
|
+
// The product's add-ons, each with where it stands on this computer and what
|
|
617
|
+
// the customer can do about it: try it, buy it, or activate it here.
|
|
618
|
+
addons: () => {
|
|
619
|
+
const license = state.license
|
|
620
|
+
if (!license) return screens[statusScreen()]()
|
|
621
|
+
const info = state.addOns
|
|
622
|
+
const loading = info.phase === 'loading'
|
|
623
|
+
const failed = !!info.error && info.addOns.length === 0
|
|
624
|
+
const rows = info.addOns.map((entry) => describeAddOn(entry, license))
|
|
625
|
+
let list
|
|
626
|
+
if (rows.length) list = rows.map(addOnRow)
|
|
627
|
+
else if (info.phase !== 'ready') list = [0, 1, 2].map(() => h('div', { class: 'card addon skeleton' }, h('div', { class: 'icon' }), h('div', { class: 'grow' }, h('span'), h('span'))))
|
|
628
|
+
else if (failed) list = errorLine(info.error)
|
|
629
|
+
else list = h('p', { class: 'empty' }, `There are no add-ons for ${product} yet.`)
|
|
630
|
+
// Under the list: why an activation or trial failed, or why a reload did while
|
|
631
|
+
// the earlier list stays up.
|
|
632
|
+
const message = info.actionError || (info.addOns.length ? info.error : null)
|
|
633
|
+
// Not while an add-on is being set up: its license is on its way.
|
|
634
|
+
const waiting = !!info.busyId
|
|
635
|
+
return h(
|
|
636
|
+
'div',
|
|
637
|
+
{},
|
|
638
|
+
backButton('License details', () => go('details')),
|
|
639
|
+
h('h1', {}, 'Add-ons'),
|
|
640
|
+
h('p', { style: 'margin-bottom:20px' }, `Everything you can add to ${product}.`),
|
|
641
|
+
h('div', { class: 'addon-list' }, list),
|
|
642
|
+
errorLine(message),
|
|
643
|
+
h(
|
|
644
|
+
'div',
|
|
645
|
+
{ class: 'links start' },
|
|
646
|
+
textButton(loading ? 'Checking…' : failed ? 'Try again' : 'Bought an add-on? Refresh', () => run(() => invoke(failed ? 'load_add_ons' : 'refresh_add_ons')), {
|
|
647
|
+
link: true,
|
|
648
|
+
disabled: loading || waiting,
|
|
649
|
+
}),
|
|
650
|
+
),
|
|
651
|
+
)
|
|
652
|
+
},
|
|
653
|
+
|
|
654
|
+
update: () => {
|
|
655
|
+
const back = () => (cameFromDetails ? go(null) : invoke('close_ui'))
|
|
656
|
+
if (!update) return h('div', { class: 'center' }, bigSpinner(true), h('p', {}, 'Fetching the release notes…'))
|
|
657
|
+
if (update.error || !update.available) {
|
|
658
|
+
return h(
|
|
659
|
+
'div',
|
|
660
|
+
{},
|
|
661
|
+
header(null),
|
|
662
|
+
h('h1', {}, `${product} is up to date`),
|
|
663
|
+
h('p', {}, update.error ? `Couldn't check for updates: ${update.error}` : `You're on the latest version.`),
|
|
664
|
+
h('div', { class: 'links' }, textButton('Back', back)),
|
|
665
|
+
)
|
|
666
|
+
}
|
|
667
|
+
const notes = update.releaseNotes
|
|
668
|
+
.split('\n')
|
|
669
|
+
.map((line) => line.replace(/^\s*[-*•]\s*/, '').trim())
|
|
670
|
+
.filter(Boolean)
|
|
671
|
+
const downloading = download.phase === 'downloading'
|
|
672
|
+
const percent = download.progress != null ? Math.round(download.progress * 100) : null
|
|
673
|
+
// Moonbase says the customer's licenses don't cover the new version, when the
|
|
674
|
+
// notes load or when the download is refused: offer the upgrade instead.
|
|
675
|
+
const notCovered = update.covered === false || download.phase === 'notCovered'
|
|
676
|
+
const access = download.releaseAccess || update.releaseAccess
|
|
677
|
+
const upgradeUrl = download.upgradeUrl || update.upgradeUrl
|
|
678
|
+
return h(
|
|
679
|
+
'div',
|
|
680
|
+
{},
|
|
681
|
+
h('div', { style: 'margin-bottom:24px' }, lockup()),
|
|
682
|
+
h('div', { style: 'margin-bottom:14px' }, h('span', { class: 'pill update' }, icon(paths.download, { size: 14, stroke: 'var(--accent)', width: 1.9 }), 'Update available')),
|
|
683
|
+
h('h1', {}, `${product} ${update.latestVersion} is ready`),
|
|
684
|
+
h(
|
|
685
|
+
'p',
|
|
686
|
+
{ style: 'margin-bottom:20px' },
|
|
687
|
+
"You're on ",
|
|
688
|
+
h('span', { class: 'mono em' }, update.currentVersion || 'an earlier version'),
|
|
689
|
+
'. The latest is ',
|
|
690
|
+
h('span', { class: 'mono', style: 'color:#82cef1' }, update.latestVersion),
|
|
691
|
+
notCovered
|
|
692
|
+
? ", which your license doesn't cover."
|
|
693
|
+
: !update.hasDownloads
|
|
694
|
+
? ', which has no download for this computer yet.'
|
|
695
|
+
: update.canDownload
|
|
696
|
+
? ', included in your license.'
|
|
697
|
+
: ", which your license doesn't include yet.",
|
|
698
|
+
),
|
|
699
|
+
notes.length > 0 &&
|
|
700
|
+
h(
|
|
701
|
+
'div',
|
|
702
|
+
{ class: 'card notes' },
|
|
703
|
+
h('div', { class: 'heading' }, "What's new"),
|
|
704
|
+
h('div', { class: 'items' }, notes.map((line) => h('div', { class: 'note' }, icon(paths.check, { stroke: 'var(--accent)', width: 2 }), h('span', {}, line)))),
|
|
705
|
+
),
|
|
706
|
+
downloading && h('div', { class: 'bar accent', style: 'margin:0 0 14px' }, h('div', { style: `width:${percent ?? 8}%` })),
|
|
707
|
+
download.phase === 'done'
|
|
708
|
+
? button('Show in folder', () => run(() => invoke('reveal_update')), { iconPath: paths.download })
|
|
709
|
+
: notCovered
|
|
710
|
+
? upgradeUrl && button(upgradeLabel(access), () => run(() => invoke('upgrade_license')), { iconPath: paths.external })
|
|
711
|
+
: update.canDownload
|
|
712
|
+
? button(downloading ? [spinner(), percent != null ? `Downloading… ${percent}%` : 'Downloading…'] : `Download ${update.latestVersion}`, () => run(() => invoke('download_update')), {
|
|
713
|
+
iconPath: downloading ? null : paths.download,
|
|
714
|
+
disabled: downloading,
|
|
715
|
+
})
|
|
716
|
+
: update.hasDownloads && button('Unlock full version', () => run(() => invoke('activate', { offline: false })), { iconPath: paths.lock }),
|
|
717
|
+
download.phase === 'done' && h('p', { style: 'margin-top:12px; text-align:center; font-size:12.5px' }, `Saved to ${download.path}`),
|
|
718
|
+
notCovered && h('p', { class: 'fine-print' }, [`Version ${update.latestVersion} needs an upgrade.`, releaseAccessText(access)].filter(Boolean).join(' ')),
|
|
719
|
+
errorLine(download.phase === 'failed' ? download.error : null),
|
|
720
|
+
h(
|
|
721
|
+
'div',
|
|
722
|
+
{ class: 'links' },
|
|
723
|
+
textButton('Remind me later', back),
|
|
724
|
+
textButton('Skip this version', async () => {
|
|
725
|
+
await run(() => invoke('skip_update', { version: update.latestVersion }))
|
|
726
|
+
back()
|
|
727
|
+
}),
|
|
728
|
+
),
|
|
729
|
+
)
|
|
730
|
+
},
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
function planName(license) {
|
|
734
|
+
if (license.trial) return `${license.product.name} trial`
|
|
735
|
+
if (license.activationMethod === 'Offline') return `${license.product.name} (offline)`
|
|
736
|
+
return license.product.name
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function features() {
|
|
740
|
+
if (!config.trialFeatures.length) return null
|
|
741
|
+
return h(
|
|
742
|
+
'div',
|
|
743
|
+
{ class: 'features' },
|
|
744
|
+
config.trialFeatures.map((feature) =>
|
|
745
|
+
h(
|
|
746
|
+
'div',
|
|
747
|
+
{ class: `feature${feature.included ? '' : ' excluded'}` },
|
|
748
|
+
icon(feature.included ? paths.check : paths.cross, { size: 17, stroke: feature.included ? '#34d27b' : '#5a6b82', width: 2 }),
|
|
749
|
+
h('span', {}, feature.label),
|
|
750
|
+
),
|
|
751
|
+
),
|
|
752
|
+
)
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// -- Add-ons --------------------------------------------------------------------
|
|
756
|
+
|
|
757
|
+
const cycleSuffix = { Daily: ' / day', Weekly: ' / week', Monthly: ' / month', Quarterly: ' / quarter', Yearly: ' / year' }
|
|
758
|
+
|
|
759
|
+
function formatAmount(amount, currency) {
|
|
760
|
+
const whole = Math.abs(amount - Math.round(amount)) < 0.005
|
|
761
|
+
try {
|
|
762
|
+
return new Intl.NumberFormat(undefined, { style: 'currency', currency, minimumFractionDigits: whole ? 0 : 2, maximumFractionDigits: whole ? 0 : 2 }).format(amount)
|
|
763
|
+
} catch {
|
|
764
|
+
return `${whole ? Math.round(amount) : amount.toFixed(2)} ${currency}`
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// What the add-on costs in the list's currency: its default price, or its first.
|
|
769
|
+
// Empty when it isn't for sale in that currency.
|
|
770
|
+
function priceText(entry, currency) {
|
|
771
|
+
const pricing = entry.product.defaultVariation || entry.product.variations?.[0]
|
|
772
|
+
const amount = currency && pricing?.price?.[currency]
|
|
773
|
+
if (amount == null) return ''
|
|
774
|
+
const recurring = pricing.recurrence?.type === 'Recurring'
|
|
775
|
+
return formatAmount(amount, currency) + (recurring ? cycleSuffix[pricing.recurrence.cycleLength] || '' : '')
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// The add-on as the license lists it, by its own part of its ID or its whole ID.
|
|
779
|
+
function findSubProduct(license, id) {
|
|
780
|
+
const prefix = `${license.product.id}.`
|
|
781
|
+
const own = id.startsWith(prefix) && id.length > prefix.length ? id.slice(prefix.length) : id
|
|
782
|
+
return (license.subProducts || []).find((entry) => entry.id === own) || null
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// One add-on as its row shows it: where it stands here, and what to do about it.
|
|
786
|
+
function describeAddOn(entry, license) {
|
|
787
|
+
const price = priceText(entry, state.addOns.currency)
|
|
788
|
+
const owns = entry.product.owned || entry.product.subscribed
|
|
789
|
+
const forSale = !!entry.buyUrl
|
|
790
|
+
const row = { id: entry.id, name: entry.product.name, status: '', tone: 'muted', primary: null, secondary: null }
|
|
791
|
+
|
|
792
|
+
// The list says where each add-on stood when it was loaded. For one the
|
|
793
|
+
// license lists, the license says where it stands on this computer now (on a
|
|
794
|
+
// seat or a trial, revoked here, until when), and keeps saying it as time
|
|
795
|
+
// passes and the license is refreshed: a trial that runs out with the screen
|
|
796
|
+
// open shows as ended, and a seat revoked here since shows as revoked.
|
|
797
|
+
const held = findSubProduct(license, entry.id)
|
|
798
|
+
const active = entry.includedInLicense ? state.activeSubProducts.includes(entry.id) : entry.active
|
|
799
|
+
const wasActive = held ? held.active : entry.active
|
|
800
|
+
const revoked = held ? held.revoked : entry.revoked
|
|
801
|
+
const ends = held ? held.expiresAt : entry.expiresAt || entry.trial?.expiresAt || null
|
|
802
|
+
const lapsed = wasActive && !active && ends && daysUntil(ends) === 0
|
|
803
|
+
// Whether a trial rather than a seat unlocks it here. A customer who buys an
|
|
804
|
+
// add-on during its trial keeps the trial until a seat replaces it.
|
|
805
|
+
// Moonbase names the statuses Available, Active, Expired and Unavailable.
|
|
806
|
+
const trialStatus = (entry.trial?.status || 'unavailable').toLowerCase()
|
|
807
|
+
const onTrial = held ? held.trial : trialStatus === 'active'
|
|
808
|
+
let trial = trialStatus
|
|
809
|
+
if (held?.trial) trial = active ? 'active' : 'expired'
|
|
810
|
+
else if (trial === 'active' && lapsed) trial = 'expired'
|
|
811
|
+
|
|
812
|
+
if (active && owns && !onTrial) {
|
|
813
|
+
row.status = entry.includedInLicense ? 'Active on this computer' : entry.product.subscribed ? 'Subscribed' : 'Owned'
|
|
814
|
+
row.tone = 'success'
|
|
815
|
+
} else if (active) {
|
|
816
|
+
const days = ends ? daysUntil(ends) : null
|
|
817
|
+
row.status = join('Trial', days == null ? '' : days === 1 ? '1 day left' : `${days} days left`)
|
|
818
|
+
row.tone = 'trial'
|
|
819
|
+
// Bought during the trial: a seat of it is theirs to take.
|
|
820
|
+
if (owns && entry.includedInLicense) row.primary = 'activate'
|
|
821
|
+
else if (forSale) row.primary = 'buy'
|
|
822
|
+
} else if (lapsed && owns && !onTrial) {
|
|
823
|
+
// Owned until now: a subscription to it that ended.
|
|
824
|
+
row.status = join('Expired', price)
|
|
825
|
+
if (forSale) row.primary = 'buy'
|
|
826
|
+
} else if (entry.includedInLicense && owns) {
|
|
827
|
+
// Owned, but this computer holds no seat of it. Its seats are in use only when
|
|
828
|
+
// neither the list nor the license knows of one free: either can be the older.
|
|
829
|
+
const listKnows = !!entry.seats
|
|
830
|
+
const licenseKnows = !!held?.seats
|
|
831
|
+
const seatsInUse = (listKnows || licenseKnows) && (!listKnows || entry.seats.remaining <= 0) && (!licenseKnows || held.seats.remaining <= 0)
|
|
832
|
+
if (revoked) {
|
|
833
|
+
row.status = 'Deactivated on this computer'
|
|
834
|
+
row.primary = 'activate'
|
|
835
|
+
} else if (seatsInUse) {
|
|
836
|
+
const total = listKnows ? entry.seats.total : held.seats.total
|
|
837
|
+
row.status = total === 1 ? 'Its seat is in use on another computer' : `All ${total} seats are in use`
|
|
838
|
+
} else {
|
|
839
|
+
row.status = 'Not activated on this computer'
|
|
840
|
+
row.primary = 'activate'
|
|
841
|
+
}
|
|
842
|
+
} else if (trial === 'available') {
|
|
843
|
+
const days = entry.trial.numberOfDays
|
|
844
|
+
row.status = join(days ? `${days}-day free trial` : 'Free trial', price)
|
|
845
|
+
row.primary = 'tryIt'
|
|
846
|
+
if (forSale) row.secondary = 'buy'
|
|
847
|
+
} else if (trial === 'expired') {
|
|
848
|
+
row.status = join('Trial ended', price)
|
|
849
|
+
if (forSale) row.primary = 'buy'
|
|
850
|
+
} else if (trial === 'unavailable' && entry.trial?.requiresNewsletterOptIn) {
|
|
851
|
+
// Its trial is for newsletter subscribers, which the customer isn't yet.
|
|
852
|
+
row.status = join('Join the newsletter to try it free', price)
|
|
853
|
+
if (forSale) row.primary = 'buy'
|
|
854
|
+
} else {
|
|
855
|
+
row.status = join(price, entry.product.tagline || '')
|
|
856
|
+
if (forSale) row.primary = 'buy'
|
|
857
|
+
}
|
|
858
|
+
return row
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const addOnActions = {
|
|
862
|
+
tryIt: { label: 'Try free', command: 'request_sub_product_trial' },
|
|
863
|
+
activate: { label: 'Activate', command: 'activate_sub_product' },
|
|
864
|
+
buy: { label: 'Buy', command: 'buy_sub_product' },
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function addOnRow(row) {
|
|
868
|
+
// While an add-on is being activated or tried its button spins, and the rest
|
|
869
|
+
// wait their turn, as they do while the list is reloading.
|
|
870
|
+
const busyId = state.addOns.busyId
|
|
871
|
+
const anyBusy = !!busyId || state.addOns.phase === 'loading'
|
|
872
|
+
const action = (kind, primary) => {
|
|
873
|
+
const spins = primary && busyId === row.id
|
|
874
|
+
return h(
|
|
875
|
+
'button',
|
|
876
|
+
{ class: `btn small ${primary ? 'primary' : 'ghost'}`, type: 'button', disabled: anyBusy, onClick: () => run(() => invoke(addOnActions[kind].command, { id: row.id })) },
|
|
877
|
+
spins ? spinner(14) : addOnActions[kind].label,
|
|
878
|
+
)
|
|
879
|
+
}
|
|
880
|
+
return h(
|
|
881
|
+
'div',
|
|
882
|
+
{ class: `card addon ${row.tone}` },
|
|
883
|
+
h('div', { class: 'icon' }, icon(row.tone === 'success' ? paths.check : paths.sparkles, { size: 20, width: 1.7 })),
|
|
884
|
+
h('div', { class: 'grow' }, h('div', { class: 'name' }, row.name), row.status && h('div', { class: 'status' }, row.status)),
|
|
885
|
+
(row.primary || row.secondary) && h('div', { class: 'actions' }, row.secondary && action(row.secondary, false), row.primary && action(row.primary, true)),
|
|
886
|
+
)
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function openUpdate(fromDetails) {
|
|
890
|
+
cameFromDetails = fromDetails
|
|
891
|
+
go('update')
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
async function saveRequest() {
|
|
895
|
+
offline.error = ''
|
|
896
|
+
try {
|
|
897
|
+
const saved = await invoke('save_machine_file')
|
|
898
|
+
if (saved) offline.saved = saved
|
|
899
|
+
} catch (error) {
|
|
900
|
+
offline.error = error?.message ?? String(error)
|
|
901
|
+
}
|
|
902
|
+
render()
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
function pickFile(file) {
|
|
906
|
+
if (!file) return
|
|
907
|
+
const reader = new FileReader()
|
|
908
|
+
reader.onload = () => {
|
|
909
|
+
offline.file = { name: file.name, text: String(reader.result) }
|
|
910
|
+
offline.error = ''
|
|
911
|
+
render()
|
|
912
|
+
}
|
|
913
|
+
reader.onerror = () => {
|
|
914
|
+
offline.error = "Couldn't read that file."
|
|
915
|
+
render()
|
|
916
|
+
}
|
|
917
|
+
reader.readAsText(file)
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
async function activateOffline() {
|
|
921
|
+
if (offline.busy) return
|
|
922
|
+
if (!offline.file) {
|
|
923
|
+
offline.error = `Add the license file from ${config.activationHost} to continue.`
|
|
924
|
+
render()
|
|
925
|
+
return
|
|
926
|
+
}
|
|
927
|
+
offline.busy = true
|
|
928
|
+
offline.error = ''
|
|
929
|
+
render()
|
|
930
|
+
try {
|
|
931
|
+
await invoke('activate_offline', { licenseFile: offline.file.text })
|
|
932
|
+
offline.file = null
|
|
933
|
+
offline.saved = null
|
|
934
|
+
view = 'success'
|
|
935
|
+
} catch {
|
|
936
|
+
offline.error = state?.error?.message || "That license file isn't valid for this device."
|
|
937
|
+
}
|
|
938
|
+
offline.busy = false
|
|
939
|
+
render()
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// -- Structure, rendering and sizing ---------------------------------------------
|
|
943
|
+
|
|
944
|
+
const screenEl = h('div')
|
|
945
|
+
const closeButton = overlay ? h('button', { class: 'mb-close', type: 'button', 'aria-label': 'Close', onClick: () => invoke('close_ui') }, icon(paths.cross, { size: 18, width: 1.8 })) : null
|
|
946
|
+
// The Moonbase brand mark, verbatim from the marketing site's
|
|
947
|
+
// images/logos/moonbase.svg (as in moonbase-cpp's JUCE module), in one colour.
|
|
948
|
+
const moonbaseMark = svg(
|
|
949
|
+
'<svg width="14" height="14" viewBox="0 0 512 512" fill="currentColor" aria-hidden="true"><path d="m493.17795,174.6135c6.257,75.3 -30.577,150.948 -100.579,190.758c-66.292,37.697 -145.001,33.405 -205.402,-4.415c0.409,-1.248 0.638,-2.577 0.638,-3.96c0,-7.026 -5.717,-12.743 -12.743,-12.743c-2.876,0 -5.524,0.969 -7.659,2.582c-18.813,-15.259 -35.159,-34.207 -47.856,-56.534c-54.663,-96.122 -21.054,-218.358 75.069,-273.021a201.218,201.218 0 0 1 33.302,-15.124c-32.428,3.667 -64.663,13.809 -94.827,30.962c-104.526,59.443 -149.511,183.241 -113.473,293.249c-3.376,3.057 -5.513,7.459 -5.513,12.362c0,9.207 7.491,16.698 16.698,16.698c0.136,0 0.267,-0.017 0.401,-0.02a252.205,252.205 0 0 0 8.683,16.691c67.869,119.344 219.635,161.073 338.98,93.204a250.416,250.416 0 0 0 32.893,-22.333c1.045,0.331 2.157,0.513 3.311,0.513c6.047,0 10.968,-4.921 10.968,-10.968c0,-0.605 -0.063,-1.196 -0.157,-1.775c69.545,-64.988 96.008,-165.054 67.266,-256.126m-446.526,25.112a5.071,5.071 0 0 1 -5.066,-5.066a5.072,5.072 0 0 1 5.066,-5.067a5.073,5.073 0 0 1 5.066,5.067a5.072,5.072 0 0 1 -5.066,5.066m-15.819,153.944c-8.238,0 -14.94,-6.702 -14.94,-14.94c0,-8.239 6.702,-14.941 14.94,-14.941c8.239,0 14.941,6.702 14.941,14.941c-0.001,8.238 -6.703,14.94 -14.941,14.94m144.258,-7.659c6.057,0 10.985,4.928 10.985,10.986c0,6.058 -4.928,10.985 -10.985,10.985c-6.058,0 -10.986,-4.928 -10.986,-10.985c0.001,-6.059 4.928,-10.986 10.986,-10.986m70.829,133.004c-5.079,0 -9.21,-4.132 -9.21,-9.21c0,-5.079 4.131,-9.21 9.21,-9.21c5.078,0 9.209,4.131 9.209,9.21c0,5.078 -4.13,9.21 -9.209,9.21m169.18,-37.289c-5.078,0 -9.209,-4.132 -9.209,-9.21s4.131,-9.209 9.209,-9.209s9.21,4.131 9.21,9.209s-4.132,9.21 -9.21,9.21"></path><path d="m144.78195,275.9675c46.746,82.201 151.278,110.943 233.48,64.197c59.864,-34.044 91.363,-98.736 86.013,-163.13a170.094,170.094 0 0 0 -5.515,-31.052c-23.045,0.567 -63.864,10.137 -104.194,61.671c-52.045,66.5 -186.285,49.153 -228.855,17.372c3.503,17.443 9.796,34.632 19.071,50.942m233.513,-65.677a8.663,8.663 0 1 1 -8.663,8.663a8.662,8.662 0 0 1 8.663,-8.663m-37.006,62.618c7.02,0 12.712,5.691 12.712,12.712s-5.692,12.712 -12.712,12.712c-7.021,0 -12.712,-5.691 -12.712,-12.712s5.691,-12.712 12.712,-12.712m-102.544,12.712a6.78,6.78 0 1 1 0,13.56a6.78,6.78 0 0 1 0,-13.56"></path><ellipse cx="251.33138" cy="152.05851" rx="7.3075" ry="7.3075"></ellipse><ellipse cx="204.89499" cy="210.31151" rx="5.35076" ry="5.35076"></ellipse><ellipse cx="302.28597" cy="200.15625" rx="12.09273" ry="12.09273"></ellipse></svg>',
|
|
950
|
+
)
|
|
951
|
+
const badge =
|
|
952
|
+
config.showBadge &&
|
|
953
|
+
h(
|
|
954
|
+
'footer',
|
|
955
|
+
{ class: 'badge' },
|
|
956
|
+
icon(paths.lock, { size: 14, width: 1.5 }),
|
|
957
|
+
h('span', {}, 'Licensing secured by'),
|
|
958
|
+
h('button', { class: 'moonbase-link', type: 'button', onClick: () => invoke('open_link', { url: MOONBASE_SITE }).catch(() => {}) }, h('span', { class: 'moon' }, moonbaseMark), h('span', { class: 'wordmark' }, 'moonbase')),
|
|
959
|
+
)
|
|
960
|
+
const panel = h('main', { class: 'panel' }, closeButton, screenEl, badge)
|
|
961
|
+
|
|
962
|
+
root.classList.add('mb-root')
|
|
963
|
+
if (overlay) root.classList.add('mb-overlay-root')
|
|
964
|
+
if (!overlay && config.os === 'macos') root.classList.add('mac')
|
|
965
|
+
if (config.reduceMotion) root.classList.add('reduce-motion')
|
|
966
|
+
root.style.setProperty('--accent', config.accent)
|
|
967
|
+
root.replaceChildren(panel)
|
|
968
|
+
|
|
969
|
+
let lastScreen = null
|
|
970
|
+
let reportedHeight = 0
|
|
971
|
+
|
|
972
|
+
// Closing is always possible in a window, which never locks the app. An overlay
|
|
973
|
+
// stays up while there is no license: that is the lock.
|
|
974
|
+
function canClose() {
|
|
975
|
+
if (!state || state.status === 'activating' || state.status === 'loading') return false
|
|
976
|
+
return !overlay || state.licensed
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function render() {
|
|
980
|
+
if (!state) return
|
|
981
|
+
const name = screenName()
|
|
982
|
+
const node = (screens[name] || screens.loading)()
|
|
983
|
+
// Animate only real screen changes, not every state push.
|
|
984
|
+
const wrapper = h('div', { class: name === lastScreen ? '' : 'screen' }, node)
|
|
985
|
+
screenEl.replaceChildren(wrapper)
|
|
986
|
+
lastScreen = name
|
|
987
|
+
if (closeButton) closeButton.hidden = !canClose()
|
|
988
|
+
// Measured straight away rather than on the next frame: WebKit pauses frames
|
|
989
|
+
// for a window that is covered, and the window should fit its screen anyway.
|
|
990
|
+
reportHeight()
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function reportHeight() {
|
|
994
|
+
if (!onHeight) return
|
|
995
|
+
const height = Math.ceil(panel.getBoundingClientRect().height)
|
|
996
|
+
if (height === reportedHeight) return
|
|
997
|
+
reportedHeight = height
|
|
998
|
+
onHeight(height)
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
function show(screen) {
|
|
1002
|
+
if (screen === 'update') return openUpdate(false)
|
|
1003
|
+
if (screen === 'license') screen = 'details'
|
|
1004
|
+
view = screen === 'welcome' || !screen ? null : screen
|
|
1005
|
+
if ((view === 'details' || view === 'addons') && !state?.license) view = null
|
|
1006
|
+
if (view === 'addons') loadAddOns()
|
|
1007
|
+
render()
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
function onState(next) {
|
|
1011
|
+
const previous = state
|
|
1012
|
+
state = next
|
|
1013
|
+
// A completed activation gets its own moment. Cancelling one while a trial runs
|
|
1014
|
+
// also leaves a license, but the same one, so compare activations.
|
|
1015
|
+
const activated = previous?.status === 'activating' && !next.activation && next.license && next.license.activationId !== previous.license?.activationId
|
|
1016
|
+
if (activated) view = 'success'
|
|
1017
|
+
// Screens about a license make no sense without one.
|
|
1018
|
+
if (['details', 'addons', 'update'].includes(view) && !next.license) view = null
|
|
1019
|
+
// Activating supersedes whatever the user was looking at, and so does a license
|
|
1020
|
+
// turning out not to cover this version.
|
|
1021
|
+
if (next.status === 'activating') view = null
|
|
1022
|
+
if (next.status === 'notCovered' && previous?.status !== 'notCovered') view = null
|
|
1023
|
+
if (view === 'success' && !next.license) view = null
|
|
1024
|
+
// The add-ons were listed for a license that has since been replaced.
|
|
1025
|
+
if (view === 'addons' && next.license && next.addOns.phase === 'idle' && previous?.addOns?.phase !== 'idle') loadAddOns()
|
|
1026
|
+
render()
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// Start with the state handed over, or ask for it.
|
|
1030
|
+
async function start(initial, screen) {
|
|
1031
|
+
try {
|
|
1032
|
+
device = await invoke('device')
|
|
1033
|
+
} catch {
|
|
1034
|
+
device = null
|
|
1035
|
+
}
|
|
1036
|
+
onState(initial || (await invoke('state')))
|
|
1037
|
+
if (screen) show(screen)
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
return {
|
|
1041
|
+
update: onState,
|
|
1042
|
+
show,
|
|
1043
|
+
start,
|
|
1044
|
+
canClose,
|
|
1045
|
+
focus() {
|
|
1046
|
+
panel.querySelector('button, [href], input, label')?.focus({ preventScroll: true })
|
|
1047
|
+
},
|
|
1048
|
+
download(next) {
|
|
1049
|
+
download = next
|
|
1050
|
+
render()
|
|
1051
|
+
},
|
|
1052
|
+
}
|
|
1053
|
+
}
|