refactor: wip

This commit is contained in:
GyDi
2022-04-20 01:44:47 +08:00
parent 4371772ec7
commit 5edfd7b6f7
13 changed files with 419 additions and 939 deletions

View File

@@ -1,4 +1,7 @@
use anyhow::{bail, Result};
use nanoid::nanoid;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
@@ -41,6 +44,38 @@ pub fn parse_str<T: FromStr>(target: &str, key: &str) -> Option<T> {
}
}
/// open file
/// use vscode by default
pub fn open_file(path: PathBuf) -> Result<()> {
// use vscode first
if let Ok(code) = which::which("code") {
#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
if let Err(err) = Command::new(code)
.creation_flags(0x08000000)
.arg(path)
.spawn()
{
bail!(format!("failed to open file by VScode for `{err}`"));
}
}
#[cfg(not(target_os = "windows"))]
if let Err(err) = Command::new(code).arg(path).spawn() {
bail!(format!("failed to open file by VScode for `{err}`"));
}
return Ok(());
}
match open::that(path) {
Ok(_) => Ok(()),
Err(err) => bail!(format!("failed to open file for `{err}`")),
}
}
#[macro_export]
macro_rules! log_if_err {
($result: expr) => {

View File

@@ -21,9 +21,9 @@ pub fn resolve_setup(app: &App) {
/// reset system proxy
pub fn resolve_reset(app_handle: &AppHandle) {
let core = app_handle.state::<Core>();
let mut verge = core.verge.lock();
let mut sysopt = core.sysopt.lock();
verge.reset_sysproxy();
sysopt.reset_sysproxy();
}
/// customize the window theme