@meacore/tauri-easy-updater 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/index.d.mts +154 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +779 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +735 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,779 @@
|
|
|
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/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
UpdateBanner: () => UpdateBanner,
|
|
34
|
+
UpdateModal: () => UpdateModal,
|
|
35
|
+
createGitHubProvider: () => createGitHubProvider,
|
|
36
|
+
createHttpProvider: () => createHttpProvider,
|
|
37
|
+
createS3Provider: () => createS3Provider,
|
|
38
|
+
getCurrentPlatform: () => getCurrentPlatform,
|
|
39
|
+
isNewerVersion: () => isNewerVersion,
|
|
40
|
+
useUpdateChecker: () => useUpdateChecker
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/utils/platform.ts
|
|
45
|
+
async function getCurrentPlatform() {
|
|
46
|
+
if (typeof window === "undefined") {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const os = await import("@tauri-apps/api/os");
|
|
51
|
+
const type = await os.type();
|
|
52
|
+
const arch = await os.arch();
|
|
53
|
+
const normalizedOs = normalizeOs(type);
|
|
54
|
+
const normalizedArch = normalizeArch(arch);
|
|
55
|
+
if (!normalizedOs || !normalizedArch) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
return `${normalizedOs}-${normalizedArch}`;
|
|
59
|
+
} catch {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function normalizeOs(os) {
|
|
64
|
+
const lower = os.toLowerCase();
|
|
65
|
+
if (lower.startsWith("win")) return "windows";
|
|
66
|
+
if (lower.startsWith("mac")) return "darwin";
|
|
67
|
+
if (lower.startsWith("linux")) return "linux";
|
|
68
|
+
return "";
|
|
69
|
+
}
|
|
70
|
+
function normalizeArch(arch) {
|
|
71
|
+
const lower = arch.toLowerCase();
|
|
72
|
+
if (lower === "x86_64" || lower === "x64" || lower === "amd64") {
|
|
73
|
+
return "x86_64";
|
|
74
|
+
}
|
|
75
|
+
if (lower === "aarch64" || lower === "arm64") {
|
|
76
|
+
return "aarch64";
|
|
77
|
+
}
|
|
78
|
+
return "";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/utils/semver.ts
|
|
82
|
+
function parseVersion(input) {
|
|
83
|
+
let v = input.trim();
|
|
84
|
+
if (v.startsWith("v") || v.startsWith("V")) {
|
|
85
|
+
v = v.slice(1);
|
|
86
|
+
}
|
|
87
|
+
const [core, prerelease] = v.split("-", 2);
|
|
88
|
+
const parts = core.split(".");
|
|
89
|
+
if (parts.length < 2 || parts.length > 3) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const [majStr, minStr, patchStr = "0"] = parts;
|
|
93
|
+
const major = Number(majStr);
|
|
94
|
+
const minor = Number(minStr);
|
|
95
|
+
const patch = Number(patchStr);
|
|
96
|
+
if (!Number.isFinite(major) || !Number.isFinite(minor) || !Number.isFinite(patch)) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
major,
|
|
101
|
+
minor,
|
|
102
|
+
patch,
|
|
103
|
+
prerelease: prerelease ?? null
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function comparePrerelease(a, b) {
|
|
107
|
+
if (a === b) return 0;
|
|
108
|
+
if (a === null) return 1;
|
|
109
|
+
if (b === null) return -1;
|
|
110
|
+
const aParts = a.split(".");
|
|
111
|
+
const bParts = b.split(".");
|
|
112
|
+
const len = Math.max(aParts.length, bParts.length);
|
|
113
|
+
for (let i = 0; i < len; i += 1) {
|
|
114
|
+
const ai = aParts[i];
|
|
115
|
+
const bi = bParts[i];
|
|
116
|
+
if (ai === void 0) return -1;
|
|
117
|
+
if (bi === void 0) return 1;
|
|
118
|
+
const aNum = Number(ai);
|
|
119
|
+
const bNum = Number(bi);
|
|
120
|
+
const aIsNum = Number.isFinite(aNum);
|
|
121
|
+
const bIsNum = Number.isFinite(bNum);
|
|
122
|
+
if (aIsNum && bIsNum) {
|
|
123
|
+
if (aNum > bNum) return 1;
|
|
124
|
+
if (aNum < bNum) return -1;
|
|
125
|
+
} else if (aIsNum && !bIsNum) {
|
|
126
|
+
return -1;
|
|
127
|
+
} else if (!aIsNum && bIsNum) {
|
|
128
|
+
return 1;
|
|
129
|
+
} else {
|
|
130
|
+
if (ai > bi) return 1;
|
|
131
|
+
if (ai < bi) return -1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
function isNewerVersion(latest, current) {
|
|
137
|
+
const a = parseVersion(latest);
|
|
138
|
+
const b = parseVersion(current);
|
|
139
|
+
if (!a || !b) return false;
|
|
140
|
+
if (a.major !== b.major) return a.major > b.major;
|
|
141
|
+
if (a.minor !== b.minor) return a.minor > b.minor;
|
|
142
|
+
if (a.patch !== b.patch) return a.patch > b.patch;
|
|
143
|
+
return comparePrerelease(a.prerelease, b.prerelease) > 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/providers/github.ts
|
|
147
|
+
function createGitHubProvider(config) {
|
|
148
|
+
const {
|
|
149
|
+
owner,
|
|
150
|
+
repo,
|
|
151
|
+
manifestAssetName = "update-manifest.json",
|
|
152
|
+
fallbackToReleaseApi = true
|
|
153
|
+
} = config;
|
|
154
|
+
const manifestUrl = `https://github.com/${owner}/${repo}/releases/latest/download/${manifestAssetName}`;
|
|
155
|
+
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
|
|
156
|
+
const provider = {
|
|
157
|
+
type: "github",
|
|
158
|
+
async fetchManifest() {
|
|
159
|
+
try {
|
|
160
|
+
const res = await fetch(manifestUrl);
|
|
161
|
+
if (res.ok) {
|
|
162
|
+
const data = await res.json();
|
|
163
|
+
return data;
|
|
164
|
+
}
|
|
165
|
+
if (!fallbackToReleaseApi || res.status !== 404) {
|
|
166
|
+
throw new Error(`GitHub manifest request failed with status ${res.status}`);
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (!fallbackToReleaseApi) {
|
|
170
|
+
throw err instanceof Error ? err : new Error("Failed to fetch GitHub manifest");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const res = await fetch(apiUrl, {
|
|
175
|
+
headers: {
|
|
176
|
+
Accept: "application/vnd.github+json"
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
if (!res.ok) {
|
|
180
|
+
throw new Error(`GitHub releases API failed with status ${res.status}`);
|
|
181
|
+
}
|
|
182
|
+
const release = await res.json();
|
|
183
|
+
const platform = await getCurrentPlatform();
|
|
184
|
+
let url = "";
|
|
185
|
+
if (platform) {
|
|
186
|
+
const asset = selectAssetForPlatform(release.assets, platform);
|
|
187
|
+
if (asset) {
|
|
188
|
+
url = asset.browser_download_url;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const manifest = {
|
|
192
|
+
version: release.tag_name,
|
|
193
|
+
pub_date: release.published_at,
|
|
194
|
+
notes: release.body ?? "",
|
|
195
|
+
platforms: url ? {
|
|
196
|
+
[platform]: {
|
|
197
|
+
url
|
|
198
|
+
}
|
|
199
|
+
} : {}
|
|
200
|
+
};
|
|
201
|
+
return manifest;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw error instanceof Error ? error : new Error("Failed to fetch GitHub release");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
provider.__tauriParams = {
|
|
208
|
+
github_owner: owner,
|
|
209
|
+
github_repo: repo,
|
|
210
|
+
manifest_url: manifestUrl
|
|
211
|
+
};
|
|
212
|
+
return provider;
|
|
213
|
+
}
|
|
214
|
+
function selectAssetForPlatform(assets, platform) {
|
|
215
|
+
if (!platform) return void 0;
|
|
216
|
+
const lowerPlatform = platform.toLowerCase();
|
|
217
|
+
return assets.find((asset) => {
|
|
218
|
+
const name = asset.name.toLowerCase();
|
|
219
|
+
if (lowerPlatform === "windows-x86_64") {
|
|
220
|
+
return name.endsWith(".exe") || name.endsWith(".msi");
|
|
221
|
+
}
|
|
222
|
+
if (lowerPlatform === "darwin-x86_64") {
|
|
223
|
+
return name.endsWith(".dmg") && !name.includes("arm64") && !name.includes("aarch64");
|
|
224
|
+
}
|
|
225
|
+
if (lowerPlatform === "darwin-aarch64") {
|
|
226
|
+
return name.endsWith(".dmg") && (name.includes("arm64") || name.includes("aarch64"));
|
|
227
|
+
}
|
|
228
|
+
if (lowerPlatform === "linux-x86_64") {
|
|
229
|
+
return name.endsWith(".appimage") || name.endsWith(".AppImage") || name.endsWith(".deb") || name.endsWith(".rpm");
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/providers/http.ts
|
|
236
|
+
function createHttpProvider(config) {
|
|
237
|
+
const { manifestUrl, headers } = config;
|
|
238
|
+
const provider = {
|
|
239
|
+
type: "http",
|
|
240
|
+
async fetchManifest() {
|
|
241
|
+
const init = {
|
|
242
|
+
method: "GET",
|
|
243
|
+
headers
|
|
244
|
+
};
|
|
245
|
+
try {
|
|
246
|
+
const res = await fetch(manifestUrl, init);
|
|
247
|
+
if (!res.ok) {
|
|
248
|
+
throw new Error(`HTTP ${res.status}`);
|
|
249
|
+
}
|
|
250
|
+
const data = await res.json();
|
|
251
|
+
return data;
|
|
252
|
+
} catch (error) {
|
|
253
|
+
throw error instanceof Error ? error : new Error("Failed to fetch update manifest");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
provider.__tauriParams = { manifest_url: manifestUrl };
|
|
258
|
+
return provider;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/providers/s3.ts
|
|
262
|
+
function createS3Provider(config) {
|
|
263
|
+
const { bucketUrl, manifestPath = "latest/update-manifest.json" } = config;
|
|
264
|
+
const manifestUrl = `${bucketUrl.replace(/\/+$/, "")}/${manifestPath.replace(/^\/+/, "")}`;
|
|
265
|
+
const httpProvider = createHttpProvider({ manifestUrl });
|
|
266
|
+
const provider = {
|
|
267
|
+
type: "s3",
|
|
268
|
+
async fetchManifest() {
|
|
269
|
+
return httpProvider.fetchManifest();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
provider.__tauriParams = { manifest_url: manifestUrl };
|
|
273
|
+
return provider;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/hooks/useUpdateChecker.ts
|
|
277
|
+
var import_react = require("react");
|
|
278
|
+
var SESSION_DISMISS_KEY = "tauri-easy-updater:dismissed-version";
|
|
279
|
+
function getDismissedVersion() {
|
|
280
|
+
if (typeof window === "undefined") return null;
|
|
281
|
+
try {
|
|
282
|
+
return window.sessionStorage.getItem(SESSION_DISMISS_KEY);
|
|
283
|
+
} catch {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function setDismissedVersion(version) {
|
|
288
|
+
if (typeof window === "undefined") return;
|
|
289
|
+
try {
|
|
290
|
+
window.sessionStorage.setItem(SESSION_DISMISS_KEY, version);
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function buildParamsFromProvider(provider, currentVersion) {
|
|
295
|
+
const anyProvider = provider;
|
|
296
|
+
const base = {
|
|
297
|
+
current_version: currentVersion,
|
|
298
|
+
manifest_url: ""
|
|
299
|
+
};
|
|
300
|
+
if (!anyProvider.__tauriParams) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
const { manifest_url, github_owner, github_repo } = anyProvider.__tauriParams;
|
|
304
|
+
if (github_owner && github_repo) {
|
|
305
|
+
return {
|
|
306
|
+
...base,
|
|
307
|
+
manifest_url: manifest_url ?? "",
|
|
308
|
+
github_owner,
|
|
309
|
+
github_repo
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (manifest_url) {
|
|
313
|
+
return {
|
|
314
|
+
...base,
|
|
315
|
+
manifest_url,
|
|
316
|
+
github_owner: null,
|
|
317
|
+
github_repo: null
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function useUpdateChecker(config) {
|
|
323
|
+
const {
|
|
324
|
+
currentVersion,
|
|
325
|
+
provider,
|
|
326
|
+
checkOnStartup = true,
|
|
327
|
+
checkIntervalMs = 0,
|
|
328
|
+
silent = false
|
|
329
|
+
} = config;
|
|
330
|
+
const [updateInfo, setUpdateInfo] = (0, import_react.useState)(null);
|
|
331
|
+
const [isChecking, setIsChecking] = (0, import_react.useState)(false);
|
|
332
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
333
|
+
const [isDismissed, setIsDismissed] = (0, import_react.useState)(false);
|
|
334
|
+
const intervalRef = (0, import_react.useRef)(null);
|
|
335
|
+
const mountedRef = (0, import_react.useRef)(true);
|
|
336
|
+
(0, import_react.useEffect)(() => {
|
|
337
|
+
mountedRef.current = true;
|
|
338
|
+
const dismissed = getDismissedVersion();
|
|
339
|
+
if (dismissed) {
|
|
340
|
+
setIsDismissed(true);
|
|
341
|
+
}
|
|
342
|
+
return () => {
|
|
343
|
+
mountedRef.current = false;
|
|
344
|
+
if (intervalRef.current !== null && typeof window !== "undefined") {
|
|
345
|
+
window.clearInterval(intervalRef.current);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}, []);
|
|
349
|
+
const canUseTauri = typeof window !== "undefined";
|
|
350
|
+
const checkNow = (0, import_react.useCallback)(async () => {
|
|
351
|
+
if (!canUseTauri) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const params = buildParamsFromProvider(provider, currentVersion);
|
|
355
|
+
if (!params) {
|
|
356
|
+
try {
|
|
357
|
+
setIsChecking(true);
|
|
358
|
+
setError(null);
|
|
359
|
+
const manifest = await provider.fetchManifest();
|
|
360
|
+
const platformInfo = Object.values(manifest.platforms)[0];
|
|
361
|
+
if (!platformInfo) {
|
|
362
|
+
if (!silent) {
|
|
363
|
+
setError(new Error("No platform information in manifest"));
|
|
364
|
+
}
|
|
365
|
+
setUpdateInfo(null);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const info = {
|
|
369
|
+
hasUpdate: true,
|
|
370
|
+
currentVersion,
|
|
371
|
+
latestVersion: manifest.version,
|
|
372
|
+
downloadUrl: platformInfo.url,
|
|
373
|
+
releaseNotes: manifest.notes,
|
|
374
|
+
pubDate: manifest.pub_date
|
|
375
|
+
};
|
|
376
|
+
if (!mountedRef.current) return;
|
|
377
|
+
setUpdateInfo(info);
|
|
378
|
+
} catch (e) {
|
|
379
|
+
if (!mountedRef.current) return;
|
|
380
|
+
if (!silent) {
|
|
381
|
+
setError(e instanceof Error ? e : new Error("Failed to check for updates"));
|
|
382
|
+
}
|
|
383
|
+
} finally {
|
|
384
|
+
if (mountedRef.current) {
|
|
385
|
+
setIsChecking(false);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
try {
|
|
391
|
+
setIsChecking(true);
|
|
392
|
+
setError(null);
|
|
393
|
+
const { invoke } = await import("@tauri-apps/api/tauri");
|
|
394
|
+
const result = await invoke("plugin:easy-updater|check_update", {
|
|
395
|
+
params
|
|
396
|
+
});
|
|
397
|
+
if (!mountedRef.current) return;
|
|
398
|
+
const dismissed = getDismissedVersion();
|
|
399
|
+
if (dismissed && dismissed === result.latestVersion) {
|
|
400
|
+
setIsDismissed(true);
|
|
401
|
+
setUpdateInfo(result);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
setUpdateInfo(result);
|
|
405
|
+
} catch (e) {
|
|
406
|
+
if (!mountedRef.current) return;
|
|
407
|
+
if (!silent) {
|
|
408
|
+
setError(e instanceof Error ? e : new Error("Failed to check for updates"));
|
|
409
|
+
}
|
|
410
|
+
} finally {
|
|
411
|
+
if (mountedRef.current) {
|
|
412
|
+
setIsChecking(false);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}, [canUseTauri, provider, currentVersion, silent]);
|
|
416
|
+
(0, import_react.useEffect)(() => {
|
|
417
|
+
if (!checkOnStartup) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
void checkNow();
|
|
421
|
+
}, [checkOnStartup, checkNow]);
|
|
422
|
+
(0, import_react.useEffect)(() => {
|
|
423
|
+
if (checkIntervalMs <= 0 || typeof window === "undefined") {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const id = window.setInterval(() => {
|
|
427
|
+
void checkNow();
|
|
428
|
+
}, checkIntervalMs);
|
|
429
|
+
intervalRef.current = id;
|
|
430
|
+
return () => {
|
|
431
|
+
window.clearInterval(id);
|
|
432
|
+
};
|
|
433
|
+
}, [checkIntervalMs, checkNow]);
|
|
434
|
+
const dismiss = (0, import_react.useCallback)(() => {
|
|
435
|
+
if (updateInfo) {
|
|
436
|
+
setDismissedVersion(updateInfo.latestVersion);
|
|
437
|
+
}
|
|
438
|
+
setIsDismissed(true);
|
|
439
|
+
}, [updateInfo]);
|
|
440
|
+
const value = (0, import_react.useMemo)(
|
|
441
|
+
() => ({
|
|
442
|
+
updateInfo,
|
|
443
|
+
isChecking,
|
|
444
|
+
error,
|
|
445
|
+
checkNow,
|
|
446
|
+
dismiss,
|
|
447
|
+
isDismissed
|
|
448
|
+
}),
|
|
449
|
+
[updateInfo, isChecking, error, checkNow, dismiss, isDismissed]
|
|
450
|
+
);
|
|
451
|
+
return value;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// src/components/UpdateBanner.tsx
|
|
455
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
456
|
+
function resolveTheme(theme = "auto") {
|
|
457
|
+
if (theme === "auto" && typeof window !== "undefined" && "matchMedia" in window) {
|
|
458
|
+
try {
|
|
459
|
+
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
460
|
+
return "dark";
|
|
461
|
+
}
|
|
462
|
+
} catch {
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return theme === "auto" ? "light" : theme;
|
|
466
|
+
}
|
|
467
|
+
async function openUrl(url) {
|
|
468
|
+
if (typeof window === "undefined") return;
|
|
469
|
+
try {
|
|
470
|
+
const { invoke } = await import("@tauri-apps/api/tauri");
|
|
471
|
+
await invoke("plugin:easy-updater|open_url", { url });
|
|
472
|
+
} catch {
|
|
473
|
+
try {
|
|
474
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
475
|
+
} catch {
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function UpdateBanner(props) {
|
|
480
|
+
const { updateInfo, onDismiss, position = "bottom", theme = "auto", className } = props;
|
|
481
|
+
const resolvedTheme = resolveTheme(theme);
|
|
482
|
+
const base = {
|
|
483
|
+
position: "fixed",
|
|
484
|
+
left: 0,
|
|
485
|
+
right: 0,
|
|
486
|
+
display: "flex",
|
|
487
|
+
alignItems: "center",
|
|
488
|
+
justifyContent: "space-between",
|
|
489
|
+
padding: "0.75rem 1rem",
|
|
490
|
+
fontSize: "0.875rem",
|
|
491
|
+
zIndex: 50
|
|
492
|
+
};
|
|
493
|
+
const positionStyle = position === "top" ? {
|
|
494
|
+
top: 0
|
|
495
|
+
} : {
|
|
496
|
+
bottom: 0
|
|
497
|
+
};
|
|
498
|
+
const themeStyle = resolvedTheme === "dark" ? {
|
|
499
|
+
backgroundColor: "rgba(15,23,42,0.95)",
|
|
500
|
+
color: "white",
|
|
501
|
+
borderTop: position === "bottom" ? "1px solid rgba(148,163,184,0.5)" : void 0,
|
|
502
|
+
borderBottom: position === "top" ? "1px solid rgba(148,163,184,0.5)" : void 0
|
|
503
|
+
} : {
|
|
504
|
+
backgroundColor: "rgba(248,250,252,0.98)",
|
|
505
|
+
color: "#020617",
|
|
506
|
+
borderTop: position === "bottom" ? "1px solid #e2e8f0" : void 0,
|
|
507
|
+
borderBottom: position === "top" ? "1px solid #e2e8f0" : void 0
|
|
508
|
+
};
|
|
509
|
+
const buttonStyle = resolvedTheme === "dark" ? {
|
|
510
|
+
backgroundColor: "#22c55e",
|
|
511
|
+
color: "#022c22"
|
|
512
|
+
} : {
|
|
513
|
+
backgroundColor: "#16a34a",
|
|
514
|
+
color: "white"
|
|
515
|
+
};
|
|
516
|
+
const secondaryButtonStyle = resolvedTheme === "dark" ? {
|
|
517
|
+
color: "#e5e7eb"
|
|
518
|
+
} : {
|
|
519
|
+
color: "#4b5563"
|
|
520
|
+
};
|
|
521
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { ...base, ...positionStyle, ...themeStyle }, className, children: [
|
|
522
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "0.125rem" }, children: [
|
|
523
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { fontWeight: 500 }, children: [
|
|
524
|
+
"Nueva versi\xF3n ",
|
|
525
|
+
updateInfo.latestVersion,
|
|
526
|
+
" disponible"
|
|
527
|
+
] }),
|
|
528
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { opacity: 0.8 }, children: [
|
|
529
|
+
"Est\xE1s usando la versi\xF3n ",
|
|
530
|
+
updateInfo.currentVersion,
|
|
531
|
+
". Descarga la \xFAltima actualizaci\xF3n."
|
|
532
|
+
] })
|
|
533
|
+
] }),
|
|
534
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
535
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
536
|
+
"button",
|
|
537
|
+
{
|
|
538
|
+
type: "button",
|
|
539
|
+
style: {
|
|
540
|
+
...buttonStyle,
|
|
541
|
+
borderRadius: "9999px",
|
|
542
|
+
padding: "0.4rem 0.9rem",
|
|
543
|
+
border: "none",
|
|
544
|
+
cursor: "pointer",
|
|
545
|
+
fontSize: "0.875rem",
|
|
546
|
+
fontWeight: 500
|
|
547
|
+
},
|
|
548
|
+
onClick: () => {
|
|
549
|
+
void openUrl(updateInfo.downloadUrl);
|
|
550
|
+
},
|
|
551
|
+
children: "Actualizar ahora"
|
|
552
|
+
}
|
|
553
|
+
),
|
|
554
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
555
|
+
"button",
|
|
556
|
+
{
|
|
557
|
+
type: "button",
|
|
558
|
+
"aria-label": "Cerrar",
|
|
559
|
+
style: {
|
|
560
|
+
...secondaryButtonStyle,
|
|
561
|
+
background: "transparent",
|
|
562
|
+
border: "none",
|
|
563
|
+
cursor: "pointer",
|
|
564
|
+
fontSize: "1rem",
|
|
565
|
+
lineHeight: 1
|
|
566
|
+
},
|
|
567
|
+
onClick: onDismiss,
|
|
568
|
+
children: "\xD7"
|
|
569
|
+
}
|
|
570
|
+
)
|
|
571
|
+
] })
|
|
572
|
+
] });
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/components/UpdateModal.tsx
|
|
576
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
577
|
+
function resolveTheme2(theme = "auto") {
|
|
578
|
+
if (theme === "auto" && typeof window !== "undefined" && "matchMedia" in window) {
|
|
579
|
+
try {
|
|
580
|
+
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
581
|
+
return "dark";
|
|
582
|
+
}
|
|
583
|
+
} catch {
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return theme === "auto" ? "light" : theme;
|
|
587
|
+
}
|
|
588
|
+
async function openUrl2(url) {
|
|
589
|
+
if (typeof window === "undefined") return;
|
|
590
|
+
try {
|
|
591
|
+
const { invoke } = await import("@tauri-apps/api/tauri");
|
|
592
|
+
await invoke("plugin:easy-updater|open_url", { url });
|
|
593
|
+
} catch {
|
|
594
|
+
try {
|
|
595
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
596
|
+
} catch {
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function UpdateModal(props) {
|
|
601
|
+
const { updateInfo, onDismiss, appName, theme = "auto", className } = props;
|
|
602
|
+
const resolvedTheme = resolveTheme2(theme);
|
|
603
|
+
const overlayStyle = {
|
|
604
|
+
position: "fixed",
|
|
605
|
+
inset: 0,
|
|
606
|
+
backgroundColor: "rgba(15,23,42,0.6)",
|
|
607
|
+
display: "flex",
|
|
608
|
+
alignItems: "center",
|
|
609
|
+
justifyContent: "center",
|
|
610
|
+
zIndex: 60
|
|
611
|
+
};
|
|
612
|
+
const modalStyle = resolvedTheme === "dark" ? {
|
|
613
|
+
backgroundColor: "#020617",
|
|
614
|
+
color: "#e5e7eb",
|
|
615
|
+
borderRadius: "0.75rem",
|
|
616
|
+
padding: "1.5rem",
|
|
617
|
+
maxWidth: "28rem",
|
|
618
|
+
width: "100%",
|
|
619
|
+
boxShadow: "0 20px 25px -5px rgba(15,23,42,0.8)"
|
|
620
|
+
} : {
|
|
621
|
+
backgroundColor: "white",
|
|
622
|
+
color: "#0f172a",
|
|
623
|
+
borderRadius: "0.75rem",
|
|
624
|
+
padding: "1.5rem",
|
|
625
|
+
maxWidth: "28rem",
|
|
626
|
+
width: "100%",
|
|
627
|
+
boxShadow: "0 20px 25px -5px rgba(15,23,42,0.2)"
|
|
628
|
+
};
|
|
629
|
+
const primaryButtonStyle = resolvedTheme === "dark" ? {
|
|
630
|
+
backgroundColor: "#22c55e",
|
|
631
|
+
color: "#022c22"
|
|
632
|
+
} : {
|
|
633
|
+
backgroundColor: "#16a34a",
|
|
634
|
+
color: "white"
|
|
635
|
+
};
|
|
636
|
+
const secondaryButtonStyle = resolvedTheme === "dark" ? {
|
|
637
|
+
borderColor: "#4b5563",
|
|
638
|
+
color: "#e5e7eb"
|
|
639
|
+
} : {
|
|
640
|
+
borderColor: "#cbd5f5",
|
|
641
|
+
color: "#1f2937"
|
|
642
|
+
};
|
|
643
|
+
const textMuted = {
|
|
644
|
+
opacity: 0.8,
|
|
645
|
+
fontSize: "0.875rem"
|
|
646
|
+
};
|
|
647
|
+
const title = appName ? `${appName} tiene una nueva versi\xF3n` : "Nueva actualizaci\xF3n disponible";
|
|
648
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: overlayStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: modalStyle, className, children: [
|
|
649
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
650
|
+
"div",
|
|
651
|
+
{
|
|
652
|
+
style: {
|
|
653
|
+
display: "flex",
|
|
654
|
+
justifyContent: "space-between",
|
|
655
|
+
alignItems: "flex-start",
|
|
656
|
+
marginBottom: "0.75rem"
|
|
657
|
+
},
|
|
658
|
+
children: [
|
|
659
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
660
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
661
|
+
"h2",
|
|
662
|
+
{
|
|
663
|
+
style: {
|
|
664
|
+
fontSize: "1.125rem",
|
|
665
|
+
fontWeight: 600,
|
|
666
|
+
margin: 0,
|
|
667
|
+
marginBottom: "0.25rem"
|
|
668
|
+
},
|
|
669
|
+
children: title
|
|
670
|
+
}
|
|
671
|
+
),
|
|
672
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { style: textMuted, children: [
|
|
673
|
+
"Versi\xF3n actual ",
|
|
674
|
+
updateInfo.currentVersion,
|
|
675
|
+
" \xB7 Nueva versi\xF3n ",
|
|
676
|
+
updateInfo.latestVersion
|
|
677
|
+
] })
|
|
678
|
+
] }),
|
|
679
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
680
|
+
"button",
|
|
681
|
+
{
|
|
682
|
+
type: "button",
|
|
683
|
+
"aria-label": "Cerrar",
|
|
684
|
+
onClick: onDismiss,
|
|
685
|
+
style: {
|
|
686
|
+
background: "transparent",
|
|
687
|
+
border: "none",
|
|
688
|
+
cursor: "pointer",
|
|
689
|
+
fontSize: "1rem",
|
|
690
|
+
lineHeight: 1,
|
|
691
|
+
marginLeft: "0.5rem"
|
|
692
|
+
},
|
|
693
|
+
children: "\xD7"
|
|
694
|
+
}
|
|
695
|
+
)
|
|
696
|
+
]
|
|
697
|
+
}
|
|
698
|
+
),
|
|
699
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
700
|
+
"div",
|
|
701
|
+
{
|
|
702
|
+
style: {
|
|
703
|
+
marginTop: "0.75rem",
|
|
704
|
+
marginBottom: "1rem",
|
|
705
|
+
maxHeight: "12rem",
|
|
706
|
+
overflowY: "auto",
|
|
707
|
+
padding: "0.5rem",
|
|
708
|
+
borderRadius: "0.5rem",
|
|
709
|
+
backgroundColor: resolvedTheme === "dark" ? "#020617" : "#f1f5f9",
|
|
710
|
+
fontSize: "0.875rem",
|
|
711
|
+
whiteSpace: "pre-wrap"
|
|
712
|
+
},
|
|
713
|
+
children: updateInfo.releaseNotes || "Esta actualizaci\xF3n incluye mejoras y correcciones de errores."
|
|
714
|
+
}
|
|
715
|
+
),
|
|
716
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
717
|
+
"div",
|
|
718
|
+
{
|
|
719
|
+
style: {
|
|
720
|
+
display: "flex",
|
|
721
|
+
justifyContent: "flex-end",
|
|
722
|
+
gap: "0.5rem",
|
|
723
|
+
marginTop: "0.5rem"
|
|
724
|
+
},
|
|
725
|
+
children: [
|
|
726
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
727
|
+
"button",
|
|
728
|
+
{
|
|
729
|
+
type: "button",
|
|
730
|
+
onClick: onDismiss,
|
|
731
|
+
style: {
|
|
732
|
+
...secondaryButtonStyle,
|
|
733
|
+
background: "transparent",
|
|
734
|
+
padding: "0.45rem 0.9rem",
|
|
735
|
+
borderRadius: "9999px",
|
|
736
|
+
borderWidth: 1,
|
|
737
|
+
borderStyle: "solid",
|
|
738
|
+
cursor: "pointer",
|
|
739
|
+
fontSize: "0.875rem"
|
|
740
|
+
},
|
|
741
|
+
children: "Recordarme despu\xE9s"
|
|
742
|
+
}
|
|
743
|
+
),
|
|
744
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
745
|
+
"button",
|
|
746
|
+
{
|
|
747
|
+
type: "button",
|
|
748
|
+
onClick: () => {
|
|
749
|
+
void openUrl2(updateInfo.downloadUrl);
|
|
750
|
+
},
|
|
751
|
+
style: {
|
|
752
|
+
...primaryButtonStyle,
|
|
753
|
+
padding: "0.45rem 0.9rem",
|
|
754
|
+
borderRadius: "9999px",
|
|
755
|
+
border: "none",
|
|
756
|
+
cursor: "pointer",
|
|
757
|
+
fontSize: "0.875rem",
|
|
758
|
+
fontWeight: 500
|
|
759
|
+
},
|
|
760
|
+
children: "Descargar ahora"
|
|
761
|
+
}
|
|
762
|
+
)
|
|
763
|
+
]
|
|
764
|
+
}
|
|
765
|
+
)
|
|
766
|
+
] }) });
|
|
767
|
+
}
|
|
768
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
769
|
+
0 && (module.exports = {
|
|
770
|
+
UpdateBanner,
|
|
771
|
+
UpdateModal,
|
|
772
|
+
createGitHubProvider,
|
|
773
|
+
createHttpProvider,
|
|
774
|
+
createS3Provider,
|
|
775
|
+
getCurrentPlatform,
|
|
776
|
+
isNewerVersion,
|
|
777
|
+
useUpdateChecker
|
|
778
|
+
});
|
|
779
|
+
//# sourceMappingURL=index.js.map
|