-
Notifications
You must be signed in to change notification settings - Fork 61k
Feature/h0lly w00dz z updater #5632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
2eebfcf
bd9de4d
a0d4a04
819238a
2419083
426269d
87d85c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,3 +386,37 @@ export function getOperationId(operation: { | |
`${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}` | ||
); | ||
} | ||
|
||
export function clientUpdate() { | ||
// this a wild for updating client app | ||
return window.__TAURI__?.updater | ||
.checkUpdate() | ||
.then((updateResult) => { | ||
if (updateResult.shouldUpdate) { | ||
window.__TAURI__?.updater | ||
.installUpdate() | ||
.then((result) => { | ||
showToast(Locale.Settings.Update.Success); | ||
}) | ||
.catch((e) => { | ||
console.error("[Install Update Error]", e); | ||
showToast(Locale.Settings.Update.Failed); | ||
}); | ||
} | ||
}) | ||
.catch((e) => { | ||
console.error("[Check Update Error]", e); | ||
showToast(Locale.Settings.Update.Failed); | ||
}); | ||
} | ||
Comment on lines
+390
to
+411
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling, user experience, and return value in the While the function implements the basic update flow, there are several areas for improvement:
Consider refactoring the function as follows: export async function clientUpdate(): Promise<boolean> {
if (!window.__TAURI__?.updater) {
console.error("Tauri updater not available");
return false;
}
try {
const updateResult = await window.__TAURI__.updater.checkUpdate();
if (updateResult.shouldUpdate) {
const userConfirmed = await showConfirmDialog(Locale.Settings.Update.Confirm);
if (userConfirmed) {
await window.__TAURI__.updater.installUpdate();
showToast(Locale.Settings.Update.Success);
return true;
}
} else {
showToast(Locale.Settings.Update.NoUpdate);
}
} catch (e) {
console.error("[Update Error]", e);
showToast(Locale.Settings.Update.Failed);
}
return false;
} This refactored version addresses the issues mentioned above and improves overall robustness and user experience. Note: You'll need to implement the |
||
|
||
// https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb | ||
export function semverCompare(a: string, b: string) { | ||
if (a.startsWith(b + "-")) return -1; | ||
if (b.startsWith(a + "-")) return 1; | ||
return a.localeCompare(b, undefined, { | ||
numeric: true, | ||
sensitivity: "case", | ||
caseFirst: "upper", | ||
}); | ||
} | ||
lloydzhou marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.