feat: support open dir
This commit is contained in:
parent
0aa2565df3
commit
3c79238a44
@ -180,17 +180,10 @@ pub fn view_profile(index: usize, profiles_state: State<'_, ProfilesState>) -> R
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// use `open` command
|
match open_command().arg(path).spawn() {
|
||||||
if let Ok(open) = which::which("open") {
|
|
||||||
return match Command::new(open).arg(path).spawn() {
|
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err("failed to open file by `open`".into()),
|
Err(_) => Err("failed to open file by `open`".into()),
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// recommand to use vscode
|
|
||||||
// todo: support other editors
|
|
||||||
return Err("please install VScode".into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// restart the sidecar
|
/// restart the sidecar
|
||||||
@ -279,3 +272,35 @@ pub async fn patch_verge_config(
|
|||||||
let mut verge = verge_state.0.lock().unwrap();
|
let mut verge = verge_state.0.lock().unwrap();
|
||||||
verge.patch_config(payload)
|
verge.patch_config(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// open app config dir
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn open_app_dir() -> Result<(), String> {
|
||||||
|
let app_dir = app_home_dir();
|
||||||
|
|
||||||
|
match open_command().arg(app_dir).spawn() {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err("failed to open logs dir".into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// open logs dir
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn open_logs_dir() -> Result<(), String> {
|
||||||
|
let log_dir = app_home_dir().join("logs");
|
||||||
|
|
||||||
|
match open_command().arg(log_dir).spawn() {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err("failed to open logs dir".into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get open/explorer command
|
||||||
|
fn open_command() -> Command {
|
||||||
|
let open = if cfg!(target_os = "windows") {
|
||||||
|
"explorer"
|
||||||
|
} else {
|
||||||
|
"open"
|
||||||
|
};
|
||||||
|
Command::new(open)
|
||||||
|
}
|
||||||
|
@ -74,6 +74,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
cmds::restart_sidecar,
|
cmds::restart_sidecar,
|
||||||
cmds::get_sys_proxy,
|
cmds::get_sys_proxy,
|
||||||
cmds::get_cur_proxy,
|
cmds::get_cur_proxy,
|
||||||
|
cmds::open_app_dir,
|
||||||
|
cmds::open_logs_dir,
|
||||||
// clash
|
// clash
|
||||||
cmds::get_clash_info,
|
cmds::get_clash_info,
|
||||||
cmds::patch_clash_config,
|
cmds::patch_clash_config,
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { ListItemText, Switch, Typography } from "@mui/material";
|
import { IconButton, ListItemText, Switch, Typography } from "@mui/material";
|
||||||
import { getVergeConfig, patchVergeConfig } from "../../services/cmds";
|
import {
|
||||||
|
getVergeConfig,
|
||||||
|
openAppDir,
|
||||||
|
openLogsDir,
|
||||||
|
patchVergeConfig,
|
||||||
|
} from "../../services/cmds";
|
||||||
import { SettingList, SettingItem } from "./setting";
|
import { SettingList, SettingItem } from "./setting";
|
||||||
import { CmdType } from "../../services/types";
|
import { CmdType } from "../../services/types";
|
||||||
import { version } from "../../../package.json";
|
import { version } from "../../../package.json";
|
||||||
import GuardState from "./guard-state";
|
import GuardState from "./guard-state";
|
||||||
import PaletteSwitch from "./palette-switch";
|
import PaletteSwitch from "./palette-switch";
|
||||||
|
import { ArrowForward } from "@mui/icons-material";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onError?: (err: Error) => void;
|
onError?: (err: Error) => void;
|
||||||
@ -55,6 +61,27 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
</GuardState>
|
</GuardState>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Open App Dir" />
|
||||||
|
<IconButton
|
||||||
|
color="inherit"
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
console.log("click");
|
||||||
|
openAppDir().then(console.log).catch(console.log);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ArrowForward />
|
||||||
|
</IconButton>
|
||||||
|
</SettingItem>
|
||||||
|
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Open Logs Dir" />
|
||||||
|
<IconButton color="inherit" size="small" onClick={openLogsDir}>
|
||||||
|
<ArrowForward />
|
||||||
|
</IconButton>
|
||||||
|
</SettingItem>
|
||||||
|
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Version" />
|
<ListItemText primary="Version" />
|
||||||
<Typography sx={{ py: "6px" }}>v{version}</Typography>
|
<Typography sx={{ py: "6px" }}>v{version}</Typography>
|
||||||
|
@ -63,3 +63,11 @@ export async function patchVergeConfig(payload: CmdType.VergeConfig) {
|
|||||||
export async function getSystemProxy() {
|
export async function getSystemProxy() {
|
||||||
return invoke<any>("get_sys_proxy");
|
return invoke<any>("get_sys_proxy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function openAppDir() {
|
||||||
|
return invoke<void>("open_app_dir");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function openLogsDir() {
|
||||||
|
return invoke<void>("open_logs_dir");
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user