Skip to content

Commit

Permalink
fix: updater
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Dec 29, 2023
1 parent 67e26bc commit ca1ed25
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json", "rustls-tls"] }
tauri = { version = "1.5.3", features = [
"updater",
"os-all",
"global-shortcut-all",
"notification-all",
"process-all",
"shell-all",
"system-tray",
"updater",
"window-all",
] }
window-vibrancy = { version = "0.4.3" }
Expand Down
17 changes: 9 additions & 8 deletions backend/tauri/src/core/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Updater {
.await??;
// 3. if core is used, close it
if current_core == *core_type {
CoreManager::global().stop_core()?;
tokio::task::spawn_blocking(move || CoreManager::global().stop_core()).await??;
}
// 4. replace core
#[cfg(target_os = "windows")]
Expand All @@ -174,7 +174,12 @@ impl Updater {
"failed to copy core: {}, trying to use elevated permission to copy and override core",
err
);

let mut target_core_str = target_core.to_str().unwrap().to_string();
if target_core_str.starts_with("\\\\?\\") {
target_core_str = target_core_str[4..].to_string();
}
debug!("tmp core path: {:?}", tmp_core_path);
debug!("target core path: {:?}", target_core_str);
// 防止 UAC 弹窗堵塞主线程
let status_code = tokio::task::spawn_blocking(move || {
#[cfg(target_os = "windows")]
Expand All @@ -185,18 +190,14 @@ impl Updater {
"copy",
"/Y",
tmp_core_path.to_str().unwrap(),
target_core.to_str().unwrap(),
&target_core_str,
])
.status()
}
#[cfg(not(target_os = "windows"))]
{
RunasCommand::new("cp")
.args(&[
"-f",
tmp_core_path.to_str().unwrap(),
target_core.to_str().unwrap(),
])
.args(&["-f", tmp_core_path.to_str().unwrap(), &target_core_str])
.status()?;
}
})
Expand Down
3 changes: 1 addition & 2 deletions scripts/generate-latest-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ const resolveMihomoAlpha: LatestVersionResolver = async () => {

const archMapping: ArchMapping = {
// [SupportedArch.WindowsX86]: "mihomo-windows-386-{}.zip",
[SupportedArch.WindowsX86_64]:
"mihomo-windows-amd64-compatible-alpha-{}.zip",
[SupportedArch.WindowsX86_64]: "mihomo-windows-amd64-compatible-{}.zip",
// [SupportedArch.WindowsAarch64]: "mihomo-windows-arm64-{}.zip",
[SupportedArch.LinuxAarch64]: "mihomo-linux-arm64-{}.gz",
[SupportedArch.LinuxAmd64]: "mihomo-linux-amd64-compatible-{}.gz",
Expand Down
13 changes: 10 additions & 3 deletions src/components/setting/mods/clash-core-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
...each,
latest:
each.core === "clash"
? results["clash_premium"]
? `n${results["clash_premium"]}`
: results[each.core.replace(/-/g, "_") as keyof typeof results],
}));
setValidCores(buf);
Expand Down Expand Up @@ -101,7 +101,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
}
});

useAsyncEffect(async () => {
const getCoreVersions = async () => {
try {
const versions = await Promise.all(
VALID_CORE.reduce(
Expand All @@ -126,7 +126,8 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
console.error(e);
}
}
}, []);
};
useAsyncEffect(getCoreVersions, []);

return (
<BaseDialog
Expand Down Expand Up @@ -180,6 +181,9 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
if (state === "start") setLock(true);
else setLock(false);
}}
onCoreUpdated={() => {
getCoreVersions();
}}
/>
))}
</List>
Expand All @@ -194,11 +198,13 @@ function CoreElement({
core,
lock,
onCoreChanged,
onCoreUpdated,
}: {
selected: boolean;
core: Core;
lock: boolean;
onCoreChanged: (core: string, state: "start" | "finish") => void;
onCoreUpdated?: (core: string) => void;
}) {
const { t } = useTranslation();
const { mutateVerge } = useVerge();
Expand Down Expand Up @@ -250,6 +256,7 @@ function CoreElement({
mutate("getVersion");
}, 100);
useNotification(t("Success"), `Successfully updated to ${core}`);
onCoreUpdated?.(core);
} catch (err: any) {
useNotification(t("Error"), err?.message || err.toString());
} finally {
Expand Down

0 comments on commit ca1ed25

Please sign in to comment.