mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat(sysinfo): add tauri-plugin-clash-verge-sysinfo for system information retrieval (#5510)
* feat(sysinfo): add tauri-plugin-clash-verge-sysinfo for system information retrieval * feat(sysinfo): add tauri-plugin-clash-verge-sysinfo for system information retrieval * fix(service): import Manager trait for app handle in linux_running_as_root function
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
use super::{CoreManager, RunningMode};
|
||||
use crate::cmd::StringifyErr as _;
|
||||
use crate::config::{Config, IVerge};
|
||||
use crate::core::handle::Handle;
|
||||
use crate::core::{
|
||||
logger::CLASH_LOGGER,
|
||||
service::{SERVICE_MANAGER, ServiceStatus},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use scopeguard::defer;
|
||||
use smartstring::alias::String;
|
||||
use tauri_plugin_clash_verge_sysinfo;
|
||||
|
||||
impl CoreManager {
|
||||
pub async fn start_core(&self) -> Result<()> {
|
||||
self.prepare_startup().await?;
|
||||
defer! {
|
||||
self.after_core_process();
|
||||
}
|
||||
|
||||
match *self.get_running_mode() {
|
||||
RunningMode::Service => self.start_core_by_service().await,
|
||||
@@ -21,6 +27,9 @@ impl CoreManager {
|
||||
|
||||
pub async fn stop_core(&self) -> Result<()> {
|
||||
CLASH_LOGGER.clear_logs().await;
|
||||
defer! {
|
||||
self.after_core_process();
|
||||
}
|
||||
|
||||
match *self.get_running_mode() {
|
||||
RunningMode::Service => self.stop_core_by_service().await,
|
||||
@@ -74,6 +83,14 @@ impl CoreManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn after_core_process(&self) {
|
||||
let app_handle = Handle::app_handle();
|
||||
tauri_plugin_clash_verge_sysinfo::set_app_core_mode(
|
||||
app_handle,
|
||||
self.get_running_mode().to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
async fn wait_for_service_if_needed(&self) {
|
||||
use crate::{config::Config, constants::timing};
|
||||
|
||||
@@ -254,9 +254,16 @@ async fn reinstall_service() -> Result<()> {
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn linux_running_as_root() -> bool {
|
||||
const ROOT_UID: u32 = 0;
|
||||
|
||||
unsafe { libc::geteuid() == ROOT_UID }
|
||||
use crate::core::handle;
|
||||
use parking_lot::RwLock;
|
||||
use tauri::Manager as _;
|
||||
use tauri_plugin_clash_verge_sysinfo::Platform;
|
||||
let app_handle = handle::Handle::app_handle();
|
||||
app_handle
|
||||
.state::<RwLock<Platform>>()
|
||||
.read()
|
||||
.appinfo
|
||||
.app_is_admin
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
Reference in New Issue
Block a user