Skip to content

Commit

Permalink
feat(updater): finish core updater backend
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Dec 12, 2023
1 parent 60fae64 commit 6215531
Show file tree
Hide file tree
Showing 13 changed files with 605 additions and 36 deletions.
162 changes: 162 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions backend/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@ parking_lot = "0.12.0"
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 = ["global-shortcut-all", "notification-all", "process-all", "shell-all", "system-tray", "updater", "window-all"] }
tauri = { version = "1.5.3", features = [
"global-shortcut-all",
"notification-all",
"process-all",
"shell-all",
"system-tray",
"updater",
"window-all",
] }
window-vibrancy = { version = "0.3.0" }
window-shadows = { version = "0.2.2" }
wry = { version = "0.24.6" }

semver = "1.0"
zip = "0.6.6"
gunzip = { version = "0.1.0", git = "https://github.com/TechHara/gunzip.git" }
tempfile = "3.8.1"

[target.'cfg(windows)'.dependencies]
runas = "=1.0.0"
Expand Down
26 changes: 24 additions & 2 deletions backend/tauri/src/cmds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
config::*,
core::*,
core::{
updater::{ManifestVersion, ManifestVersionLatest},
*,
},
feat,
utils::{dirs, help, resolve::save_window_state},
};
Expand Down Expand Up @@ -170,7 +173,7 @@ pub async fn patch_verge_config(payload: IVerge) -> CmdResult {
}

#[tauri::command]
pub async fn change_clash_core(clash_core: Option<String>) -> CmdResult {
pub async fn change_clash_core(clash_core: Option<ClashCore>) -> CmdResult {
wrap_err!(CoreManager::global().change_core(clash_core).await)
}

Expand Down Expand Up @@ -240,6 +243,25 @@ pub fn save_window_size_state() -> CmdResult<()> {
wrap_err!(save_window_state(&handle, true))
}

#[tauri::command]
#[allow(clippy::await_holding_lock)]
pub async fn fetch_latest_core_versions() -> CmdResult<ManifestVersionLatest> {
let mut updater = updater::Updater::global().write().await; // It is intended to block here
wrap_err!(updater.fetch_latest().await);
Ok(updater.get_latest_versions())
}

#[tauri::command]
#[allow(clippy::await_holding_lock)]
pub async fn update_core(core_type: ClashCore) -> CmdResult {
wrap_err!(updater::Updater::global()
.read()
.await
.update_core(&core_type)
.await
.context("failed to update core"))
}

#[cfg(windows)]
pub mod uwp {
use super::*;
Expand Down
Loading

2 comments on commit 6215531

@iugo
Copy link

@iugo iugo commented on 6215531 Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要在已经实现 https://github.com/keiko233/clash-nyanpasu/blob/85bc278c62768ee2758a05abb36e77d30e076fdc/backend/tauri/tauri.conf.json#L58-L64 的基础上再写一遍 updater.rs? 是因为想要区分 "内核更新" 和 "UI 更新" 吗?

@greenhat616
Copy link
Collaborator Author

@greenhat616 greenhat616 commented on 6215531 Jan 9, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.