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