@meacore/tauri-easy-updater 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1349 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/react/index.ts
31
+ var react_exports = {};
32
+ __export(react_exports, {
33
+ EN_LABELS: () => EN_LABELS,
34
+ ES_LABELS: () => ES_LABELS,
35
+ UpdateBanner: () => UpdateBanner,
36
+ UpdateModal: () => UpdateModal,
37
+ formatBytes: () => formatBytes,
38
+ formatTemplate: () => formatTemplate,
39
+ resolveLabels: () => resolveLabels,
40
+ resolveTheme: () => resolveTheme,
41
+ useUpdateChecker: () => useUpdateChecker,
42
+ useUpdater: () => useUpdater
43
+ });
44
+ module.exports = __toCommonJS(react_exports);
45
+
46
+ // src/react/useUpdater.ts
47
+ var import_react = require("react");
48
+
49
+ // src/types.ts
50
+ var UpdaterError = class _UpdaterError extends Error {
51
+ constructor(code, message) {
52
+ super(message);
53
+ this.name = "UpdaterError";
54
+ this.code = code;
55
+ }
56
+ static fromUnknown(err) {
57
+ if (err instanceof _UpdaterError) {
58
+ return err;
59
+ }
60
+ if (err && typeof err === "object") {
61
+ const obj = err;
62
+ if (typeof obj.code === "string" && typeof obj.message === "string") {
63
+ return new _UpdaterError(obj.code, obj.message);
64
+ }
65
+ if (err instanceof Error) {
66
+ return new _UpdaterError("UNKNOWN_ERROR", err.message);
67
+ }
68
+ }
69
+ if (typeof err === "string") {
70
+ return new _UpdaterError("UNKNOWN_ERROR", err);
71
+ }
72
+ return new _UpdaterError("UNKNOWN_ERROR", "An unexpected updater error occurred");
73
+ }
74
+ };
75
+
76
+ // src/utils/platform.ts
77
+ function isTauriRuntime() {
78
+ if (typeof window === "undefined") return false;
79
+ return "__TAURI_INTERNALS__" in window || "__TAURI__" in window;
80
+ }
81
+ function inferInstallerFormat(urlOrFilename) {
82
+ const clean = urlOrFilename.split("?")[0]?.toLowerCase() ?? "";
83
+ if (clean.endsWith(".exe")) return "nsis";
84
+ if (clean.endsWith(".msi")) return "msi";
85
+ if (clean.endsWith(".dmg")) return "dmg";
86
+ if (clean.endsWith(".pkg")) return "pkg";
87
+ if (clean.endsWith(".appimage")) return "appimage";
88
+ if (clean.endsWith(".deb")) return "deb";
89
+ if (clean.endsWith(".rpm")) return "rpm";
90
+ return null;
91
+ }
92
+ async function getPlatformSummary() {
93
+ if (typeof window === "undefined") {
94
+ return null;
95
+ }
96
+ if (isTauriRuntime()) {
97
+ try {
98
+ const { invoke } = await import("@tauri-apps/api/core");
99
+ return await invoke("plugin:easy-updater|get_platform");
100
+ } catch {
101
+ }
102
+ }
103
+ const ua = typeof navigator !== "undefined" ? navigator.userAgent : "";
104
+ const platform = typeof navigator !== "undefined" ? navigator.platform : "";
105
+ const combined = `${platform} ${ua}`.toLowerCase();
106
+ let os = "";
107
+ if (combined.includes("win")) os = "windows";
108
+ else if (combined.includes("mac") || combined.includes("darwin")) os = "darwin";
109
+ else if (combined.includes("linux")) os = "linux";
110
+ if (!os) return null;
111
+ const isArm = combined.includes("arm64") || combined.includes("aarch64");
112
+ const arch = isArm ? "aarch64" : "x86_64";
113
+ const supportedFormats = os === "windows" ? ["nsis", "msi"] : os === "darwin" ? ["dmg", "pkg"] : ["appimage", "deb", "rpm"];
114
+ return {
115
+ os,
116
+ arch,
117
+ key: `${os}-${arch}`,
118
+ supportedFormats
119
+ };
120
+ }
121
+ async function getCurrentPlatform() {
122
+ const summary = await getPlatformSummary();
123
+ return summary?.key ?? "";
124
+ }
125
+ function selectPlatformFromManifest(manifest, platformKey) {
126
+ if (!platformKey) return null;
127
+ const direct = manifest.platforms[platformKey];
128
+ if (direct) {
129
+ return { key: platformKey, entry: direct };
130
+ }
131
+ if (platformKey.startsWith("darwin-") && manifest.platforms["darwin-universal"]) {
132
+ return { key: "darwin-universal", entry: manifest.platforms["darwin-universal"] };
133
+ }
134
+ return null;
135
+ }
136
+ function resolveArtifactsFromPlatform(entry, preferredFormat) {
137
+ const defaultPrimary = {
138
+ format: entry.format ?? inferInstallerFormat(entry.url),
139
+ url: entry.url,
140
+ sha256: entry.sha256 ?? null,
141
+ size: entry.size ?? null,
142
+ signature: entry.signature ?? null
143
+ };
144
+ const all = (entry.artifacts ?? []).map((a) => ({
145
+ format: a.format,
146
+ url: a.url,
147
+ sha256: a.sha256 ?? null,
148
+ size: a.size ?? null,
149
+ signature: a.signature ?? null
150
+ }));
151
+ if (all.length === 0) {
152
+ all.push(defaultPrimary);
153
+ } else if (!all.some((a) => a.url === defaultPrimary.url)) {
154
+ all.unshift(defaultPrimary);
155
+ }
156
+ const primary = preferredFormat ? all.find((a) => a.format === preferredFormat) ?? defaultPrimary : defaultPrimary;
157
+ return { primary, all };
158
+ }
159
+
160
+ // src/utils/security.ts
161
+ var FORBIDDEN_URL_SYMBOLS = /[\s&|^<>;"'`\\$(){}!]/;
162
+ function hasForbiddenUrlChars(rawUrl) {
163
+ if (FORBIDDEN_URL_SYMBOLS.test(rawUrl)) return true;
164
+ for (let i = 0; i < rawUrl.length; i += 1) {
165
+ const code = rawUrl.charCodeAt(i);
166
+ if (code <= 31 || code === 127) return true;
167
+ }
168
+ return false;
169
+ }
170
+ function isSafeRemoteUrl(rawUrl, allowInsecureHttp = false) {
171
+ if (typeof rawUrl !== "string" || rawUrl.length === 0) return false;
172
+ if (rawUrl.startsWith("-")) return false;
173
+ if (hasForbiddenUrlChars(rawUrl)) return false;
174
+ try {
175
+ const parsed = new URL(rawUrl);
176
+ const schemeAllowed = parsed.protocol === "https:" || allowInsecureHttp && parsed.protocol === "http:";
177
+ if (!schemeAllowed) return false;
178
+ if (parsed.username || parsed.password) return false;
179
+ if (!parsed.hostname) return false;
180
+ return true;
181
+ } catch {
182
+ return false;
183
+ }
184
+ }
185
+ function assertSafeRemoteUrl(rawUrl, allowInsecureHttp = false) {
186
+ if (!isSafeRemoteUrl(rawUrl, allowInsecureHttp)) {
187
+ throw new UpdaterError(
188
+ rawUrl.startsWith("http://") ? "INSECURE_SCHEME" : "INVALID_URL",
189
+ `Blocked unsafe or non-HTTPS URL: ${rawUrl.slice(0, 120)}`
190
+ );
191
+ }
192
+ return rawUrl;
193
+ }
194
+
195
+ // src/utils/semver.ts
196
+ var STRICT_SEMVER_RE = /^[vV]?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
197
+ var NUMERIC_IDENT_RE = /^(0|[1-9]\d*)$/;
198
+ function parseSemver(input) {
199
+ if (typeof input !== "string") return null;
200
+ const trimmed = input.trim();
201
+ const match = STRICT_SEMVER_RE.exec(trimmed);
202
+ if (!match) return null;
203
+ const major = Number(match[1]);
204
+ const minor = Number(match[2]);
205
+ const patch = Number(match[3]);
206
+ if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) {
207
+ return null;
208
+ }
209
+ const prerelease = match[4] ? match[4].split(".") : [];
210
+ const build = match[5] ?? null;
211
+ return { major, minor, patch, prerelease, build };
212
+ }
213
+ function comparePrerelease(a, b) {
214
+ const aEmpty = a.length === 0;
215
+ const bEmpty = b.length === 0;
216
+ if (aEmpty && bEmpty) return 0;
217
+ if (aEmpty) return 1;
218
+ if (bEmpty) return -1;
219
+ const len = Math.max(a.length, b.length);
220
+ for (let i = 0; i < len; i += 1) {
221
+ const ai = a[i];
222
+ const bi = b[i];
223
+ if (ai === void 0) return -1;
224
+ if (bi === void 0) return 1;
225
+ if (ai === bi) continue;
226
+ const aNum = NUMERIC_IDENT_RE.test(ai);
227
+ const bNum = NUMERIC_IDENT_RE.test(bi);
228
+ if (aNum && bNum) {
229
+ const av = BigInt(ai);
230
+ const bv = BigInt(bi);
231
+ if (av > bv) return 1;
232
+ if (av < bv) return -1;
233
+ } else if (aNum && !bNum) {
234
+ return -1;
235
+ } else if (!aNum && bNum) {
236
+ return 1;
237
+ } else {
238
+ return ai > bi ? 1 : -1;
239
+ }
240
+ }
241
+ return 0;
242
+ }
243
+ function compareSemver(a, b) {
244
+ const pa = parseSemver(a);
245
+ const pb = parseSemver(b);
246
+ if (!pa || !pb) return null;
247
+ if (pa.major !== pb.major) return pa.major > pb.major ? 1 : -1;
248
+ if (pa.minor !== pb.minor) return pa.minor > pb.minor ? 1 : -1;
249
+ if (pa.patch !== pb.patch) return pa.patch > pb.patch ? 1 : -1;
250
+ const pre = comparePrerelease(pa.prerelease, pb.prerelease);
251
+ if (pre > 0) return 1;
252
+ if (pre < 0) return -1;
253
+ return 0;
254
+ }
255
+ function isNewerVersion(latest, current) {
256
+ return compareSemver(latest, current) === 1;
257
+ }
258
+ function isBelowMinVersion(current, minVersion) {
259
+ return compareSemver(current, minVersion) === -1;
260
+ }
261
+
262
+ // src/client.ts
263
+ var SESSION_DISMISS_KEY = "tauri-easy-updater:dismissed-version";
264
+ var PROGRESS_EVENT_NAME = "easy-updater://download-progress";
265
+ function defaultStorage() {
266
+ if (typeof window === "undefined") return null;
267
+ try {
268
+ return window.sessionStorage;
269
+ } catch {
270
+ return null;
271
+ }
272
+ }
273
+ var UpdaterClient = class {
274
+ constructor(config = {}) {
275
+ this.listeners = /* @__PURE__ */ new Set();
276
+ this.state = {
277
+ status: "idle",
278
+ updateInfo: null,
279
+ progress: null,
280
+ downloadResult: null,
281
+ error: null,
282
+ isDismissed: false,
283
+ lastCheckedAt: null
284
+ };
285
+ this.inFlightCheck = null;
286
+ this.activeDownloadId = null;
287
+ this.pollTimer = null;
288
+ this.unlistenProgress = null;
289
+ this.disposed = false;
290
+ this.config = config;
291
+ this.storage = config.storage ?? defaultStorage();
292
+ }
293
+ /** Returns the current immutable state snapshot. */
294
+ getState() {
295
+ return this.state;
296
+ }
297
+ /** Subscribes to state transitions. Returns an unsubscribe function. */
298
+ subscribe(listener) {
299
+ this.listeners.add(listener);
300
+ return () => {
301
+ this.listeners.delete(listener);
302
+ };
303
+ }
304
+ /** Starts periodic update checks (`intervalMs > 0`). */
305
+ startPolling(intervalMs) {
306
+ this.stopPolling();
307
+ if (intervalMs <= 0 || this.disposed) return;
308
+ this.pollTimer = setInterval(() => {
309
+ void this.check();
310
+ }, intervalMs);
311
+ }
312
+ /** Stops periodic update checks. */
313
+ stopPolling() {
314
+ if (this.pollTimer !== null) {
315
+ clearInterval(this.pollTimer);
316
+ this.pollTimer = null;
317
+ }
318
+ }
319
+ /** Releases timers and Tauri event listeners. */
320
+ dispose() {
321
+ this.disposed = true;
322
+ this.stopPolling();
323
+ this.detachProgressListener();
324
+ this.listeners.clear();
325
+ }
326
+ /**
327
+ * Checks for an available update. Concurrent calls share the same in-flight promise.
328
+ */
329
+ async check() {
330
+ if (this.disposed) return null;
331
+ if (this.inFlightCheck) {
332
+ return this.inFlightCheck;
333
+ }
334
+ const promise = this.performCheck().finally(() => {
335
+ this.inFlightCheck = null;
336
+ });
337
+ this.inFlightCheck = promise;
338
+ return promise;
339
+ }
340
+ async performCheck() {
341
+ this.setState({
342
+ status: "checking",
343
+ error: null
344
+ });
345
+ try {
346
+ const info = await this.fetchUpdateInfo();
347
+ if (this.disposed) return null;
348
+ const dismissedVersion = this.readDismissedVersion();
349
+ const isDismissed = !info.mandatory && Boolean(dismissedVersion) && dismissedVersion === info.latestVersion;
350
+ this.setState({
351
+ status: info.hasUpdate ? "available" : "up-to-date",
352
+ updateInfo: info,
353
+ isDismissed,
354
+ error: null,
355
+ lastCheckedAt: Date.now()
356
+ });
357
+ return info;
358
+ } catch (rawErr) {
359
+ if (this.disposed) return null;
360
+ const err = UpdaterError.fromUnknown(rawErr);
361
+ if (this.config.silent) {
362
+ this.setState({
363
+ status: this.state.updateInfo?.hasUpdate ? "available" : "idle",
364
+ error: null
365
+ });
366
+ } else {
367
+ this.setState({
368
+ status: "error",
369
+ error: err
370
+ });
371
+ }
372
+ return null;
373
+ }
374
+ }
375
+ async fetchUpdateInfo() {
376
+ const provider = this.config.provider;
377
+ const useTauriPlugin = isTauriRuntime() && (!provider || Boolean(provider.tauriParams));
378
+ if (useTauriPlugin) {
379
+ const { invoke } = await import("@tauri-apps/api/core");
380
+ const params = {
381
+ ...provider?.tauriParams ?? {}
382
+ };
383
+ if (this.config.currentVersion) {
384
+ params.currentVersion = this.config.currentVersion;
385
+ }
386
+ if (this.config.channel) {
387
+ params.channel = this.config.channel;
388
+ }
389
+ if (this.config.preferredFormat) {
390
+ params.preferredFormat = this.config.preferredFormat;
391
+ }
392
+ return await invoke("plugin:easy-updater|check_update", { params });
393
+ }
394
+ if (!provider) {
395
+ throw new UpdaterError(
396
+ "INVALID_INPUT",
397
+ "A provider is required when running outside a Tauri v2 runtime"
398
+ );
399
+ }
400
+ if (!this.config.currentVersion) {
401
+ throw new UpdaterError(
402
+ "INVALID_INPUT",
403
+ "currentVersion is required when using pure JS fallback outside Tauri"
404
+ );
405
+ }
406
+ const manifest = await provider.fetchManifest();
407
+ const currentVersion = this.config.currentVersion;
408
+ const cmp = compareSemver(manifest.version, currentVersion);
409
+ if (cmp === null) {
410
+ throw new UpdaterError(
411
+ "INVALID_VERSION",
412
+ `Unable to compare versions "${manifest.version}" and "${currentVersion}"`
413
+ );
414
+ }
415
+ if (cmp < 0) {
416
+ throw new UpdaterError(
417
+ "DOWNGRADE_BLOCKED",
418
+ `Downgrade blocked: target ${manifest.version} is older than ${currentVersion}`
419
+ );
420
+ }
421
+ const hasUpdate = isNewerVersion(manifest.version, currentVersion);
422
+ const belowMin = manifest.min_version ? isBelowMinVersion(currentVersion, manifest.min_version) : false;
423
+ const mandatory = hasUpdate && (Boolean(manifest.mandatory) || belowMin);
424
+ const platformKey = await getCurrentPlatform();
425
+ const matched = selectPlatformFromManifest(manifest, platformKey);
426
+ if (!matched) {
427
+ if (hasUpdate) {
428
+ throw new UpdaterError(
429
+ "PLATFORM_NOT_FOUND",
430
+ `No update artifact available for platform "${platformKey || "unknown"}"`
431
+ );
432
+ }
433
+ return {
434
+ hasUpdate: false,
435
+ currentVersion,
436
+ latestVersion: manifest.version,
437
+ channel: manifest.channel ?? this.config.channel ?? "stable",
438
+ mandatory: false,
439
+ minVersion: manifest.min_version ?? null,
440
+ platform: platformKey,
441
+ downloadUrl: null,
442
+ sha256: null,
443
+ size: null,
444
+ format: null,
445
+ signature: null,
446
+ verifiedManifest: false,
447
+ artifacts: [],
448
+ releaseNotes: manifest.notes ?? "",
449
+ pubDate: manifest.pub_date ?? ""
450
+ };
451
+ }
452
+ const { primary, all } = resolveArtifactsFromPlatform(
453
+ matched.entry,
454
+ this.config.preferredFormat
455
+ );
456
+ assertSafeRemoteUrl(primary.url, Boolean(this.config.allowInsecureHttp));
457
+ return {
458
+ hasUpdate,
459
+ currentVersion,
460
+ latestVersion: manifest.version,
461
+ channel: manifest.channel ?? this.config.channel ?? "stable",
462
+ mandatory,
463
+ minVersion: manifest.min_version ?? null,
464
+ platform: matched.key,
465
+ downloadUrl: primary.url,
466
+ sha256: primary.sha256,
467
+ size: primary.size,
468
+ format: primary.format,
469
+ signature: primary.signature,
470
+ verifiedManifest: false,
471
+ artifacts: all,
472
+ releaseNotes: manifest.notes ?? "",
473
+ pubDate: manifest.pub_date ?? ""
474
+ };
475
+ }
476
+ /**
477
+ * Downloads and verifies the currently available update inside Tauri (streaming + SHA-256/Ed25519).
478
+ */
479
+ async download(overrideInfo) {
480
+ const info = overrideInfo ?? this.state.updateInfo;
481
+ if (!info?.downloadUrl) {
482
+ throw new UpdaterError("INVALID_INPUT", "No downloadable update is currently available");
483
+ }
484
+ if (!isTauriRuntime()) {
485
+ throw new UpdaterError(
486
+ "INVALID_INPUT",
487
+ "In-app verified downloads require the Tauri v2 runtime; use openDownloadUrl() on the web"
488
+ );
489
+ }
490
+ const downloadId = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `dl-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
491
+ this.activeDownloadId = downloadId;
492
+ this.setState({
493
+ status: "downloading",
494
+ error: null,
495
+ downloadResult: null,
496
+ progress: {
497
+ downloadId,
498
+ downloadedBytes: 0,
499
+ totalBytes: info.size,
500
+ percent: info.size ? 0 : null,
501
+ stage: "started"
502
+ }
503
+ });
504
+ await this.attachProgressListener(downloadId);
505
+ try {
506
+ const { invoke } = await import("@tauri-apps/api/core");
507
+ const result = await invoke("plugin:easy-updater|download_update", {
508
+ params: {
509
+ url: info.downloadUrl,
510
+ version: info.latestVersion,
511
+ platform: info.platform,
512
+ sha256: info.sha256,
513
+ expectedSize: info.size,
514
+ signature: info.signature,
515
+ format: info.format,
516
+ downloadId
517
+ }
518
+ });
519
+ if (!this.disposed) {
520
+ this.setState({
521
+ status: "ready",
522
+ downloadResult: result,
523
+ progress: {
524
+ downloadId: result.downloadId,
525
+ downloadedBytes: result.size,
526
+ totalBytes: result.size,
527
+ percent: 100,
528
+ stage: "completed"
529
+ },
530
+ error: null
531
+ });
532
+ }
533
+ return result;
534
+ } catch (rawErr) {
535
+ const err = UpdaterError.fromUnknown(rawErr);
536
+ if (!this.disposed) {
537
+ if (err.code === "DOWNLOAD_CANCELLED") {
538
+ this.setState({
539
+ status: "available",
540
+ progress: null,
541
+ error: null
542
+ });
543
+ } else {
544
+ this.setState({
545
+ status: "error",
546
+ error: err
547
+ });
548
+ }
549
+ }
550
+ throw err;
551
+ } finally {
552
+ this.activeDownloadId = null;
553
+ this.detachProgressListener();
554
+ }
555
+ }
556
+ /**
557
+ * Cancels an active in-app download cleanly.
558
+ */
559
+ async cancelDownload() {
560
+ if (!this.activeDownloadId || !isTauriRuntime()) {
561
+ return false;
562
+ }
563
+ const { invoke } = await import("@tauri-apps/api/core");
564
+ return await invoke("plugin:easy-updater|cancel_download", {
565
+ downloadId: this.activeDownloadId
566
+ });
567
+ }
568
+ /**
569
+ * Launches the previously downloaded & verified installer (anti-TOCTOU re-verified in Rust).
570
+ */
571
+ async install(downloadId) {
572
+ const id = downloadId ?? this.state.downloadResult?.downloadId;
573
+ if (!id) {
574
+ throw new UpdaterError("DOWNLOAD_NOT_FOUND", "No verified download is ready to install");
575
+ }
576
+ if (!isTauriRuntime()) {
577
+ throw new UpdaterError("INSTALL_FAILED", "Native installation requires Tauri v2 runtime");
578
+ }
579
+ this.setState({ status: "installing", error: null });
580
+ try {
581
+ const { invoke } = await import("@tauri-apps/api/core");
582
+ await invoke("plugin:easy-updater|install_update", { downloadId: id });
583
+ if (!this.disposed) {
584
+ this.setState({ status: "ready" });
585
+ }
586
+ } catch (rawErr) {
587
+ const err = UpdaterError.fromUnknown(rawErr);
588
+ if (!this.disposed) {
589
+ this.setState({ status: "error", error: err });
590
+ }
591
+ throw err;
592
+ }
593
+ }
594
+ /**
595
+ * Opens the verified HTTPS update URL in the user's default browser (lightweight mode).
596
+ */
597
+ async openDownloadUrl(urlOverride) {
598
+ const url = urlOverride ?? this.state.updateInfo?.downloadUrl;
599
+ if (!url) {
600
+ throw new UpdaterError("INVALID_URL", "No download URL available");
601
+ }
602
+ assertSafeRemoteUrl(url, Boolean(this.config.allowInsecureHttp));
603
+ if (isTauriRuntime()) {
604
+ const { invoke } = await import("@tauri-apps/api/core");
605
+ await invoke("plugin:easy-updater|open_url", { url });
606
+ return;
607
+ }
608
+ if (typeof window !== "undefined" && isSafeRemoteUrl(url, Boolean(this.config.allowInsecureHttp))) {
609
+ window.open(url, "_blank", "noopener,noreferrer");
610
+ }
611
+ }
612
+ /**
613
+ * Applies the available update according to the configured `mode` (`hybrid`, `download`, or `browser`).
614
+ */
615
+ async applyUpdate(modeOverride) {
616
+ const mode = modeOverride ?? this.config.mode ?? "hybrid";
617
+ const info = this.state.updateInfo;
618
+ if (!info?.downloadUrl) {
619
+ throw new UpdaterError("INVALID_INPUT", "No update available to apply");
620
+ }
621
+ if (mode === "browser") {
622
+ await this.openDownloadUrl(info.downloadUrl);
623
+ return;
624
+ }
625
+ if (mode === "download") {
626
+ const result = this.state.downloadResult ?? await this.download(info);
627
+ await this.install(result.downloadId);
628
+ return;
629
+ }
630
+ if (isTauriRuntime() && info.sha256) {
631
+ const result = this.state.downloadResult ?? await this.download(info);
632
+ await this.install(result.downloadId);
633
+ } else {
634
+ await this.openDownloadUrl(info.downloadUrl);
635
+ }
636
+ }
637
+ /**
638
+ * Dismisses the currently available update for this session.
639
+ * Ignored if the update is `mandatory`.
640
+ */
641
+ dismiss() {
642
+ const info = this.state.updateInfo;
643
+ if (info?.mandatory) {
644
+ return;
645
+ }
646
+ if (info) {
647
+ this.writeDismissedVersion(info.latestVersion);
648
+ }
649
+ this.setState({ isDismissed: true });
650
+ }
651
+ async attachProgressListener(downloadId) {
652
+ this.detachProgressListener();
653
+ if (!isTauriRuntime()) return;
654
+ try {
655
+ const { listen } = await import("@tauri-apps/api/event");
656
+ const unlisten = await listen(PROGRESS_EVENT_NAME, (event) => {
657
+ if (this.disposed) return;
658
+ const payload = event.payload;
659
+ if (!payload || payload.downloadId !== downloadId) return;
660
+ const nextStatus = payload.stage === "verifying" ? "verifying" : payload.stage === "completed" ? "ready" : "downloading";
661
+ this.setState({
662
+ status: nextStatus,
663
+ progress: payload
664
+ });
665
+ });
666
+ this.unlistenProgress = unlisten;
667
+ } catch {
668
+ }
669
+ }
670
+ detachProgressListener() {
671
+ if (this.unlistenProgress) {
672
+ try {
673
+ this.unlistenProgress();
674
+ } catch {
675
+ }
676
+ this.unlistenProgress = null;
677
+ }
678
+ }
679
+ readDismissedVersion() {
680
+ try {
681
+ return this.storage?.getItem(SESSION_DISMISS_KEY) ?? null;
682
+ } catch {
683
+ return null;
684
+ }
685
+ }
686
+ writeDismissedVersion(version) {
687
+ try {
688
+ this.storage?.setItem(SESSION_DISMISS_KEY, version);
689
+ } catch {
690
+ }
691
+ }
692
+ setState(partial) {
693
+ this.state = {
694
+ ...this.state,
695
+ ...partial
696
+ };
697
+ for (const listener of this.listeners) {
698
+ listener(this.state);
699
+ }
700
+ }
701
+ };
702
+
703
+ // src/react/useUpdater.ts
704
+ function buildConfigKey(config) {
705
+ return JSON.stringify([
706
+ config.currentVersion ?? null,
707
+ config.provider?.fingerprint ?? null,
708
+ config.channel ?? null,
709
+ config.preferredFormat ?? null,
710
+ config.mode ?? "hybrid",
711
+ Boolean(config.silent),
712
+ Boolean(config.allowInsecureHttp)
713
+ ]);
714
+ }
715
+ function useUpdater(config = {}) {
716
+ const { checkOnStartup = true, checkIntervalMs = 0 } = config;
717
+ const configKey = buildConfigKey(config);
718
+ const clientRef = (0, import_react.useRef)(null);
719
+ if (!clientRef.current || clientRef.current.key !== configKey) {
720
+ clientRef.current?.client.dispose();
721
+ clientRef.current = {
722
+ key: configKey,
723
+ client: new UpdaterClient(config)
724
+ };
725
+ }
726
+ const client = clientRef.current.client;
727
+ const subscribe = (0, import_react.useCallback)(
728
+ (onStoreChange) => client.subscribe(onStoreChange),
729
+ [client]
730
+ );
731
+ const getSnapshot = (0, import_react.useCallback)(() => client.getState(), [client]);
732
+ const state = (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
733
+ (0, import_react.useEffect)(() => {
734
+ if (checkOnStartup) {
735
+ void client.check();
736
+ }
737
+ }, [client, checkOnStartup]);
738
+ (0, import_react.useEffect)(() => {
739
+ if (checkIntervalMs > 0) {
740
+ client.startPolling(checkIntervalMs);
741
+ } else {
742
+ client.stopPolling();
743
+ }
744
+ return () => {
745
+ client.stopPolling();
746
+ };
747
+ }, [client, checkIntervalMs]);
748
+ (0, import_react.useEffect)(() => {
749
+ return () => {
750
+ client.dispose();
751
+ };
752
+ }, [client]);
753
+ const checkNow = (0, import_react.useCallback)(() => client.check(), [client]);
754
+ const download = (0, import_react.useCallback)(() => client.download(), [client]);
755
+ const cancelDownload = (0, import_react.useCallback)(() => client.cancelDownload(), [client]);
756
+ const install = (0, import_react.useCallback)(() => client.install(), [client]);
757
+ const applyUpdate = (0, import_react.useCallback)(
758
+ (modeOverride) => client.applyUpdate(modeOverride),
759
+ [client]
760
+ );
761
+ const openDownloadUrl = (0, import_react.useCallback)(() => client.openDownloadUrl(), [client]);
762
+ const dismiss = (0, import_react.useCallback)(() => client.dismiss(), [client]);
763
+ return (0, import_react.useMemo)(
764
+ () => ({
765
+ state,
766
+ status: state.status,
767
+ updateInfo: state.updateInfo,
768
+ progress: state.progress,
769
+ downloadResult: state.downloadResult,
770
+ isChecking: state.status === "checking",
771
+ isDownloading: state.status === "downloading" || state.status === "verifying",
772
+ error: state.error,
773
+ isDismissed: state.isDismissed,
774
+ checkNow,
775
+ download,
776
+ cancelDownload,
777
+ install,
778
+ applyUpdate,
779
+ openDownloadUrl,
780
+ dismiss
781
+ }),
782
+ [state, checkNow, download, cancelDownload, install, applyUpdate, openDownloadUrl, dismiss]
783
+ );
784
+ }
785
+
786
+ // src/react/useUpdateChecker.ts
787
+ function useUpdateChecker(config = {}) {
788
+ return useUpdater(config);
789
+ }
790
+
791
+ // src/react/i18n.ts
792
+ var EN_LABELS = {
793
+ bannerTitle: "Version {latestVersion} is available",
794
+ bannerSubtitle: "You are using version {currentVersion}. Update to get the latest improvements.",
795
+ modalTitle: "New update available",
796
+ modalTitleWithApp: "{appName} has a new version",
797
+ versionSummary: "Current version {currentVersion} \xB7 New version {latestVersion}",
798
+ defaultReleaseNotes: "This update includes performance improvements and bug fixes.",
799
+ mandatoryBadge: "Required update",
800
+ updateNow: "Update now",
801
+ downloadNow: "Download update",
802
+ installNow: "Install now",
803
+ openInBrowser: "Download in browser",
804
+ downloading: "Downloading update\u2026",
805
+ verifying: "Verifying integrity\u2026",
806
+ installing: "Launching installer\u2026",
807
+ cancel: "Cancel",
808
+ retry: "Retry",
809
+ remindLater: "Remind me later",
810
+ closeAriaLabel: "Close"
811
+ };
812
+ var ES_LABELS = {
813
+ bannerTitle: "Nueva versi\xF3n {latestVersion} disponible",
814
+ bannerSubtitle: "Est\xE1s usando la versi\xF3n {currentVersion}. Actualiza para obtener las \xFAltimas mejoras.",
815
+ modalTitle: "Nueva actualizaci\xF3n disponible",
816
+ modalTitleWithApp: "{appName} tiene una nueva versi\xF3n",
817
+ versionSummary: "Versi\xF3n actual {currentVersion} \xB7 Nueva versi\xF3n {latestVersion}",
818
+ defaultReleaseNotes: "Esta actualizaci\xF3n incluye mejoras de rendimiento y correcciones de errores.",
819
+ mandatoryBadge: "Actualizaci\xF3n obligatoria",
820
+ updateNow: "Actualizar ahora",
821
+ downloadNow: "Descargar actualizaci\xF3n",
822
+ installNow: "Instalar ahora",
823
+ openInBrowser: "Descargar en navegador",
824
+ downloading: "Descargando actualizaci\xF3n\u2026",
825
+ verifying: "Verificando integridad\u2026",
826
+ installing: "Abriendo instalador\u2026",
827
+ cancel: "Cancelar",
828
+ retry: "Reintentar",
829
+ remindLater: "Recordarme despu\xE9s",
830
+ closeAriaLabel: "Cerrar"
831
+ };
832
+ function resolveLabels(locale = "en", overrides) {
833
+ const base = locale === "es" ? ES_LABELS : EN_LABELS;
834
+ return overrides ? { ...base, ...overrides } : base;
835
+ }
836
+ function formatTemplate(template, vars) {
837
+ return template.replace(
838
+ /\{(\w+)\}/g,
839
+ (match, key) => key in vars ? vars[key] : match
840
+ );
841
+ }
842
+ function formatBytes(bytes) {
843
+ if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
844
+ const units = ["B", "KB", "MB", "GB"];
845
+ let value = bytes;
846
+ let idx = 0;
847
+ while (value >= 1024 && idx < units.length - 1) {
848
+ value /= 1024;
849
+ idx += 1;
850
+ }
851
+ return `${value.toFixed(idx === 0 ? 0 : 1)} ${units[idx]}`;
852
+ }
853
+
854
+ // src/react/theme.ts
855
+ function resolveTheme(theme = "auto") {
856
+ if (theme === "auto" && typeof window !== "undefined" && typeof window.matchMedia === "function") {
857
+ try {
858
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
859
+ return "dark";
860
+ }
861
+ } catch {
862
+ }
863
+ }
864
+ return theme === "auto" ? "light" : theme;
865
+ }
866
+
867
+ // src/react/components/UpdateBanner.tsx
868
+ var import_jsx_runtime = require("react/jsx-runtime");
869
+ async function defaultSafeOpenUrl(url) {
870
+ assertSafeRemoteUrl(url);
871
+ if (isTauriRuntime()) {
872
+ const { invoke } = await import("@tauri-apps/api/core");
873
+ await invoke("plugin:easy-updater|open_url", { url });
874
+ return;
875
+ }
876
+ if (typeof window !== "undefined" && isSafeRemoteUrl(url)) {
877
+ window.open(url, "_blank", "noopener,noreferrer");
878
+ }
879
+ }
880
+ function UpdateBanner(props) {
881
+ const {
882
+ updateInfo,
883
+ onDismiss,
884
+ onUpdate,
885
+ onCancel,
886
+ status = "available",
887
+ progress = null,
888
+ error = null,
889
+ position = "bottom",
890
+ theme = "auto",
891
+ locale = "en",
892
+ labels: labelOverrides,
893
+ className
894
+ } = props;
895
+ const resolvedTheme = resolveTheme(theme);
896
+ const labels = resolveLabels(locale, labelOverrides);
897
+ const isBusy = status === "downloading" || status === "verifying" || status === "installing";
898
+ const canDismiss = !updateInfo.mandatory && Boolean(onDismiss) && !isBusy;
899
+ const vars = {
900
+ latestVersion: updateInfo.latestVersion,
901
+ currentVersion: updateInfo.currentVersion
902
+ };
903
+ const handlePrimaryClick = () => {
904
+ if (onUpdate) {
905
+ void onUpdate();
906
+ } else if (updateInfo.downloadUrl) {
907
+ void defaultSafeOpenUrl(updateInfo.downloadUrl);
908
+ }
909
+ };
910
+ const isDark = resolvedTheme === "dark";
911
+ const containerStyle = {
912
+ position: "fixed",
913
+ left: 0,
914
+ right: 0,
915
+ ...position === "top" ? { top: 0 } : { bottom: 0 },
916
+ display: "flex",
917
+ alignItems: "center",
918
+ justifyContent: "space-between",
919
+ gap: "1rem",
920
+ padding: "0.75rem 1.25rem",
921
+ fontSize: "0.875rem",
922
+ zIndex: 50,
923
+ backgroundColor: isDark ? "rgba(15, 23, 42, 0.96)" : "rgba(248, 250, 252, 0.98)",
924
+ color: isDark ? "#f8fafc" : "#0f172a",
925
+ borderTop: position === "bottom" ? `1px solid ${isDark ? "rgba(148, 163, 184, 0.35)" : "#e2e8f0"}` : void 0,
926
+ borderBottom: position === "top" ? `1px solid ${isDark ? "rgba(148, 163, 184, 0.35)" : "#e2e8f0"}` : void 0,
927
+ boxShadow: "0 4px 16px rgba(15, 23, 42, 0.14)"
928
+ };
929
+ const primaryBtnStyle = {
930
+ backgroundColor: isDark ? "#22c55e" : "#16a34a",
931
+ color: isDark ? "#022c22" : "#ffffff",
932
+ borderRadius: "9999px",
933
+ padding: "0.45rem 1rem",
934
+ border: "none",
935
+ cursor: isBusy ? "wait" : "pointer",
936
+ opacity: isBusy ? 0.75 : 1,
937
+ fontSize: "0.875rem",
938
+ fontWeight: 600
939
+ };
940
+ const secondaryBtnStyle = {
941
+ background: "transparent",
942
+ color: isDark ? "#e2e8f0" : "#334155",
943
+ border: `1px solid ${isDark ? "#475569" : "#cbd5e1"}`,
944
+ borderRadius: "9999px",
945
+ padding: "0.4rem 0.85rem",
946
+ cursor: "pointer",
947
+ fontSize: "0.8125rem",
948
+ fontWeight: 500
949
+ };
950
+ const primaryLabel = status === "verifying" ? labels.verifying : status === "installing" ? labels.installing : status === "downloading" ? labels.downloading : status === "ready" ? labels.installNow : status === "error" ? labels.retry : labels.updateNow;
951
+ const percent = progress?.percent ?? null;
952
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
953
+ "div",
954
+ {
955
+ role: "status",
956
+ "aria-live": "polite",
957
+ style: containerStyle,
958
+ className,
959
+ children: [
960
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "0.25rem", flex: 1, minWidth: 0 }, children: [
961
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem", flexWrap: "wrap" }, children: [
962
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontWeight: 600 }, children: formatTemplate(labels.bannerTitle, vars) }),
963
+ updateInfo.mandatory && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
964
+ "span",
965
+ {
966
+ style: {
967
+ fontSize: "0.75rem",
968
+ fontWeight: 600,
969
+ padding: "0.125rem 0.5rem",
970
+ borderRadius: "9999px",
971
+ backgroundColor: isDark ? "rgba(239, 68, 68, 0.2)" : "#fee2e2",
972
+ color: isDark ? "#fca5a5" : "#b91c1c"
973
+ },
974
+ children: labels.mandatoryBadge
975
+ }
976
+ )
977
+ ] }),
978
+ error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: isDark ? "#fca5a5" : "#b91c1c", fontSize: "0.8125rem" }, children: error.message }) : status === "downloading" || status === "verifying" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "0.25rem", maxWidth: "28rem" }, children: [
979
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", justifyContent: "space-between", fontSize: "0.75rem", opacity: 0.85 }, children: [
980
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: status === "verifying" ? labels.verifying : labels.downloading }),
981
+ progress && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
982
+ formatBytes(progress.downloadedBytes),
983
+ progress.totalBytes ? ` / ${formatBytes(progress.totalBytes)}` : "",
984
+ percent !== null ? ` (${percent}%)` : ""
985
+ ] })
986
+ ] }),
987
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
988
+ "div",
989
+ {
990
+ role: "progressbar",
991
+ "aria-valuemin": 0,
992
+ "aria-valuemax": 100,
993
+ "aria-valuenow": percent ?? void 0,
994
+ style: {
995
+ height: "0.375rem",
996
+ borderRadius: "9999px",
997
+ overflow: "hidden",
998
+ backgroundColor: isDark ? "#1e293b" : "#e2e8f0"
999
+ },
1000
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1001
+ "div",
1002
+ {
1003
+ style: {
1004
+ height: "100%",
1005
+ width: `${percent ?? 100}%`,
1006
+ backgroundColor: isDark ? "#22c55e" : "#16a34a",
1007
+ transition: "width 150ms ease"
1008
+ }
1009
+ }
1010
+ )
1011
+ }
1012
+ )
1013
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { opacity: 0.85 }, children: formatTemplate(labels.bannerSubtitle, vars) })
1014
+ ] }),
1015
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem", flexShrink: 0 }, children: [
1016
+ status === "downloading" && onCancel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: secondaryBtnStyle, onClick: () => void onCancel(), children: labels.cancel }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1017
+ "button",
1018
+ {
1019
+ type: "button",
1020
+ disabled: isBusy || !updateInfo.downloadUrl,
1021
+ style: primaryBtnStyle,
1022
+ onClick: handlePrimaryClick,
1023
+ children: primaryLabel
1024
+ }
1025
+ ),
1026
+ canDismiss && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1027
+ "button",
1028
+ {
1029
+ type: "button",
1030
+ "aria-label": labels.closeAriaLabel,
1031
+ style: {
1032
+ background: "transparent",
1033
+ border: "none",
1034
+ color: isDark ? "#e2e8f0" : "#475569",
1035
+ cursor: "pointer",
1036
+ fontSize: "1.25rem",
1037
+ lineHeight: 1,
1038
+ padding: "0.25rem 0.4rem"
1039
+ },
1040
+ onClick: onDismiss,
1041
+ children: "\xD7"
1042
+ }
1043
+ )
1044
+ ] })
1045
+ ]
1046
+ }
1047
+ );
1048
+ }
1049
+
1050
+ // src/react/components/UpdateModal.tsx
1051
+ var import_react2 = require("react");
1052
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1053
+ async function defaultSafeOpenUrl2(url) {
1054
+ assertSafeRemoteUrl(url);
1055
+ if (isTauriRuntime()) {
1056
+ const { invoke } = await import("@tauri-apps/api/core");
1057
+ await invoke("plugin:easy-updater|open_url", { url });
1058
+ return;
1059
+ }
1060
+ if (typeof window !== "undefined" && isSafeRemoteUrl(url)) {
1061
+ window.open(url, "_blank", "noopener,noreferrer");
1062
+ }
1063
+ }
1064
+ function UpdateModal(props) {
1065
+ const {
1066
+ updateInfo,
1067
+ onDismiss,
1068
+ onUpdate,
1069
+ onCancel,
1070
+ status = "available",
1071
+ progress = null,
1072
+ error = null,
1073
+ appName,
1074
+ theme = "auto",
1075
+ locale = "en",
1076
+ labels: labelOverrides,
1077
+ className
1078
+ } = props;
1079
+ const titleId = (0, import_react2.useId)();
1080
+ const resolvedTheme = resolveTheme(theme);
1081
+ const labels = resolveLabels(locale, labelOverrides);
1082
+ const isBusy = status === "downloading" || status === "verifying" || status === "installing";
1083
+ const canDismiss = !updateInfo.mandatory && Boolean(onDismiss) && !isBusy;
1084
+ const isDark = resolvedTheme === "dark";
1085
+ (0, import_react2.useEffect)(() => {
1086
+ if (!canDismiss || !onDismiss) return;
1087
+ const handleKeyDown = (event) => {
1088
+ if (event.key === "Escape") {
1089
+ onDismiss();
1090
+ }
1091
+ };
1092
+ window.addEventListener("keydown", handleKeyDown);
1093
+ return () => {
1094
+ window.removeEventListener("keydown", handleKeyDown);
1095
+ };
1096
+ }, [canDismiss, onDismiss]);
1097
+ const vars = {
1098
+ appName: appName ?? "",
1099
+ latestVersion: updateInfo.latestVersion,
1100
+ currentVersion: updateInfo.currentVersion
1101
+ };
1102
+ const title = appName ? formatTemplate(labels.modalTitleWithApp, vars) : labels.modalTitle;
1103
+ const handlePrimaryClick = () => {
1104
+ if (onUpdate) {
1105
+ void onUpdate();
1106
+ } else if (updateInfo.downloadUrl) {
1107
+ void defaultSafeOpenUrl2(updateInfo.downloadUrl);
1108
+ }
1109
+ };
1110
+ const overlayStyle = {
1111
+ position: "fixed",
1112
+ inset: 0,
1113
+ backgroundColor: "rgba(15, 23, 42, 0.65)",
1114
+ display: "flex",
1115
+ alignItems: "center",
1116
+ justifyContent: "center",
1117
+ padding: "1rem",
1118
+ zIndex: 60
1119
+ };
1120
+ const modalStyle = {
1121
+ backgroundColor: isDark ? "#0f172a" : "#ffffff",
1122
+ color: isDark ? "#f8fafc" : "#0f172a",
1123
+ border: `1px solid ${isDark ? "rgba(148, 163, 184, 0.25)" : "#e2e8f0"}`,
1124
+ borderRadius: "0.75rem",
1125
+ padding: "1.5rem",
1126
+ maxWidth: "28rem",
1127
+ width: "100%",
1128
+ boxShadow: isDark ? "0 20px 30px -5px rgba(2, 6, 23, 0.85)" : "0 20px 25px -5px rgba(15, 23, 42, 0.2)"
1129
+ };
1130
+ const primaryButtonStyle = {
1131
+ backgroundColor: isDark ? "#22c55e" : "#16a34a",
1132
+ color: isDark ? "#022c22" : "#ffffff",
1133
+ padding: "0.5rem 1rem",
1134
+ borderRadius: "9999px",
1135
+ border: "none",
1136
+ cursor: isBusy ? "wait" : "pointer",
1137
+ opacity: isBusy ? 0.75 : 1,
1138
+ fontSize: "0.875rem",
1139
+ fontWeight: 600
1140
+ };
1141
+ const secondaryButtonStyle = {
1142
+ background: "transparent",
1143
+ borderColor: isDark ? "#475569" : "#cbd5e1",
1144
+ color: isDark ? "#e2e8f0" : "#1e293b",
1145
+ padding: "0.5rem 1rem",
1146
+ borderRadius: "9999px",
1147
+ borderWidth: 1,
1148
+ borderStyle: "solid",
1149
+ cursor: "pointer",
1150
+ fontSize: "0.875rem",
1151
+ fontWeight: 500
1152
+ };
1153
+ const primaryLabel = status === "verifying" ? labels.verifying : status === "installing" ? labels.installing : status === "downloading" ? labels.downloading : status === "ready" ? labels.installNow : status === "error" ? labels.retry : labels.downloadNow;
1154
+ const percent = progress?.percent ?? null;
1155
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1156
+ "div",
1157
+ {
1158
+ style: overlayStyle,
1159
+ onClick: (e) => {
1160
+ if (e.target === e.currentTarget && canDismiss && onDismiss) {
1161
+ onDismiss();
1162
+ }
1163
+ },
1164
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1165
+ "div",
1166
+ {
1167
+ role: "dialog",
1168
+ "aria-modal": "true",
1169
+ "aria-labelledby": titleId,
1170
+ style: modalStyle,
1171
+ className,
1172
+ children: [
1173
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1174
+ "div",
1175
+ {
1176
+ style: {
1177
+ display: "flex",
1178
+ justifyContent: "space-between",
1179
+ alignItems: "flex-start",
1180
+ gap: "0.75rem",
1181
+ marginBottom: "0.75rem"
1182
+ },
1183
+ children: [
1184
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
1185
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem", flexWrap: "wrap" }, children: [
1186
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1187
+ "h2",
1188
+ {
1189
+ id: titleId,
1190
+ style: {
1191
+ fontSize: "1.125rem",
1192
+ fontWeight: 600,
1193
+ margin: 0
1194
+ },
1195
+ children: title
1196
+ }
1197
+ ),
1198
+ updateInfo.mandatory && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1199
+ "span",
1200
+ {
1201
+ style: {
1202
+ fontSize: "0.75rem",
1203
+ fontWeight: 600,
1204
+ padding: "0.125rem 0.5rem",
1205
+ borderRadius: "9999px",
1206
+ backgroundColor: isDark ? "rgba(239, 68, 68, 0.2)" : "#fee2e2",
1207
+ color: isDark ? "#fca5a5" : "#b91c1c"
1208
+ },
1209
+ children: labels.mandatoryBadge
1210
+ }
1211
+ )
1212
+ ] }),
1213
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { opacity: 0.8, fontSize: "0.875rem", margin: "0.25rem 0 0" }, children: formatTemplate(labels.versionSummary, vars) })
1214
+ ] }),
1215
+ canDismiss && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1216
+ "button",
1217
+ {
1218
+ type: "button",
1219
+ "aria-label": labels.closeAriaLabel,
1220
+ onClick: onDismiss,
1221
+ style: {
1222
+ background: "transparent",
1223
+ border: "none",
1224
+ color: isDark ? "#e2e8f0" : "#475569",
1225
+ cursor: "pointer",
1226
+ fontSize: "1.25rem",
1227
+ lineHeight: 1,
1228
+ padding: "0.2rem 0.4rem"
1229
+ },
1230
+ children: "\xD7"
1231
+ }
1232
+ )
1233
+ ]
1234
+ }
1235
+ ),
1236
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1237
+ "div",
1238
+ {
1239
+ style: {
1240
+ marginTop: "0.75rem",
1241
+ marginBottom: "1rem",
1242
+ maxHeight: "12rem",
1243
+ overflowY: "auto",
1244
+ padding: "0.75rem",
1245
+ borderRadius: "0.5rem",
1246
+ backgroundColor: isDark ? "#020617" : "#f1f5f9",
1247
+ border: `1px solid ${isDark ? "#1e293b" : "#e2e8f0"}`,
1248
+ fontSize: "0.875rem",
1249
+ whiteSpace: "pre-wrap",
1250
+ lineHeight: 1.5
1251
+ },
1252
+ children: updateInfo.releaseNotes || labels.defaultReleaseNotes
1253
+ }
1254
+ ),
1255
+ (status === "downloading" || status === "verifying") && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { marginBottom: "1rem", display: "flex", flexDirection: "column", gap: "0.35rem" }, children: [
1256
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", justifyContent: "space-between", fontSize: "0.8125rem", opacity: 0.85 }, children: [
1257
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: status === "verifying" ? labels.verifying : labels.downloading }),
1258
+ progress && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1259
+ formatBytes(progress.downloadedBytes),
1260
+ progress.totalBytes ? ` / ${formatBytes(progress.totalBytes)}` : "",
1261
+ percent !== null ? ` (${percent}%)` : ""
1262
+ ] })
1263
+ ] }),
1264
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1265
+ "div",
1266
+ {
1267
+ role: "progressbar",
1268
+ "aria-valuemin": 0,
1269
+ "aria-valuemax": 100,
1270
+ "aria-valuenow": percent ?? void 0,
1271
+ style: {
1272
+ height: "0.5rem",
1273
+ borderRadius: "9999px",
1274
+ overflow: "hidden",
1275
+ backgroundColor: isDark ? "#1e293b" : "#e2e8f0"
1276
+ },
1277
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1278
+ "div",
1279
+ {
1280
+ style: {
1281
+ height: "100%",
1282
+ width: `${percent ?? 100}%`,
1283
+ backgroundColor: isDark ? "#22c55e" : "#16a34a",
1284
+ transition: "width 150ms ease"
1285
+ }
1286
+ }
1287
+ )
1288
+ }
1289
+ )
1290
+ ] }),
1291
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1292
+ "div",
1293
+ {
1294
+ role: "alert",
1295
+ style: {
1296
+ marginBottom: "1rem",
1297
+ padding: "0.6rem 0.75rem",
1298
+ borderRadius: "0.5rem",
1299
+ backgroundColor: isDark ? "rgba(239, 68, 68, 0.16)" : "#fef2f2",
1300
+ color: isDark ? "#fca5a5" : "#b91c1c",
1301
+ fontSize: "0.8125rem"
1302
+ },
1303
+ children: error.message
1304
+ }
1305
+ ),
1306
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1307
+ "div",
1308
+ {
1309
+ style: {
1310
+ display: "flex",
1311
+ justifyContent: "flex-end",
1312
+ gap: "0.5rem",
1313
+ marginTop: "0.5rem"
1314
+ },
1315
+ children: status === "downloading" && onCancel ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => void onCancel(), style: secondaryButtonStyle, children: labels.cancel }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1316
+ canDismiss && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: onDismiss, style: secondaryButtonStyle, children: labels.remindLater }),
1317
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1318
+ "button",
1319
+ {
1320
+ type: "button",
1321
+ disabled: isBusy || !updateInfo.downloadUrl,
1322
+ onClick: handlePrimaryClick,
1323
+ style: primaryButtonStyle,
1324
+ children: primaryLabel
1325
+ }
1326
+ )
1327
+ ] })
1328
+ }
1329
+ )
1330
+ ]
1331
+ }
1332
+ )
1333
+ }
1334
+ );
1335
+ }
1336
+ // Annotate the CommonJS export names for ESM import in node:
1337
+ 0 && (module.exports = {
1338
+ EN_LABELS,
1339
+ ES_LABELS,
1340
+ UpdateBanner,
1341
+ UpdateModal,
1342
+ formatBytes,
1343
+ formatTemplate,
1344
+ resolveLabels,
1345
+ resolveTheme,
1346
+ useUpdateChecker,
1347
+ useUpdater
1348
+ });
1349
+ //# sourceMappingURL=index.js.map