feat: optimize config feedback

This commit is contained in:
GyDi
2022-09-26 20:46:29 +08:00
committed by GitHub
parent 29fe9d973c
commit a75706f329
7 changed files with 45 additions and 11 deletions

View File

@@ -40,6 +40,12 @@ impl Handle {
}
}
pub fn notice_message(&self, status: String, msg: String) {
if let Some(window) = self.get_window() {
log_if_err!(window.emit("verge://notice-message", (status, msg)));
}
}
// update system tray state (clash config)
pub fn update_systray_clash(&self) -> Result<()> {
if self.app_handle.is_none() {

View File

@@ -284,9 +284,14 @@ impl Core {
match Service::set_config(clash_info, config).await {
Ok(_) => {
let handle = handle.lock();
handle.refresh_clash()
handle.refresh_clash();
handle.notice_message("set_config::ok".into(), "ok".into());
}
Err(err) => {
let handle = handle.lock();
handle.notice_message("set_config::error".into(), format!("{err}"));
log::error!(target: "app", "last {err}")
}
Err(err) => log::error!(target: "app", "{err}"),
}
});

View File

@@ -212,8 +212,17 @@ impl Service {
let mut data = HashMap::new();
data.insert("path", temp_path.as_os_str().to_str().unwrap());
macro_rules! report_err {
($i: expr, $e: expr) => {
match $i {
4 => bail!($e),
_ => log::error!(target: "app", $e),
}
};
}
// retry 5 times
for _ in 0..5 {
for i in 0..5 {
let headers = headers.clone();
match reqwest::ClientBuilder::new().no_proxy().build() {
Ok(client) => {
@@ -223,14 +232,12 @@ impl Service {
204 => break,
// 配置有问题不重试
400 => bail!("failed to update clash config with status 400"),
status @ _ => {
log::error!(target: "app", "failed to activate clash with status \"{status}\"");
}
status @ _ => report_err!(i, "failed to activate clash with status \"{status}\""),
},
Err(err) => log::error!(target: "app", "{err}"),
Err(err) => report_err!(i, "{err}"),
}
}
Err(err) => log::error!(target: "app", "{err}"),
Err(err) => report_err!(i, "{err}"),
}
sleep(Duration::from_millis(500)).await;
}