add: RunningMode Display implementation and TypeScript enum

This commit is contained in:
Tunglies 2025-03-26 17:01:48 +08:00
parent d91653b218
commit ca0cf4552c
4 changed files with 25 additions and 8 deletions

View File

@ -1,6 +1,6 @@
use super::CmdResult; use super::CmdResult;
use crate::{ use crate::{
core::{self, handle, CoreManager}, core::{self, handle, CoreManager, RunningMode},
module::sysinfo::PlatformSpecification, module::sysinfo::PlatformSpecification,
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -44,11 +44,7 @@ pub async fn get_system_info() -> CmdResult<String> {
/// 获取当前内核运行模式 /// 获取当前内核运行模式
#[tauri::command] #[tauri::command]
pub async fn get_running_mode() -> Result<String, String> { pub async fn get_running_mode() -> Result<String, String> {
match CoreManager::global().get_running_mode().await { Ok(CoreManager::global().get_running_mode().await.to_string())
core::RunningMode::Service => Ok("service".to_string()),
core::RunningMode::Sidecar => Ok("standalone".to_string()),
core::RunningMode::NotRunning => Ok("not_running".to_string()),
}
} }
/// 获取应用的运行时间(毫秒) /// 获取应用的运行时间(毫秒)

View File

@ -16,7 +16,7 @@ use crate::{
}; };
use anyhow::Result; use anyhow::Result;
use once_cell::sync::OnceCell; 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 tauri_plugin_shell::{process::CommandChild, ShellExt};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -37,6 +37,16 @@ pub enum RunningMode {
NotRunning, 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"]; const CLASH_CORES: [&str; 2] = ["verge-mihomo", "verge-mihomo-alpha"];
impl CoreManager { impl CoreManager {

View File

@ -1,6 +1,7 @@
import dayjs from "dayjs"; import dayjs from "dayjs";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { Notice } from "@/components/base"; import { Notice } from "@/components/base";
import { IRunningMode } from "./types";
export async function copyClashEnv() { export async function copyClashEnv() {
return invoke<void>("copy_clash_env"); return invoke<void>("copy_clash_env");
@ -312,7 +313,7 @@ export async function validateScriptFile(filePath: string) {
// 获取当前运行模式 // 获取当前运行模式
export const getRunningMode = async () => { export const getRunningMode = async () => {
return invoke<string>("get_running_mode"); return invoke<IRunningMode>("get_running_mode");
}; };
// 获取应用运行时间 // 获取应用运行时间

View File

@ -806,3 +806,13 @@ interface IWebDavConfig {
username: string; username: string;
password: string; password: string;
} }
export enum RunningMode {
Service = "Service",
Sidecar = "Sidecar",
NotRunning = "NotRunning",
}
export interface IRunningMode {
mode: RunningMode;
}