From a1bb1feadd388bbf2bebddd0628de4b4ad120b71 Mon Sep 17 00:00:00 2001 From: VirtualHotBar <96966978+VirtualHotBar@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:56:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/autostart.rs | 8 +++++--- src-tauri/src/main.rs | 12 +++++++----- src-tauri/src/utils.rs | 1 + src/controller/main.ts | 2 ++ src/controller/storage/mount/mount.ts | 3 +-- src/main.tsx | 1 + src/utils/rclone/process.ts | 8 ++++++-- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/autostart.rs b/src-tauri/src/autostart.rs index ccaf407..d5ff2e4 100644 --- a/src-tauri/src/autostart.rs +++ b/src-tauri/src/autostart.rs @@ -59,6 +59,8 @@ pub fn is_autostart() -> io::Result { pub fn set_autostart(enabled: bool) -> io::Result<()> { use std::fs::File; use std::io::prelude::*; + use std::path::Path; + let exe_path = env::current_exe()?; let exe_path_str = exe_path .to_str() @@ -109,8 +111,8 @@ WantedBy=multi-user.target } #[cfg(target_os = "linux")] -pub fn is_autostart(service_name: &str) -> bool { +pub fn is_autostart() -> io::Result { use std::path::Path; - let file_path = format!("/etc/systemd/system/{}.service", service_name); - Path::new(&file_path).exists() + let file_path = format!("/etc/systemd/system/{}.service", "netmount"); + Ok(Path::new(&file_path).exists()) } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7767098..f02eec4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -18,8 +18,11 @@ mod localized; use crate::autostart::is_autostart; use crate::autostart::set_autostart; use crate::utils::download_with_progress; +#[cfg(target_os = "windows")] use crate::utils::find_first_available_drive_letter; +#[cfg(target_os = "windows")] use crate::utils::set_window_shadow; +#[cfg(target_os = "windows")] use crate::utils::is_winfsp_installed; //use crate::localized::LANGUAGE_PACK; @@ -40,10 +43,6 @@ fn main() { // 根据不同的操作系统配置Tauri Builder let builder = tauri::Builder::default() - .setup(|app| { - set_window_shadow(app); // 设置窗口阴影 - Ok(()) - }) .system_tray(tray::menu()) // 设置系统托盘菜单 .on_system_tray_event(tray::handler) // 设置系统托盘事件处理器 .invoke_handler(tauri::generate_handler![ @@ -60,7 +59,10 @@ fn main() { let builder = builder.invoke_handler(tauri::generate_handler![ get_winfsp_install_state, get_available_drive_letter - ]); + ]).setup(|app| { + set_window_shadow(app); // 设置窗口阴影 + Ok(()) + }); // 运行Tauri应用,使用`generate_context!()`来加载应用配置 builder.run(tauri::generate_context!()).expect("error while running tauri application"); diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index ca18d51..668375b 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -7,6 +7,7 @@ use std::fs; use std::io::{self, Write}; //use tauri::AppHandle; +#[cfg(target_os = "windows")] pub fn set_window_shadow(app: &tauri::App) { let window = app.get_window("main").unwrap(); set_shadow(&window, true).expect("Unsupported platform!"); diff --git a/src/controller/main.ts b/src/controller/main.ts index 634e5c2..40ff7a7 100644 --- a/src/controller/main.ts +++ b/src/controller/main.ts @@ -18,6 +18,7 @@ import { setLocalized } from "./language/localized" import { checkNotice } from "./update/notice" async function init(setStartStr: Function) { + setStartStr(t('init')) listenWindow() @@ -27,6 +28,7 @@ async function init(setStartStr: Function) { setStartStr(t('read_config')) await readNmConfig() + if (nmConfig.settings.startHide) { windowsHide() } diff --git a/src/controller/storage/mount/mount.ts b/src/controller/storage/mount/mount.ts index 669adef..cc1b4af 100644 --- a/src/controller/storage/mount/mount.ts +++ b/src/controller/storage/mount/mount.ts @@ -9,11 +9,10 @@ import { rclone_api_post } from "../../../utils/rclone/request" //列举存储 async function reupMount(noRefreshUI?: boolean) { - const mountPoints = (await rclone_api_post( '/mount/listmounts', )).mountPoints - rcloneInfo.mountList = [] + rcloneInfo.mountList = []; if (mountPoints) { mountPoints.forEach((tiem: any) => { diff --git a/src/main.tsx b/src/main.tsx index 355be32..6dfaf7d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -36,6 +36,7 @@ let appStarting = false async function appStart(setStartStr: Function) { if (appStarting) { return }//避免重新执行 appStarting = true +1 await init(setStartStr)//初始化功能 reactRoot.render( diff --git a/src/utils/rclone/process.ts b/src/utils/rclone/process.ts index fd5ed35..479e0fe 100644 --- a/src/utils/rclone/process.ts +++ b/src/utils/rclone/process.ts @@ -26,8 +26,12 @@ async function startRclone() { rcloneInfo.process.command = new Command('rclone', args) rcloneInfo.process.log='' - rcloneInfo.process.command.stdout.on('data', (data) => { rcloneInfo.process.log += data }) - rcloneInfo.process.command.stderr.on('data', (data) => { rcloneInfo.process.log += data }) + const addLog= (data:string) => { rcloneInfo.process.log += data ; + console.log(data); + } + + rcloneInfo.process.command.stdout.on('data',(data) => addLog(data)) + rcloneInfo.process.command.stderr.on('data', (data) => addLog(data)) rcloneInfo.process.child = await rcloneInfo.process.command.spawn()