From ca0cf4552c75a0e869a7fe1a6ff15250518771c9 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Wed, 26 Mar 2025 17:01:48 +0800 Subject: [PATCH] add: RunningMode Display implementation and TypeScript enum --- src-tauri/src/cmd/system.rs | 8 ++------ src-tauri/src/core/core.rs | 12 +++++++++++- src/services/cmds.ts | 3 ++- src/services/types.d.ts | 10 ++++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/cmd/system.rs b/src-tauri/src/cmd/system.rs index 3c7c04e8..c978f3bf 100644 --- a/src-tauri/src/cmd/system.rs +++ b/src-tauri/src/cmd/system.rs @@ -1,6 +1,6 @@ use super::CmdResult; use crate::{ - core::{self, handle, CoreManager}, + core::{self, handle, CoreManager, RunningMode}, module::sysinfo::PlatformSpecification, }; use once_cell::sync::Lazy; @@ -44,11 +44,7 @@ pub async fn get_system_info() -> CmdResult { /// 获取当前内核运行模式 #[tauri::command] pub async fn get_running_mode() -> Result { - match CoreManager::global().get_running_mode().await { - core::RunningMode::Service => Ok("service".to_string()), - core::RunningMode::Sidecar => Ok("standalone".to_string()), - core::RunningMode::NotRunning => Ok("not_running".to_string()), - } + Ok(CoreManager::global().get_running_mode().await.to_string()) } /// 获取应用的运行时间(毫秒) diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index 38ac585e..5b6a38f1 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -16,7 +16,7 @@ use crate::{ }; use anyhow::Result; use once_cell::sync::OnceCell; -use std::{path::PathBuf, sync::Arc}; +use std::{fmt, path::PathBuf, sync::Arc}; use tauri_plugin_shell::{process::CommandChild, ShellExt}; use tokio::sync::Mutex; @@ -37,6 +37,16 @@ pub enum RunningMode { NotRunning, } +impl fmt::Display for RunningMode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RunningMode::Service => write!(f, "Service"), + RunningMode::Sidecar => write!(f, "Sidecar"), + RunningMode::NotRunning => write!(f, "NotRunning"), + } + } +} + const CLASH_CORES: [&str; 2] = ["verge-mihomo", "verge-mihomo-alpha"]; impl CoreManager { diff --git a/src/services/cmds.ts b/src/services/cmds.ts index b7af66bd..9ab2c21d 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -1,6 +1,7 @@ import dayjs from "dayjs"; import { invoke } from "@tauri-apps/api/core"; import { Notice } from "@/components/base"; +import { IRunningMode } from "./types"; export async function copyClashEnv() { return invoke("copy_clash_env"); @@ -312,7 +313,7 @@ export async function validateScriptFile(filePath: string) { // 获取当前运行模式 export const getRunningMode = async () => { - return invoke("get_running_mode"); + return invoke("get_running_mode"); }; // 获取应用运行时间 diff --git a/src/services/types.d.ts b/src/services/types.d.ts index 09ae045d..e40eda10 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -806,3 +806,13 @@ interface IWebDavConfig { username: string; password: string; } + +export enum RunningMode { + Service = "Service", + Sidecar = "Sidecar", + NotRunning = "NotRunning", +} + +export interface IRunningMode { + mode: RunningMode; +}