@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.
- package/README.md +29 -21
- package/dist/index.d.mts +191 -102
- package/dist/index.d.ts +191 -102
- package/dist/index.js +946 -645
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +925 -639
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +106 -0
- package/dist/react/index.d.ts +106 -0
- package/dist/react/index.js +1349 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +1303 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/types-DEGEuQ-i.d.mts +237 -0
- package/dist/types-DEGEuQ-i.d.ts +237 -0
- package/package.json +48 -10
package/dist/index.mjs
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var UpdaterError = class _UpdaterError extends Error {
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "UpdaterError";
|
|
6
|
+
this.code = code;
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
static fromUnknown(err) {
|
|
9
|
+
if (err instanceof _UpdaterError) {
|
|
10
|
+
return err;
|
|
11
|
+
}
|
|
12
|
+
if (err && typeof err === "object") {
|
|
13
|
+
const obj = err;
|
|
14
|
+
if (typeof obj.code === "string" && typeof obj.message === "string") {
|
|
15
|
+
return new _UpdaterError(obj.code, obj.message);
|
|
16
|
+
}
|
|
17
|
+
if (err instanceof Error) {
|
|
18
|
+
return new _UpdaterError("UNKNOWN_ERROR", err.message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (typeof err === "string") {
|
|
22
|
+
return new _UpdaterError("UNKNOWN_ERROR", err);
|
|
23
|
+
}
|
|
24
|
+
return new _UpdaterError("UNKNOWN_ERROR", "An unexpected updater error occurred");
|
|
18
25
|
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/utils/platform.ts
|
|
29
|
+
function isTauriRuntime() {
|
|
30
|
+
if (typeof window === "undefined") return false;
|
|
31
|
+
return "__TAURI_INTERNALS__" in window || "__TAURI__" in window;
|
|
19
32
|
}
|
|
20
33
|
function normalizeOs(os) {
|
|
21
|
-
const lower = os.toLowerCase();
|
|
34
|
+
const lower = os.trim().toLowerCase();
|
|
22
35
|
if (lower.startsWith("win")) return "windows";
|
|
23
|
-
if (lower.startsWith("mac")) return "darwin";
|
|
36
|
+
if (lower.startsWith("darwin") || lower.startsWith("mac")) return "darwin";
|
|
24
37
|
if (lower.startsWith("linux")) return "linux";
|
|
25
38
|
return "";
|
|
26
39
|
}
|
|
27
40
|
function normalizeArch(arch) {
|
|
28
|
-
const lower = arch.toLowerCase();
|
|
41
|
+
const lower = arch.trim().toLowerCase();
|
|
29
42
|
if (lower === "x86_64" || lower === "x64" || lower === "amd64") {
|
|
30
43
|
return "x86_64";
|
|
31
44
|
}
|
|
@@ -34,702 +47,975 @@ function normalizeArch(arch) {
|
|
|
34
47
|
}
|
|
35
48
|
return "";
|
|
36
49
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
function inferInstallerFormat(urlOrFilename) {
|
|
51
|
+
const clean = urlOrFilename.split("?")[0]?.toLowerCase() ?? "";
|
|
52
|
+
if (clean.endsWith(".exe")) return "nsis";
|
|
53
|
+
if (clean.endsWith(".msi")) return "msi";
|
|
54
|
+
if (clean.endsWith(".dmg")) return "dmg";
|
|
55
|
+
if (clean.endsWith(".pkg")) return "pkg";
|
|
56
|
+
if (clean.endsWith(".appimage")) return "appimage";
|
|
57
|
+
if (clean.endsWith(".deb")) return "deb";
|
|
58
|
+
if (clean.endsWith(".rpm")) return "rpm";
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
async function getPlatformSummary() {
|
|
62
|
+
if (typeof window === "undefined") {
|
|
47
63
|
return null;
|
|
48
64
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
if (isTauriRuntime()) {
|
|
66
|
+
try {
|
|
67
|
+
const { invoke } = await import("@tauri-apps/api/core");
|
|
68
|
+
return await invoke("plugin:easy-updater|get_platform");
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
55
71
|
}
|
|
72
|
+
const ua = typeof navigator !== "undefined" ? navigator.userAgent : "";
|
|
73
|
+
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
|
|
74
|
+
const combined = `${platform} ${ua}`.toLowerCase();
|
|
75
|
+
let os = "";
|
|
76
|
+
if (combined.includes("win")) os = "windows";
|
|
77
|
+
else if (combined.includes("mac") || combined.includes("darwin")) os = "darwin";
|
|
78
|
+
else if (combined.includes("linux")) os = "linux";
|
|
79
|
+
if (!os) return null;
|
|
80
|
+
const isArm = combined.includes("arm64") || combined.includes("aarch64");
|
|
81
|
+
const arch = isArm ? "aarch64" : "x86_64";
|
|
82
|
+
const supportedFormats = os === "windows" ? ["nsis", "msi"] : os === "darwin" ? ["dmg", "pkg"] : ["appimage", "deb", "rpm"];
|
|
56
83
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
84
|
+
os,
|
|
85
|
+
arch,
|
|
86
|
+
key: `${os}-${arch}`,
|
|
87
|
+
supportedFormats
|
|
61
88
|
};
|
|
62
89
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const bi = bParts[i];
|
|
73
|
-
if (ai === void 0) return -1;
|
|
74
|
-
if (bi === void 0) return 1;
|
|
75
|
-
const aNum = Number(ai);
|
|
76
|
-
const bNum = Number(bi);
|
|
77
|
-
const aIsNum = Number.isFinite(aNum);
|
|
78
|
-
const bIsNum = Number.isFinite(bNum);
|
|
79
|
-
if (aIsNum && bIsNum) {
|
|
80
|
-
if (aNum > bNum) return 1;
|
|
81
|
-
if (aNum < bNum) return -1;
|
|
82
|
-
} else if (aIsNum && !bIsNum) {
|
|
83
|
-
return -1;
|
|
84
|
-
} else if (!aIsNum && bIsNum) {
|
|
85
|
-
return 1;
|
|
86
|
-
} else {
|
|
87
|
-
if (ai > bi) return 1;
|
|
88
|
-
if (ai < bi) return -1;
|
|
89
|
-
}
|
|
90
|
+
async function getCurrentPlatform() {
|
|
91
|
+
const summary = await getPlatformSummary();
|
|
92
|
+
return summary?.key ?? "";
|
|
93
|
+
}
|
|
94
|
+
function selectPlatformFromManifest(manifest, platformKey) {
|
|
95
|
+
if (!platformKey) return null;
|
|
96
|
+
const direct = manifest.platforms[platformKey];
|
|
97
|
+
if (direct) {
|
|
98
|
+
return { key: platformKey, entry: direct };
|
|
90
99
|
}
|
|
91
|
-
|
|
100
|
+
if (platformKey.startsWith("darwin-") && manifest.platforms["darwin-universal"]) {
|
|
101
|
+
return { key: "darwin-universal", entry: manifest.platforms["darwin-universal"] };
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
92
104
|
}
|
|
93
|
-
function
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
function resolveArtifactsFromPlatform(entry, preferredFormat) {
|
|
106
|
+
const defaultPrimary = {
|
|
107
|
+
format: entry.format ?? inferInstallerFormat(entry.url),
|
|
108
|
+
url: entry.url,
|
|
109
|
+
sha256: entry.sha256 ?? null,
|
|
110
|
+
size: entry.size ?? null,
|
|
111
|
+
signature: entry.signature ?? null
|
|
112
|
+
};
|
|
113
|
+
const all = (entry.artifacts ?? []).map((a) => ({
|
|
114
|
+
format: a.format,
|
|
115
|
+
url: a.url,
|
|
116
|
+
sha256: a.sha256 ?? null,
|
|
117
|
+
size: a.size ?? null,
|
|
118
|
+
signature: a.signature ?? null
|
|
119
|
+
}));
|
|
120
|
+
if (all.length === 0) {
|
|
121
|
+
all.push(defaultPrimary);
|
|
122
|
+
} else if (!all.some((a) => a.url === defaultPrimary.url)) {
|
|
123
|
+
all.unshift(defaultPrimary);
|
|
124
|
+
}
|
|
125
|
+
const primary = preferredFormat ? all.find((a) => a.format === preferredFormat) ?? defaultPrimary : defaultPrimary;
|
|
126
|
+
return { primary, all };
|
|
101
127
|
}
|
|
102
128
|
|
|
103
|
-
// src/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
type: "github",
|
|
115
|
-
async fetchManifest() {
|
|
116
|
-
try {
|
|
117
|
-
const res = await fetch(manifestUrl);
|
|
118
|
-
if (res.ok) {
|
|
119
|
-
const data = await res.json();
|
|
120
|
-
return data;
|
|
121
|
-
}
|
|
122
|
-
if (!fallbackToReleaseApi || res.status !== 404) {
|
|
123
|
-
throw new Error(`GitHub manifest request failed with status ${res.status}`);
|
|
124
|
-
}
|
|
125
|
-
} catch (err) {
|
|
126
|
-
if (!fallbackToReleaseApi) {
|
|
127
|
-
throw err instanceof Error ? err : new Error("Failed to fetch GitHub manifest");
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
const res = await fetch(apiUrl, {
|
|
132
|
-
headers: {
|
|
133
|
-
Accept: "application/vnd.github+json"
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
if (!res.ok) {
|
|
137
|
-
throw new Error(`GitHub releases API failed with status ${res.status}`);
|
|
138
|
-
}
|
|
139
|
-
const release = await res.json();
|
|
140
|
-
const platform = await getCurrentPlatform();
|
|
141
|
-
let url = "";
|
|
142
|
-
if (platform) {
|
|
143
|
-
const asset = selectAssetForPlatform(release.assets, platform);
|
|
144
|
-
if (asset) {
|
|
145
|
-
url = asset.browser_download_url;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const manifest = {
|
|
149
|
-
version: release.tag_name,
|
|
150
|
-
pub_date: release.published_at,
|
|
151
|
-
notes: release.body ?? "",
|
|
152
|
-
platforms: url ? {
|
|
153
|
-
[platform]: {
|
|
154
|
-
url
|
|
155
|
-
}
|
|
156
|
-
} : {}
|
|
157
|
-
};
|
|
158
|
-
return manifest;
|
|
159
|
-
} catch (error) {
|
|
160
|
-
throw error instanceof Error ? error : new Error("Failed to fetch GitHub release");
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
provider.__tauriParams = {
|
|
165
|
-
github_owner: owner,
|
|
166
|
-
github_repo: repo,
|
|
167
|
-
manifest_url: manifestUrl
|
|
168
|
-
};
|
|
169
|
-
return provider;
|
|
129
|
+
// src/utils/security.ts
|
|
130
|
+
var FORBIDDEN_URL_SYMBOLS = /[\s&|^<>;"'`\\$(){}!]/;
|
|
131
|
+
var GITHUB_IDENT_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/;
|
|
132
|
+
var SHA256_HEX_RE = /^[a-fA-F0-9]{64}$/;
|
|
133
|
+
function hasForbiddenUrlChars(rawUrl) {
|
|
134
|
+
if (FORBIDDEN_URL_SYMBOLS.test(rawUrl)) return true;
|
|
135
|
+
for (let i = 0; i < rawUrl.length; i += 1) {
|
|
136
|
+
const code = rawUrl.charCodeAt(i);
|
|
137
|
+
if (code <= 31 || code === 127) return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
170
140
|
}
|
|
171
|
-
function
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
141
|
+
function isSafeRemoteUrl(rawUrl, allowInsecureHttp = false) {
|
|
142
|
+
if (typeof rawUrl !== "string" || rawUrl.length === 0) return false;
|
|
143
|
+
if (rawUrl.startsWith("-")) return false;
|
|
144
|
+
if (hasForbiddenUrlChars(rawUrl)) return false;
|
|
145
|
+
try {
|
|
146
|
+
const parsed = new URL(rawUrl);
|
|
147
|
+
const schemeAllowed = parsed.protocol === "https:" || allowInsecureHttp && parsed.protocol === "http:";
|
|
148
|
+
if (!schemeAllowed) return false;
|
|
149
|
+
if (parsed.username || parsed.password) return false;
|
|
150
|
+
if (!parsed.hostname) return false;
|
|
151
|
+
return true;
|
|
152
|
+
} catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function assertSafeRemoteUrl(rawUrl, allowInsecureHttp = false) {
|
|
157
|
+
if (!isSafeRemoteUrl(rawUrl, allowInsecureHttp)) {
|
|
158
|
+
throw new UpdaterError(
|
|
159
|
+
rawUrl.startsWith("http://") ? "INSECURE_SCHEME" : "INVALID_URL",
|
|
160
|
+
`Blocked unsafe or non-HTTPS URL: ${rawUrl.slice(0, 120)}`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return rawUrl;
|
|
164
|
+
}
|
|
165
|
+
function assertValidGitHubIdent(value, fieldName) {
|
|
166
|
+
if (typeof value !== "string" || !GITHUB_IDENT_RE.test(value) || value === "." || value === ".." || value.includes("..")) {
|
|
167
|
+
throw new UpdaterError(
|
|
168
|
+
"INVALID_INPUT",
|
|
169
|
+
`Invalid GitHub ${fieldName}: must match [A-Za-z0-9][A-Za-z0-9_.-]* without '..'`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function validateManifest(data, allowInsecureHttp = false) {
|
|
174
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
175
|
+
throw new UpdaterError("INVALID_MANIFEST", "Manifest must be a JSON object");
|
|
176
|
+
}
|
|
177
|
+
const obj = data;
|
|
178
|
+
if (typeof obj.version !== "string" || !obj.version.trim()) {
|
|
179
|
+
throw new UpdaterError("INVALID_MANIFEST", 'Manifest is missing a valid "version" string');
|
|
180
|
+
}
|
|
181
|
+
if (!obj.platforms || typeof obj.platforms !== "object" || Array.isArray(obj.platforms)) {
|
|
182
|
+
throw new UpdaterError("INVALID_MANIFEST", 'Manifest is missing a valid "platforms" map');
|
|
183
|
+
}
|
|
184
|
+
const platforms = obj.platforms;
|
|
185
|
+
for (const [key, entry] of Object.entries(platforms)) {
|
|
186
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
187
|
+
throw new UpdaterError("INVALID_MANIFEST", `Platform "${key}" must be an object`);
|
|
181
188
|
}
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
const p = entry;
|
|
190
|
+
if (typeof p.url !== "string" || !isSafeRemoteUrl(p.url, allowInsecureHttp)) {
|
|
191
|
+
throw new UpdaterError(
|
|
192
|
+
"INVALID_MANIFEST",
|
|
193
|
+
`Platform "${key}" has an invalid or non-HTTPS download URL`
|
|
194
|
+
);
|
|
184
195
|
}
|
|
185
|
-
if (
|
|
186
|
-
|
|
196
|
+
if (p.sha256 !== void 0 && (typeof p.sha256 !== "string" || !SHA256_HEX_RE.test(p.sha256))) {
|
|
197
|
+
throw new UpdaterError(
|
|
198
|
+
"INVALID_MANIFEST",
|
|
199
|
+
`Platform "${key}" has an invalid sha256 digest`
|
|
200
|
+
);
|
|
187
201
|
}
|
|
188
|
-
|
|
189
|
-
|
|
202
|
+
}
|
|
203
|
+
return data;
|
|
190
204
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
202
|
-
try {
|
|
203
|
-
const res = await fetch(manifestUrl, init);
|
|
204
|
-
if (!res.ok) {
|
|
205
|
-
throw new Error(`HTTP ${res.status}`);
|
|
206
|
-
}
|
|
207
|
-
const data = await res.json();
|
|
208
|
-
return data;
|
|
209
|
-
} catch (error) {
|
|
210
|
-
throw error instanceof Error ? error : new Error("Failed to fetch update manifest");
|
|
211
|
-
}
|
|
205
|
+
async function fetchWithTimeout(url, init = {}, timeoutMs = 15e3) {
|
|
206
|
+
const controller = new AbortController();
|
|
207
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
208
|
+
try {
|
|
209
|
+
return await fetch(url, {
|
|
210
|
+
...init,
|
|
211
|
+
signal: controller.signal
|
|
212
|
+
});
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
215
|
+
throw new UpdaterError("TIMEOUT", `Request timed out after ${timeoutMs}ms`);
|
|
212
216
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
throw new UpdaterError(
|
|
218
|
+
"NETWORK_ERROR",
|
|
219
|
+
err instanceof Error ? err.message : "Network request failed"
|
|
220
|
+
);
|
|
221
|
+
} finally {
|
|
222
|
+
clearTimeout(timer);
|
|
223
|
+
}
|
|
216
224
|
}
|
|
217
225
|
|
|
218
|
-
// src/
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
// src/utils/semver.ts
|
|
227
|
+
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-]+)*))?$/;
|
|
228
|
+
var NUMERIC_IDENT_RE = /^(0|[1-9]\d*)$/;
|
|
229
|
+
function parseSemver(input) {
|
|
230
|
+
if (typeof input !== "string") return null;
|
|
231
|
+
const trimmed = input.trim();
|
|
232
|
+
const match = STRICT_SEMVER_RE.exec(trimmed);
|
|
233
|
+
if (!match) return null;
|
|
234
|
+
const major = Number(match[1]);
|
|
235
|
+
const minor = Number(match[2]);
|
|
236
|
+
const patch = Number(match[3]);
|
|
237
|
+
if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
const prerelease = match[4] ? match[4].split(".") : [];
|
|
241
|
+
const build = match[5] ?? null;
|
|
242
|
+
return { major, minor, patch, prerelease, build };
|
|
243
|
+
}
|
|
244
|
+
function comparePrerelease(a, b) {
|
|
245
|
+
const aEmpty = a.length === 0;
|
|
246
|
+
const bEmpty = b.length === 0;
|
|
247
|
+
if (aEmpty && bEmpty) return 0;
|
|
248
|
+
if (aEmpty) return 1;
|
|
249
|
+
if (bEmpty) return -1;
|
|
250
|
+
const len = Math.max(a.length, b.length);
|
|
251
|
+
for (let i = 0; i < len; i += 1) {
|
|
252
|
+
const ai = a[i];
|
|
253
|
+
const bi = b[i];
|
|
254
|
+
if (ai === void 0) return -1;
|
|
255
|
+
if (bi === void 0) return 1;
|
|
256
|
+
if (ai === bi) continue;
|
|
257
|
+
const aNum = NUMERIC_IDENT_RE.test(ai);
|
|
258
|
+
const bNum = NUMERIC_IDENT_RE.test(bi);
|
|
259
|
+
if (aNum && bNum) {
|
|
260
|
+
const av = BigInt(ai);
|
|
261
|
+
const bv = BigInt(bi);
|
|
262
|
+
if (av > bv) return 1;
|
|
263
|
+
if (av < bv) return -1;
|
|
264
|
+
} else if (aNum && !bNum) {
|
|
265
|
+
return -1;
|
|
266
|
+
} else if (!aNum && bNum) {
|
|
267
|
+
return 1;
|
|
268
|
+
} else {
|
|
269
|
+
return ai > bi ? 1 : -1;
|
|
227
270
|
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
271
|
+
}
|
|
272
|
+
return 0;
|
|
273
|
+
}
|
|
274
|
+
function compareSemver(a, b) {
|
|
275
|
+
const pa = parseSemver(a);
|
|
276
|
+
const pb = parseSemver(b);
|
|
277
|
+
if (!pa || !pb) return null;
|
|
278
|
+
if (pa.major !== pb.major) return pa.major > pb.major ? 1 : -1;
|
|
279
|
+
if (pa.minor !== pb.minor) return pa.minor > pb.minor ? 1 : -1;
|
|
280
|
+
if (pa.patch !== pb.patch) return pa.patch > pb.patch ? 1 : -1;
|
|
281
|
+
const pre = comparePrerelease(pa.prerelease, pb.prerelease);
|
|
282
|
+
if (pre > 0) return 1;
|
|
283
|
+
if (pre < 0) return -1;
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
function isNewerVersion(latest, current) {
|
|
287
|
+
return compareSemver(latest, current) === 1;
|
|
288
|
+
}
|
|
289
|
+
function isBelowMinVersion(current, minVersion) {
|
|
290
|
+
return compareSemver(current, minVersion) === -1;
|
|
231
291
|
}
|
|
232
292
|
|
|
233
|
-
// src/
|
|
234
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
293
|
+
// src/client.ts
|
|
235
294
|
var SESSION_DISMISS_KEY = "tauri-easy-updater:dismissed-version";
|
|
236
|
-
|
|
295
|
+
var PROGRESS_EVENT_NAME = "easy-updater://download-progress";
|
|
296
|
+
function defaultStorage() {
|
|
237
297
|
if (typeof window === "undefined") return null;
|
|
238
298
|
try {
|
|
239
|
-
return window.sessionStorage
|
|
299
|
+
return window.sessionStorage;
|
|
240
300
|
} catch {
|
|
241
301
|
return null;
|
|
242
302
|
}
|
|
243
303
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
304
|
+
var UpdaterClient = class {
|
|
305
|
+
constructor(config = {}) {
|
|
306
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
307
|
+
this.state = {
|
|
308
|
+
status: "idle",
|
|
309
|
+
updateInfo: null,
|
|
310
|
+
progress: null,
|
|
311
|
+
downloadResult: null,
|
|
312
|
+
error: null,
|
|
313
|
+
isDismissed: false,
|
|
314
|
+
lastCheckedAt: null
|
|
315
|
+
};
|
|
316
|
+
this.inFlightCheck = null;
|
|
317
|
+
this.activeDownloadId = null;
|
|
318
|
+
this.pollTimer = null;
|
|
319
|
+
this.unlistenProgress = null;
|
|
320
|
+
this.disposed = false;
|
|
321
|
+
this.config = config;
|
|
322
|
+
this.storage = config.storage ?? defaultStorage();
|
|
249
323
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const base = {
|
|
254
|
-
current_version: currentVersion,
|
|
255
|
-
manifest_url: ""
|
|
256
|
-
};
|
|
257
|
-
if (!anyProvider.__tauriParams) {
|
|
258
|
-
return null;
|
|
324
|
+
/** Returns the current immutable state snapshot. */
|
|
325
|
+
getState() {
|
|
326
|
+
return this.state;
|
|
259
327
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
github_owner,
|
|
266
|
-
github_repo
|
|
328
|
+
/** Subscribes to state transitions. Returns an unsubscribe function. */
|
|
329
|
+
subscribe(listener) {
|
|
330
|
+
this.listeners.add(listener);
|
|
331
|
+
return () => {
|
|
332
|
+
this.listeners.delete(listener);
|
|
267
333
|
};
|
|
268
334
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
};
|
|
335
|
+
/** Starts periodic update checks (`intervalMs > 0`). */
|
|
336
|
+
startPolling(intervalMs) {
|
|
337
|
+
this.stopPolling();
|
|
338
|
+
if (intervalMs <= 0 || this.disposed) return;
|
|
339
|
+
this.pollTimer = setInterval(() => {
|
|
340
|
+
void this.check();
|
|
341
|
+
}, intervalMs);
|
|
276
342
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
provider,
|
|
283
|
-
checkOnStartup = true,
|
|
284
|
-
checkIntervalMs = 0,
|
|
285
|
-
silent = false
|
|
286
|
-
} = config;
|
|
287
|
-
const [updateInfo, setUpdateInfo] = useState(null);
|
|
288
|
-
const [isChecking, setIsChecking] = useState(false);
|
|
289
|
-
const [error, setError] = useState(null);
|
|
290
|
-
const [isDismissed, setIsDismissed] = useState(false);
|
|
291
|
-
const intervalRef = useRef(null);
|
|
292
|
-
const mountedRef = useRef(true);
|
|
293
|
-
useEffect(() => {
|
|
294
|
-
mountedRef.current = true;
|
|
295
|
-
const dismissed = getDismissedVersion();
|
|
296
|
-
if (dismissed) {
|
|
297
|
-
setIsDismissed(true);
|
|
343
|
+
/** Stops periodic update checks. */
|
|
344
|
+
stopPolling() {
|
|
345
|
+
if (this.pollTimer !== null) {
|
|
346
|
+
clearInterval(this.pollTimer);
|
|
347
|
+
this.pollTimer = null;
|
|
298
348
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
349
|
+
}
|
|
350
|
+
/** Releases timers and Tauri event listeners. */
|
|
351
|
+
dispose() {
|
|
352
|
+
this.disposed = true;
|
|
353
|
+
this.stopPolling();
|
|
354
|
+
this.detachProgressListener();
|
|
355
|
+
this.listeners.clear();
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Checks for an available update. Concurrent calls share the same in-flight promise.
|
|
359
|
+
*/
|
|
360
|
+
async check() {
|
|
361
|
+
if (this.disposed) return null;
|
|
362
|
+
if (this.inFlightCheck) {
|
|
363
|
+
return this.inFlightCheck;
|
|
364
|
+
}
|
|
365
|
+
const promise = this.performCheck().finally(() => {
|
|
366
|
+
this.inFlightCheck = null;
|
|
367
|
+
});
|
|
368
|
+
this.inFlightCheck = promise;
|
|
369
|
+
return promise;
|
|
370
|
+
}
|
|
371
|
+
async performCheck() {
|
|
372
|
+
this.setState({
|
|
373
|
+
status: "checking",
|
|
374
|
+
error: null
|
|
375
|
+
});
|
|
376
|
+
try {
|
|
377
|
+
const info = await this.fetchUpdateInfo();
|
|
378
|
+
if (this.disposed) return null;
|
|
379
|
+
const dismissedVersion = this.readDismissedVersion();
|
|
380
|
+
const isDismissed = !info.mandatory && Boolean(dismissedVersion) && dismissedVersion === info.latestVersion;
|
|
381
|
+
this.setState({
|
|
382
|
+
status: info.hasUpdate ? "available" : "up-to-date",
|
|
383
|
+
updateInfo: info,
|
|
384
|
+
isDismissed,
|
|
385
|
+
error: null,
|
|
386
|
+
lastCheckedAt: Date.now()
|
|
387
|
+
});
|
|
388
|
+
return info;
|
|
389
|
+
} catch (rawErr) {
|
|
390
|
+
if (this.disposed) return null;
|
|
391
|
+
const err = UpdaterError.fromUnknown(rawErr);
|
|
392
|
+
if (this.config.silent) {
|
|
393
|
+
this.setState({
|
|
394
|
+
status: this.state.updateInfo?.hasUpdate ? "available" : "idle",
|
|
395
|
+
error: null
|
|
396
|
+
});
|
|
397
|
+
} else {
|
|
398
|
+
this.setState({
|
|
399
|
+
status: "error",
|
|
400
|
+
error: err
|
|
401
|
+
});
|
|
303
402
|
}
|
|
304
|
-
|
|
305
|
-
}, []);
|
|
306
|
-
const canUseTauri = typeof window !== "undefined";
|
|
307
|
-
const checkNow = useCallback(async () => {
|
|
308
|
-
if (!canUseTauri) {
|
|
309
|
-
return;
|
|
403
|
+
return null;
|
|
310
404
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
setUpdateInfo(null);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const info = {
|
|
326
|
-
hasUpdate: true,
|
|
327
|
-
currentVersion,
|
|
328
|
-
latestVersion: manifest.version,
|
|
329
|
-
downloadUrl: platformInfo.url,
|
|
330
|
-
releaseNotes: manifest.notes,
|
|
331
|
-
pubDate: manifest.pub_date
|
|
332
|
-
};
|
|
333
|
-
if (!mountedRef.current) return;
|
|
334
|
-
setUpdateInfo(info);
|
|
335
|
-
} catch (e) {
|
|
336
|
-
if (!mountedRef.current) return;
|
|
337
|
-
if (!silent) {
|
|
338
|
-
setError(e instanceof Error ? e : new Error("Failed to check for updates"));
|
|
339
|
-
}
|
|
340
|
-
} finally {
|
|
341
|
-
if (mountedRef.current) {
|
|
342
|
-
setIsChecking(false);
|
|
343
|
-
}
|
|
405
|
+
}
|
|
406
|
+
async fetchUpdateInfo() {
|
|
407
|
+
const provider = this.config.provider;
|
|
408
|
+
const useTauriPlugin = isTauriRuntime() && (!provider || Boolean(provider.tauriParams));
|
|
409
|
+
if (useTauriPlugin) {
|
|
410
|
+
const { invoke } = await import("@tauri-apps/api/core");
|
|
411
|
+
const params = {
|
|
412
|
+
...provider?.tauriParams ?? {}
|
|
413
|
+
};
|
|
414
|
+
if (this.config.currentVersion) {
|
|
415
|
+
params.currentVersion = this.config.currentVersion;
|
|
344
416
|
}
|
|
345
|
-
|
|
417
|
+
if (this.config.channel) {
|
|
418
|
+
params.channel = this.config.channel;
|
|
419
|
+
}
|
|
420
|
+
if (this.config.preferredFormat) {
|
|
421
|
+
params.preferredFormat = this.config.preferredFormat;
|
|
422
|
+
}
|
|
423
|
+
return await invoke("plugin:easy-updater|check_update", { params });
|
|
424
|
+
}
|
|
425
|
+
if (!provider) {
|
|
426
|
+
throw new UpdaterError(
|
|
427
|
+
"INVALID_INPUT",
|
|
428
|
+
"A provider is required when running outside a Tauri v2 runtime"
|
|
429
|
+
);
|
|
346
430
|
}
|
|
431
|
+
if (!this.config.currentVersion) {
|
|
432
|
+
throw new UpdaterError(
|
|
433
|
+
"INVALID_INPUT",
|
|
434
|
+
"currentVersion is required when using pure JS fallback outside Tauri"
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
const manifest = await provider.fetchManifest();
|
|
438
|
+
const currentVersion = this.config.currentVersion;
|
|
439
|
+
const cmp = compareSemver(manifest.version, currentVersion);
|
|
440
|
+
if (cmp === null) {
|
|
441
|
+
throw new UpdaterError(
|
|
442
|
+
"INVALID_VERSION",
|
|
443
|
+
`Unable to compare versions "${manifest.version}" and "${currentVersion}"`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
if (cmp < 0) {
|
|
447
|
+
throw new UpdaterError(
|
|
448
|
+
"DOWNGRADE_BLOCKED",
|
|
449
|
+
`Downgrade blocked: target ${manifest.version} is older than ${currentVersion}`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
const hasUpdate = isNewerVersion(manifest.version, currentVersion);
|
|
453
|
+
const belowMin = manifest.min_version ? isBelowMinVersion(currentVersion, manifest.min_version) : false;
|
|
454
|
+
const mandatory = hasUpdate && (Boolean(manifest.mandatory) || belowMin);
|
|
455
|
+
const platformKey = await getCurrentPlatform();
|
|
456
|
+
const matched = selectPlatformFromManifest(manifest, platformKey);
|
|
457
|
+
if (!matched) {
|
|
458
|
+
if (hasUpdate) {
|
|
459
|
+
throw new UpdaterError(
|
|
460
|
+
"PLATFORM_NOT_FOUND",
|
|
461
|
+
`No update artifact available for platform "${platformKey || "unknown"}"`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
hasUpdate: false,
|
|
466
|
+
currentVersion,
|
|
467
|
+
latestVersion: manifest.version,
|
|
468
|
+
channel: manifest.channel ?? this.config.channel ?? "stable",
|
|
469
|
+
mandatory: false,
|
|
470
|
+
minVersion: manifest.min_version ?? null,
|
|
471
|
+
platform: platformKey,
|
|
472
|
+
downloadUrl: null,
|
|
473
|
+
sha256: null,
|
|
474
|
+
size: null,
|
|
475
|
+
format: null,
|
|
476
|
+
signature: null,
|
|
477
|
+
verifiedManifest: false,
|
|
478
|
+
artifacts: [],
|
|
479
|
+
releaseNotes: manifest.notes ?? "",
|
|
480
|
+
pubDate: manifest.pub_date ?? ""
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const { primary, all } = resolveArtifactsFromPlatform(
|
|
484
|
+
matched.entry,
|
|
485
|
+
this.config.preferredFormat
|
|
486
|
+
);
|
|
487
|
+
assertSafeRemoteUrl(primary.url, Boolean(this.config.allowInsecureHttp));
|
|
488
|
+
return {
|
|
489
|
+
hasUpdate,
|
|
490
|
+
currentVersion,
|
|
491
|
+
latestVersion: manifest.version,
|
|
492
|
+
channel: manifest.channel ?? this.config.channel ?? "stable",
|
|
493
|
+
mandatory,
|
|
494
|
+
minVersion: manifest.min_version ?? null,
|
|
495
|
+
platform: matched.key,
|
|
496
|
+
downloadUrl: primary.url,
|
|
497
|
+
sha256: primary.sha256,
|
|
498
|
+
size: primary.size,
|
|
499
|
+
format: primary.format,
|
|
500
|
+
signature: primary.signature,
|
|
501
|
+
verifiedManifest: false,
|
|
502
|
+
artifacts: all,
|
|
503
|
+
releaseNotes: manifest.notes ?? "",
|
|
504
|
+
pubDate: manifest.pub_date ?? ""
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Downloads and verifies the currently available update inside Tauri (streaming + SHA-256/Ed25519).
|
|
509
|
+
*/
|
|
510
|
+
async download(overrideInfo) {
|
|
511
|
+
const info = overrideInfo ?? this.state.updateInfo;
|
|
512
|
+
if (!info?.downloadUrl) {
|
|
513
|
+
throw new UpdaterError("INVALID_INPUT", "No downloadable update is currently available");
|
|
514
|
+
}
|
|
515
|
+
if (!isTauriRuntime()) {
|
|
516
|
+
throw new UpdaterError(
|
|
517
|
+
"INVALID_INPUT",
|
|
518
|
+
"In-app verified downloads require the Tauri v2 runtime; use openDownloadUrl() on the web"
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
const downloadId = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `dl-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
522
|
+
this.activeDownloadId = downloadId;
|
|
523
|
+
this.setState({
|
|
524
|
+
status: "downloading",
|
|
525
|
+
error: null,
|
|
526
|
+
downloadResult: null,
|
|
527
|
+
progress: {
|
|
528
|
+
downloadId,
|
|
529
|
+
downloadedBytes: 0,
|
|
530
|
+
totalBytes: info.size,
|
|
531
|
+
percent: info.size ? 0 : null,
|
|
532
|
+
stage: "started"
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
await this.attachProgressListener(downloadId);
|
|
347
536
|
try {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
537
|
+
const { invoke } = await import("@tauri-apps/api/core");
|
|
538
|
+
const result = await invoke("plugin:easy-updater|download_update", {
|
|
539
|
+
params: {
|
|
540
|
+
url: info.downloadUrl,
|
|
541
|
+
version: info.latestVersion,
|
|
542
|
+
platform: info.platform,
|
|
543
|
+
sha256: info.sha256,
|
|
544
|
+
expectedSize: info.size,
|
|
545
|
+
signature: info.signature,
|
|
546
|
+
format: info.format,
|
|
547
|
+
downloadId
|
|
548
|
+
}
|
|
353
549
|
});
|
|
354
|
-
if (!
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
550
|
+
if (!this.disposed) {
|
|
551
|
+
this.setState({
|
|
552
|
+
status: "ready",
|
|
553
|
+
downloadResult: result,
|
|
554
|
+
progress: {
|
|
555
|
+
downloadId: result.downloadId,
|
|
556
|
+
downloadedBytes: result.size,
|
|
557
|
+
totalBytes: result.size,
|
|
558
|
+
percent: 100,
|
|
559
|
+
stage: "completed"
|
|
560
|
+
},
|
|
561
|
+
error: null
|
|
562
|
+
});
|
|
360
563
|
}
|
|
361
|
-
|
|
362
|
-
} catch (
|
|
363
|
-
|
|
364
|
-
if (!
|
|
365
|
-
|
|
564
|
+
return result;
|
|
565
|
+
} catch (rawErr) {
|
|
566
|
+
const err = UpdaterError.fromUnknown(rawErr);
|
|
567
|
+
if (!this.disposed) {
|
|
568
|
+
if (err.code === "DOWNLOAD_CANCELLED") {
|
|
569
|
+
this.setState({
|
|
570
|
+
status: "available",
|
|
571
|
+
progress: null,
|
|
572
|
+
error: null
|
|
573
|
+
});
|
|
574
|
+
} else {
|
|
575
|
+
this.setState({
|
|
576
|
+
status: "error",
|
|
577
|
+
error: err
|
|
578
|
+
});
|
|
579
|
+
}
|
|
366
580
|
}
|
|
581
|
+
throw err;
|
|
367
582
|
} finally {
|
|
368
|
-
|
|
369
|
-
|
|
583
|
+
this.activeDownloadId = null;
|
|
584
|
+
this.detachProgressListener();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Cancels an active in-app download cleanly.
|
|
589
|
+
*/
|
|
590
|
+
async cancelDownload() {
|
|
591
|
+
if (!this.activeDownloadId || !isTauriRuntime()) {
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
const { invoke } = await import("@tauri-apps/api/core");
|
|
595
|
+
return await invoke("plugin:easy-updater|cancel_download", {
|
|
596
|
+
downloadId: this.activeDownloadId
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Launches the previously downloaded & verified installer (anti-TOCTOU re-verified in Rust).
|
|
601
|
+
*/
|
|
602
|
+
async install(downloadId) {
|
|
603
|
+
const id = downloadId ?? this.state.downloadResult?.downloadId;
|
|
604
|
+
if (!id) {
|
|
605
|
+
throw new UpdaterError("DOWNLOAD_NOT_FOUND", "No verified download is ready to install");
|
|
606
|
+
}
|
|
607
|
+
if (!isTauriRuntime()) {
|
|
608
|
+
throw new UpdaterError("INSTALL_FAILED", "Native installation requires Tauri v2 runtime");
|
|
609
|
+
}
|
|
610
|
+
this.setState({ status: "installing", error: null });
|
|
611
|
+
try {
|
|
612
|
+
const { invoke } = await import("@tauri-apps/api/core");
|
|
613
|
+
await invoke("plugin:easy-updater|install_update", { downloadId: id });
|
|
614
|
+
if (!this.disposed) {
|
|
615
|
+
this.setState({ status: "ready" });
|
|
616
|
+
}
|
|
617
|
+
} catch (rawErr) {
|
|
618
|
+
const err = UpdaterError.fromUnknown(rawErr);
|
|
619
|
+
if (!this.disposed) {
|
|
620
|
+
this.setState({ status: "error", error: err });
|
|
370
621
|
}
|
|
622
|
+
throw err;
|
|
371
623
|
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Opens the verified HTTPS update URL in the user's default browser (lightweight mode).
|
|
627
|
+
*/
|
|
628
|
+
async openDownloadUrl(urlOverride) {
|
|
629
|
+
const url = urlOverride ?? this.state.updateInfo?.downloadUrl;
|
|
630
|
+
if (!url) {
|
|
631
|
+
throw new UpdaterError("INVALID_URL", "No download URL available");
|
|
632
|
+
}
|
|
633
|
+
assertSafeRemoteUrl(url, Boolean(this.config.allowInsecureHttp));
|
|
634
|
+
if (isTauriRuntime()) {
|
|
635
|
+
const { invoke } = await import("@tauri-apps/api/core");
|
|
636
|
+
await invoke("plugin:easy-updater|open_url", { url });
|
|
375
637
|
return;
|
|
376
638
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
639
|
+
if (typeof window !== "undefined" && isSafeRemoteUrl(url, Boolean(this.config.allowInsecureHttp))) {
|
|
640
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Applies the available update according to the configured `mode` (`hybrid`, `download`, or `browser`).
|
|
645
|
+
*/
|
|
646
|
+
async applyUpdate(modeOverride) {
|
|
647
|
+
const mode = modeOverride ?? this.config.mode ?? "hybrid";
|
|
648
|
+
const info = this.state.updateInfo;
|
|
649
|
+
if (!info?.downloadUrl) {
|
|
650
|
+
throw new UpdaterError("INVALID_INPUT", "No update available to apply");
|
|
651
|
+
}
|
|
652
|
+
if (mode === "browser") {
|
|
653
|
+
await this.openDownloadUrl(info.downloadUrl);
|
|
381
654
|
return;
|
|
382
655
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
413
|
-
function resolveTheme(theme = "auto") {
|
|
414
|
-
if (theme === "auto" && typeof window !== "undefined" && "matchMedia" in window) {
|
|
656
|
+
if (mode === "download") {
|
|
657
|
+
const result = this.state.downloadResult ?? await this.download(info);
|
|
658
|
+
await this.install(result.downloadId);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (isTauriRuntime() && info.sha256) {
|
|
662
|
+
const result = this.state.downloadResult ?? await this.download(info);
|
|
663
|
+
await this.install(result.downloadId);
|
|
664
|
+
} else {
|
|
665
|
+
await this.openDownloadUrl(info.downloadUrl);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Dismisses the currently available update for this session.
|
|
670
|
+
* Ignored if the update is `mandatory`.
|
|
671
|
+
*/
|
|
672
|
+
dismiss() {
|
|
673
|
+
const info = this.state.updateInfo;
|
|
674
|
+
if (info?.mandatory) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
if (info) {
|
|
678
|
+
this.writeDismissedVersion(info.latestVersion);
|
|
679
|
+
}
|
|
680
|
+
this.setState({ isDismissed: true });
|
|
681
|
+
}
|
|
682
|
+
async attachProgressListener(downloadId) {
|
|
683
|
+
this.detachProgressListener();
|
|
684
|
+
if (!isTauriRuntime()) return;
|
|
415
685
|
try {
|
|
416
|
-
|
|
417
|
-
|
|
686
|
+
const { listen } = await import("@tauri-apps/api/event");
|
|
687
|
+
const unlisten = await listen(PROGRESS_EVENT_NAME, (event) => {
|
|
688
|
+
if (this.disposed) return;
|
|
689
|
+
const payload = event.payload;
|
|
690
|
+
if (!payload || payload.downloadId !== downloadId) return;
|
|
691
|
+
const nextStatus = payload.stage === "verifying" ? "verifying" : payload.stage === "completed" ? "ready" : "downloading";
|
|
692
|
+
this.setState({
|
|
693
|
+
status: nextStatus,
|
|
694
|
+
progress: payload
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
this.unlistenProgress = unlisten;
|
|
698
|
+
} catch {
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
detachProgressListener() {
|
|
702
|
+
if (this.unlistenProgress) {
|
|
703
|
+
try {
|
|
704
|
+
this.unlistenProgress();
|
|
705
|
+
} catch {
|
|
418
706
|
}
|
|
707
|
+
this.unlistenProgress = null;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
readDismissedVersion() {
|
|
711
|
+
try {
|
|
712
|
+
return this.storage?.getItem(SESSION_DISMISS_KEY) ?? null;
|
|
419
713
|
} catch {
|
|
714
|
+
return null;
|
|
420
715
|
}
|
|
421
716
|
}
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
async function openUrl(url) {
|
|
425
|
-
if (typeof window === "undefined") return;
|
|
426
|
-
try {
|
|
427
|
-
const { invoke } = await import("@tauri-apps/api/tauri");
|
|
428
|
-
await invoke("plugin:easy-updater|open_url", { url });
|
|
429
|
-
} catch {
|
|
717
|
+
writeDismissedVersion(version) {
|
|
430
718
|
try {
|
|
431
|
-
|
|
719
|
+
this.storage?.setItem(SESSION_DISMISS_KEY, version);
|
|
432
720
|
} catch {
|
|
433
721
|
}
|
|
434
722
|
}
|
|
723
|
+
setState(partial) {
|
|
724
|
+
this.state = {
|
|
725
|
+
...this.state,
|
|
726
|
+
...partial
|
|
727
|
+
};
|
|
728
|
+
for (const listener of this.listeners) {
|
|
729
|
+
listener(this.state);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
function createUpdaterClient(config = {}) {
|
|
734
|
+
return new UpdaterClient(config);
|
|
435
735
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
style: {
|
|
497
|
-
...buttonStyle,
|
|
498
|
-
borderRadius: "9999px",
|
|
499
|
-
padding: "0.4rem 0.9rem",
|
|
500
|
-
border: "none",
|
|
501
|
-
cursor: "pointer",
|
|
502
|
-
fontSize: "0.875rem",
|
|
503
|
-
fontWeight: 500
|
|
504
|
-
},
|
|
505
|
-
onClick: () => {
|
|
506
|
-
void openUrl(updateInfo.downloadUrl);
|
|
507
|
-
},
|
|
508
|
-
children: "Actualizar ahora"
|
|
736
|
+
|
|
737
|
+
// src/providers/github.ts
|
|
738
|
+
function createGitHubProvider(config) {
|
|
739
|
+
const {
|
|
740
|
+
owner,
|
|
741
|
+
repo,
|
|
742
|
+
manifestAssetName = "update-manifest.json",
|
|
743
|
+
fallbackToReleaseApi = true,
|
|
744
|
+
channel = "stable",
|
|
745
|
+
preferredFormat,
|
|
746
|
+
timeoutMs = 15e3
|
|
747
|
+
} = config;
|
|
748
|
+
assertValidGitHubIdent(owner, "owner");
|
|
749
|
+
assertValidGitHubIdent(repo, "repo");
|
|
750
|
+
if (!manifestAssetName || manifestAssetName.includes("/") || manifestAssetName.includes("\\") || manifestAssetName.includes("..")) {
|
|
751
|
+
throw new UpdaterError("INVALID_INPUT", `Unsafe manifestAssetName: "${manifestAssetName}"`);
|
|
752
|
+
}
|
|
753
|
+
const manifestUrl = `https://github.com/${owner}/${repo}/releases/latest/download/${manifestAssetName}`;
|
|
754
|
+
const isPrereleaseChannel = channel !== "stable";
|
|
755
|
+
const fingerprint = JSON.stringify([
|
|
756
|
+
"github",
|
|
757
|
+
owner,
|
|
758
|
+
repo,
|
|
759
|
+
manifestAssetName,
|
|
760
|
+
fallbackToReleaseApi,
|
|
761
|
+
channel,
|
|
762
|
+
preferredFormat ?? null
|
|
763
|
+
]);
|
|
764
|
+
return {
|
|
765
|
+
type: "github",
|
|
766
|
+
fingerprint,
|
|
767
|
+
tauriParams: {
|
|
768
|
+
githubOwner: owner,
|
|
769
|
+
githubRepo: repo,
|
|
770
|
+
manifestAssetName,
|
|
771
|
+
fallbackToReleaseApi,
|
|
772
|
+
channel,
|
|
773
|
+
preferredFormat
|
|
774
|
+
},
|
|
775
|
+
async fetchManifest() {
|
|
776
|
+
if (!isPrereleaseChannel) {
|
|
777
|
+
try {
|
|
778
|
+
const res2 = await fetchWithTimeout(manifestUrl, { method: "GET" }, timeoutMs);
|
|
779
|
+
if (res2.ok) {
|
|
780
|
+
const json = await res2.json();
|
|
781
|
+
return validateManifest(json);
|
|
782
|
+
}
|
|
783
|
+
if (!fallbackToReleaseApi || res2.status !== 404) {
|
|
784
|
+
throw new UpdaterError(
|
|
785
|
+
"NETWORK_ERROR",
|
|
786
|
+
`GitHub manifest request failed with HTTP ${res2.status}`
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
} catch (err) {
|
|
790
|
+
if (err instanceof UpdaterError && err.code === "INVALID_MANIFEST") {
|
|
791
|
+
throw err;
|
|
792
|
+
}
|
|
793
|
+
if (!fallbackToReleaseApi) {
|
|
794
|
+
throw UpdaterError.fromUnknown(err);
|
|
795
|
+
}
|
|
509
796
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
797
|
+
}
|
|
798
|
+
const apiUrl = isPrereleaseChannel ? `https://api.github.com/repos/${owner}/${repo}/releases?per_page=20` : `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
|
|
799
|
+
const res = await fetchWithTimeout(
|
|
800
|
+
apiUrl,
|
|
513
801
|
{
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
802
|
+
headers: {
|
|
803
|
+
Accept: "application/vnd.github+json",
|
|
804
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
timeoutMs
|
|
808
|
+
);
|
|
809
|
+
if (!res.ok) {
|
|
810
|
+
throw new UpdaterError(
|
|
811
|
+
"NETWORK_ERROR",
|
|
812
|
+
`GitHub Releases API failed with HTTP ${res.status}`
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
const raw = await res.json();
|
|
816
|
+
const release = isPrereleaseChannel ? selectReleaseForChannel(Array.isArray(raw) ? raw : [], channel) : raw;
|
|
817
|
+
if (!release) {
|
|
818
|
+
throw new UpdaterError(
|
|
819
|
+
"INVALID_MANIFEST",
|
|
820
|
+
`No matching GitHub release found for channel "${channel}"`
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
const assets = release.assets ?? [];
|
|
824
|
+
const manifestAsset = assets.find((a) => a.name === manifestAssetName);
|
|
825
|
+
if (manifestAsset) {
|
|
826
|
+
const assetRes = await fetchWithTimeout(
|
|
827
|
+
manifestAsset.browser_download_url,
|
|
828
|
+
{ method: "GET" },
|
|
829
|
+
timeoutMs
|
|
830
|
+
);
|
|
831
|
+
if (assetRes.ok) {
|
|
832
|
+
return validateManifest(await assetRes.json());
|
|
526
833
|
}
|
|
527
|
-
)
|
|
528
|
-
] })
|
|
529
|
-
] });
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// src/components/UpdateModal.tsx
|
|
533
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
534
|
-
function resolveTheme2(theme = "auto") {
|
|
535
|
-
if (theme === "auto" && typeof window !== "undefined" && "matchMedia" in window) {
|
|
536
|
-
try {
|
|
537
|
-
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
538
|
-
return "dark";
|
|
539
834
|
}
|
|
540
|
-
|
|
835
|
+
if (!fallbackToReleaseApi) {
|
|
836
|
+
throw new UpdaterError(
|
|
837
|
+
"INVALID_MANIFEST",
|
|
838
|
+
`Manifest asset "${manifestAssetName}" not found in release "${release.tag_name}"`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
const platform = await getCurrentPlatform();
|
|
842
|
+
const asset = platform ? selectAssetForPlatform(assets, platform, preferredFormat) : void 0;
|
|
843
|
+
const manifest = {
|
|
844
|
+
schema_version: 1,
|
|
845
|
+
version: release.tag_name,
|
|
846
|
+
channel,
|
|
847
|
+
pub_date: release.published_at ?? "",
|
|
848
|
+
notes: release.body ?? "",
|
|
849
|
+
platforms: asset && platform ? {
|
|
850
|
+
[platform]: {
|
|
851
|
+
url: asset.browser_download_url,
|
|
852
|
+
size: asset.size,
|
|
853
|
+
format: inferInstallerFormat(asset.name) ?? void 0
|
|
854
|
+
}
|
|
855
|
+
} : {}
|
|
856
|
+
};
|
|
857
|
+
return validateManifest(manifest);
|
|
541
858
|
}
|
|
542
|
-
}
|
|
543
|
-
return theme === "auto" ? "light" : theme;
|
|
859
|
+
};
|
|
544
860
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
861
|
+
function selectReleaseForChannel(releases, channel) {
|
|
862
|
+
const published = releases.filter((r) => !r.draft);
|
|
863
|
+
const needle = channel.toLowerCase();
|
|
864
|
+
return published.find((r) => {
|
|
865
|
+
const tag = r.tag_name.toLowerCase();
|
|
866
|
+
return tag.includes(`-${needle}`) || tag.includes(`.${needle}`);
|
|
867
|
+
}) ?? published.find((r) => Boolean(r.prerelease)) ?? published[0];
|
|
868
|
+
}
|
|
869
|
+
function selectAssetForPlatform(assets, platform, preferredFormat) {
|
|
870
|
+
const [os, arch] = platform.toLowerCase().split("-");
|
|
871
|
+
if (!os || !arch) return void 0;
|
|
872
|
+
const scored = [];
|
|
873
|
+
for (const asset of assets) {
|
|
874
|
+
const name = asset.name.toLowerCase();
|
|
875
|
+
const fmt = inferInstallerFormat(name);
|
|
876
|
+
if (!fmt) continue;
|
|
877
|
+
const osOk = os === "windows" && (fmt === "nsis" || fmt === "msi") || os === "darwin" && (fmt === "dmg" || fmt === "pkg") || os === "linux" && (fmt === "appimage" || fmt === "deb" || fmt === "rpm");
|
|
878
|
+
if (!osOk) continue;
|
|
879
|
+
const isArm = name.includes("arm64") || name.includes("aarch64");
|
|
880
|
+
const isX64 = name.includes("x86_64") || name.includes("x64") || name.includes("amd64");
|
|
881
|
+
const isUniversal = name.includes("universal");
|
|
882
|
+
let score = 0;
|
|
883
|
+
if (arch === "aarch64") {
|
|
884
|
+
if (isArm) score = 3;
|
|
885
|
+
else if (isUniversal && os === "darwin") score = 2;
|
|
886
|
+
else continue;
|
|
887
|
+
} else if (arch === "x86_64") {
|
|
888
|
+
if (isX64) score = 3;
|
|
889
|
+
else if (isUniversal && os === "darwin") score = 2;
|
|
890
|
+
else if (!isArm) score = 1;
|
|
891
|
+
else continue;
|
|
892
|
+
} else {
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
if (preferredFormat && fmt === preferredFormat) {
|
|
896
|
+
score += 10;
|
|
554
897
|
}
|
|
898
|
+
scored.push({ asset, score });
|
|
555
899
|
}
|
|
900
|
+
scored.sort((a, b) => b.score - a.score);
|
|
901
|
+
return scored[0]?.asset;
|
|
556
902
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
const secondaryButtonStyle = resolvedTheme === "dark" ? {
|
|
594
|
-
borderColor: "#4b5563",
|
|
595
|
-
color: "#e5e7eb"
|
|
596
|
-
} : {
|
|
597
|
-
borderColor: "#cbd5f5",
|
|
598
|
-
color: "#1f2937"
|
|
599
|
-
};
|
|
600
|
-
const textMuted = {
|
|
601
|
-
opacity: 0.8,
|
|
602
|
-
fontSize: "0.875rem"
|
|
603
|
-
};
|
|
604
|
-
const title = appName ? `${appName} tiene una nueva versi\xF3n` : "Nueva actualizaci\xF3n disponible";
|
|
605
|
-
return /* @__PURE__ */ jsx2("div", { style: overlayStyle, children: /* @__PURE__ */ jsxs2("div", { style: modalStyle, className, children: [
|
|
606
|
-
/* @__PURE__ */ jsxs2(
|
|
607
|
-
"div",
|
|
608
|
-
{
|
|
609
|
-
style: {
|
|
610
|
-
display: "flex",
|
|
611
|
-
justifyContent: "space-between",
|
|
612
|
-
alignItems: "flex-start",
|
|
613
|
-
marginBottom: "0.75rem"
|
|
614
|
-
},
|
|
615
|
-
children: [
|
|
616
|
-
/* @__PURE__ */ jsxs2("div", { children: [
|
|
617
|
-
/* @__PURE__ */ jsx2(
|
|
618
|
-
"h2",
|
|
619
|
-
{
|
|
620
|
-
style: {
|
|
621
|
-
fontSize: "1.125rem",
|
|
622
|
-
fontWeight: 600,
|
|
623
|
-
margin: 0,
|
|
624
|
-
marginBottom: "0.25rem"
|
|
625
|
-
},
|
|
626
|
-
children: title
|
|
627
|
-
}
|
|
628
|
-
),
|
|
629
|
-
/* @__PURE__ */ jsxs2("p", { style: textMuted, children: [
|
|
630
|
-
"Versi\xF3n actual ",
|
|
631
|
-
updateInfo.currentVersion,
|
|
632
|
-
" \xB7 Nueva versi\xF3n ",
|
|
633
|
-
updateInfo.latestVersion
|
|
634
|
-
] })
|
|
635
|
-
] }),
|
|
636
|
-
/* @__PURE__ */ jsx2(
|
|
637
|
-
"button",
|
|
638
|
-
{
|
|
639
|
-
type: "button",
|
|
640
|
-
"aria-label": "Cerrar",
|
|
641
|
-
onClick: onDismiss,
|
|
642
|
-
style: {
|
|
643
|
-
background: "transparent",
|
|
644
|
-
border: "none",
|
|
645
|
-
cursor: "pointer",
|
|
646
|
-
fontSize: "1rem",
|
|
647
|
-
lineHeight: 1,
|
|
648
|
-
marginLeft: "0.5rem"
|
|
649
|
-
},
|
|
650
|
-
children: "\xD7"
|
|
651
|
-
}
|
|
652
|
-
)
|
|
653
|
-
]
|
|
654
|
-
}
|
|
655
|
-
),
|
|
656
|
-
/* @__PURE__ */ jsx2(
|
|
657
|
-
"div",
|
|
658
|
-
{
|
|
659
|
-
style: {
|
|
660
|
-
marginTop: "0.75rem",
|
|
661
|
-
marginBottom: "1rem",
|
|
662
|
-
maxHeight: "12rem",
|
|
663
|
-
overflowY: "auto",
|
|
664
|
-
padding: "0.5rem",
|
|
665
|
-
borderRadius: "0.5rem",
|
|
666
|
-
backgroundColor: resolvedTheme === "dark" ? "#020617" : "#f1f5f9",
|
|
667
|
-
fontSize: "0.875rem",
|
|
668
|
-
whiteSpace: "pre-wrap"
|
|
669
|
-
},
|
|
670
|
-
children: updateInfo.releaseNotes || "Esta actualizaci\xF3n incluye mejoras y correcciones de errores."
|
|
671
|
-
}
|
|
672
|
-
),
|
|
673
|
-
/* @__PURE__ */ jsxs2(
|
|
674
|
-
"div",
|
|
675
|
-
{
|
|
676
|
-
style: {
|
|
677
|
-
display: "flex",
|
|
678
|
-
justifyContent: "flex-end",
|
|
679
|
-
gap: "0.5rem",
|
|
680
|
-
marginTop: "0.5rem"
|
|
903
|
+
|
|
904
|
+
// src/providers/http.ts
|
|
905
|
+
function createHttpProvider(config) {
|
|
906
|
+
const {
|
|
907
|
+
manifestUrl,
|
|
908
|
+
headers,
|
|
909
|
+
channel,
|
|
910
|
+
preferredFormat,
|
|
911
|
+
allowInsecureHttp = false,
|
|
912
|
+
timeoutMs = 15e3
|
|
913
|
+
} = config;
|
|
914
|
+
assertSafeRemoteUrl(manifestUrl, allowInsecureHttp);
|
|
915
|
+
const sortedHeaders = headers ? Object.keys(headers).sort().map((k) => [k, headers[k]]) : [];
|
|
916
|
+
const fingerprint = JSON.stringify([
|
|
917
|
+
"http",
|
|
918
|
+
manifestUrl,
|
|
919
|
+
sortedHeaders,
|
|
920
|
+
channel ?? null,
|
|
921
|
+
preferredFormat ?? null,
|
|
922
|
+
allowInsecureHttp
|
|
923
|
+
]);
|
|
924
|
+
return {
|
|
925
|
+
type: "http",
|
|
926
|
+
fingerprint,
|
|
927
|
+
tauriParams: {
|
|
928
|
+
manifestUrl,
|
|
929
|
+
headers,
|
|
930
|
+
channel,
|
|
931
|
+
preferredFormat
|
|
932
|
+
},
|
|
933
|
+
async fetchManifest() {
|
|
934
|
+
const res = await fetchWithTimeout(
|
|
935
|
+
manifestUrl,
|
|
936
|
+
{
|
|
937
|
+
method: "GET",
|
|
938
|
+
headers
|
|
681
939
|
},
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
type: "button",
|
|
687
|
-
onClick: onDismiss,
|
|
688
|
-
style: {
|
|
689
|
-
...secondaryButtonStyle,
|
|
690
|
-
background: "transparent",
|
|
691
|
-
padding: "0.45rem 0.9rem",
|
|
692
|
-
borderRadius: "9999px",
|
|
693
|
-
borderWidth: 1,
|
|
694
|
-
borderStyle: "solid",
|
|
695
|
-
cursor: "pointer",
|
|
696
|
-
fontSize: "0.875rem"
|
|
697
|
-
},
|
|
698
|
-
children: "Recordarme despu\xE9s"
|
|
699
|
-
}
|
|
700
|
-
),
|
|
701
|
-
/* @__PURE__ */ jsx2(
|
|
702
|
-
"button",
|
|
703
|
-
{
|
|
704
|
-
type: "button",
|
|
705
|
-
onClick: () => {
|
|
706
|
-
void openUrl2(updateInfo.downloadUrl);
|
|
707
|
-
},
|
|
708
|
-
style: {
|
|
709
|
-
...primaryButtonStyle,
|
|
710
|
-
padding: "0.45rem 0.9rem",
|
|
711
|
-
borderRadius: "9999px",
|
|
712
|
-
border: "none",
|
|
713
|
-
cursor: "pointer",
|
|
714
|
-
fontSize: "0.875rem",
|
|
715
|
-
fontWeight: 500
|
|
716
|
-
},
|
|
717
|
-
children: "Descargar ahora"
|
|
718
|
-
}
|
|
719
|
-
)
|
|
720
|
-
]
|
|
940
|
+
timeoutMs
|
|
941
|
+
);
|
|
942
|
+
if (!res.ok) {
|
|
943
|
+
throw new UpdaterError("NETWORK_ERROR", `Manifest endpoint returned HTTP ${res.status}`);
|
|
721
944
|
}
|
|
722
|
-
|
|
723
|
-
|
|
945
|
+
const json = await res.json();
|
|
946
|
+
return validateManifest(json, allowInsecureHttp);
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// src/providers/s3.ts
|
|
952
|
+
function createS3Provider(config) {
|
|
953
|
+
const {
|
|
954
|
+
bucketUrl,
|
|
955
|
+
manifestPath,
|
|
956
|
+
channel = "stable",
|
|
957
|
+
preferredFormat,
|
|
958
|
+
headers,
|
|
959
|
+
allowInsecureHttp = false,
|
|
960
|
+
timeoutMs = 15e3
|
|
961
|
+
} = config;
|
|
962
|
+
assertSafeRemoteUrl(bucketUrl, allowInsecureHttp);
|
|
963
|
+
const resolvedPath = manifestPath?.replace(/^\/+/, "") || (channel === "stable" ? "latest/update-manifest.json" : `${channel}/update-manifest.json`);
|
|
964
|
+
const manifestUrl = `${bucketUrl.replace(/\/+$/, "")}/${resolvedPath}`;
|
|
965
|
+
const httpProvider = createHttpProvider({
|
|
966
|
+
manifestUrl,
|
|
967
|
+
headers,
|
|
968
|
+
channel,
|
|
969
|
+
preferredFormat,
|
|
970
|
+
allowInsecureHttp,
|
|
971
|
+
timeoutMs
|
|
972
|
+
});
|
|
973
|
+
const fingerprint = JSON.stringify([
|
|
974
|
+
"s3",
|
|
975
|
+
bucketUrl.replace(/\/+$/, ""),
|
|
976
|
+
resolvedPath,
|
|
977
|
+
channel,
|
|
978
|
+
preferredFormat ?? null,
|
|
979
|
+
allowInsecureHttp
|
|
980
|
+
]);
|
|
981
|
+
return {
|
|
982
|
+
type: "s3",
|
|
983
|
+
fingerprint,
|
|
984
|
+
tauriParams: {
|
|
985
|
+
s3BucketUrl: bucketUrl,
|
|
986
|
+
s3ManifestPath: resolvedPath,
|
|
987
|
+
headers,
|
|
988
|
+
channel,
|
|
989
|
+
preferredFormat
|
|
990
|
+
},
|
|
991
|
+
fetchManifest() {
|
|
992
|
+
return httpProvider.fetchManifest();
|
|
993
|
+
}
|
|
994
|
+
};
|
|
724
995
|
}
|
|
725
996
|
export {
|
|
726
|
-
|
|
727
|
-
|
|
997
|
+
UpdaterClient,
|
|
998
|
+
UpdaterError,
|
|
999
|
+
assertSafeRemoteUrl,
|
|
1000
|
+
assertValidGitHubIdent,
|
|
1001
|
+
compareSemver,
|
|
728
1002
|
createGitHubProvider,
|
|
729
1003
|
createHttpProvider,
|
|
730
1004
|
createS3Provider,
|
|
1005
|
+
createUpdaterClient,
|
|
1006
|
+
fetchWithTimeout,
|
|
731
1007
|
getCurrentPlatform,
|
|
1008
|
+
getPlatformSummary,
|
|
1009
|
+
inferInstallerFormat,
|
|
1010
|
+
isBelowMinVersion,
|
|
732
1011
|
isNewerVersion,
|
|
733
|
-
|
|
1012
|
+
isSafeRemoteUrl,
|
|
1013
|
+
isTauriRuntime,
|
|
1014
|
+
normalizeArch,
|
|
1015
|
+
normalizeOs,
|
|
1016
|
+
parseSemver,
|
|
1017
|
+
resolveArtifactsFromPlatform,
|
|
1018
|
+
selectPlatformFromManifest,
|
|
1019
|
+
validateManifest
|
|
734
1020
|
};
|
|
735
1021
|
//# sourceMappingURL=index.mjs.map
|