模块调整
This commit is contained in:
1 parent
fcbcf07b87
commit
6f875bd7b4
23 files changed
+538
-116
No files matched your search
Generated
+1
-1
@@ -7658,7 +7658,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thing"
|
||||
version = "26.10.1"
|
||||
version = "26.10.2"
|
||||
dependencies = [
|
||||
"aes 0.8.4",
|
||||
"async-trait",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "thing"
|
||||
version = "26.10.1"
|
||||
version = "26.10.2"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
@@ -9,6 +9,7 @@ mod drag_drop;
|
||||
mod dsh;
|
||||
mod logger;
|
||||
mod mihomo_manager;
|
||||
mod module_state;
|
||||
mod monitor_kernel;
|
||||
pub mod music;
|
||||
mod network_monitor;
|
||||
@@ -42,6 +43,7 @@ use download_engine::{
|
||||
use logger::{
|
||||
log_clear, log_info_state, log_list, log_message,
|
||||
};
|
||||
use module_state::module_sync_states;
|
||||
use editor::{
|
||||
editor_add_template, editor_authorize_file, editor_backlinks, editor_backup_now,
|
||||
editor_create_folder, editor_create_note, editor_daily_note, editor_delete_entry,
|
||||
@@ -253,6 +255,8 @@ fn export_bindings() {
|
||||
// 应用更新(6)
|
||||
app_version, update_check, update_install, update_thinghk_apply,
|
||||
update_thinghk_confirm, update_thinghk_cancel,
|
||||
// 模块启停(1)
|
||||
module_sync_states,
|
||||
// proxy(20)
|
||||
proxy_activate_profile, proxy_apply_kernel_update, proxy_cancel_kernel_install, proxy_check_kernel_update, proxy_clear_system_proxy,
|
||||
proxy_close_connection, proxy_confirm_install, proxy_delete_profile, proxy_get_settings,
|
||||
@@ -495,6 +499,7 @@ pub fn run() {
|
||||
update_thinghk_apply,
|
||||
update_thinghk_confirm,
|
||||
update_thinghk_cancel,
|
||||
module_sync_states,
|
||||
process_start,
|
||||
process_stop,
|
||||
process_status,
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
//! 模块启停状态的 Rust 侧镜像与统一同步入口。
|
||||
//!
|
||||
//! 前端把「已禁用模块列表」持久化在 WebView 的 localStorage 里,Rust 启动阶段
|
||||
//! (WebView 就绪之前)读不到它。于是会出现:用户在设置里禁用了截图 / 编辑器 /
|
||||
//! 翻译等模块,重启后 Rust 仍按「全部启用」注册全局快捷键、自动拉起后台服务、
|
||||
//! 预创建常驻窗口。
|
||||
//!
|
||||
//! 这里的做法:
|
||||
//! - 前端在启动完成和每次切换模块后调用 [`module_sync_states`],把完整禁用列表
|
||||
//! 落到 `{app_data_dir}/module_states.json`,并立即同步 Rust 侧副作用;
|
||||
//! - `setup` 启动阶段先读该文件,再决定是否注册快捷键 / 自动启动 / 预创建窗口。
|
||||
//!
|
||||
//! 只覆盖 Rust 侧拥有的资源;前端拥有的资源(终端会话、播放器、OSD store 等)
|
||||
//! 由各模块自己的 `onEnable` / `onDisable` 生命周期处理。
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Mutex;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::clipboard::ClipboardManager;
|
||||
use crate::diff::DiffManager;
|
||||
use crate::editor::EditorManager;
|
||||
|
||||
const FILE_NAME: &str = "module_states.json";
|
||||
|
||||
/// 文件尚未生成(首次启动)时的兜底:与各模块 `defaultEnabled` 保持一致。
|
||||
const DEFAULT_DISABLED: &[&str] = &["smarthome"];
|
||||
|
||||
/// `setup` 是否已返回。启动期间主线程正在逐个创建隐藏窗口(剪贴板 / 快速面板 /
|
||||
/// 托盘菜单…)并阻塞在 WebView2 初始化上;此时若 IPC 线程在本命令里同步发起
|
||||
/// 窗口创建或快捷键注册,主线程与 IPC 线程会互等 —— 浏览器进程随之冻结,
|
||||
/// 表现为「进程在、主窗口不显示、所有 IPC 无响应」。因此启动阶段只落盘,
|
||||
/// 副作用延后到 [`finish_setup`]。
|
||||
static SETUP_DONE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// 启动阶段收到的禁用列表(最后一次),由 [`finish_setup`] 补应用。
|
||||
static PENDING_DISABLED: Mutex<Option<Vec<String>>> = Mutex::new(None);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ModuleStatesFile {
|
||||
/// 已禁用模块 id(完整列表;未列出的按启用处理)
|
||||
#[serde(default)]
|
||||
disabled: Vec<String>,
|
||||
}
|
||||
|
||||
fn file_path(app_data_dir: &Path) -> PathBuf {
|
||||
app_data_dir.join(FILE_NAME)
|
||||
}
|
||||
|
||||
/// 读取已禁用模块集合(setup 启动阶段调用)。
|
||||
pub fn load_disabled(app_data_dir: &Path) -> HashSet<String> {
|
||||
let fallback = || DEFAULT_DISABLED.iter().map(|s| s.to_string()).collect();
|
||||
match std::fs::read_to_string(file_path(app_data_dir)) {
|
||||
Ok(raw) => match serde_json::from_str::<ModuleStatesFile>(&raw) {
|
||||
Ok(file) => file.disabled.into_iter().collect(),
|
||||
Err(e) => {
|
||||
crate::logger::log_warn(
|
||||
"module",
|
||||
&format!("模块状态文件解析失败,按默认值处理: {e}"),
|
||||
);
|
||||
fallback()
|
||||
}
|
||||
},
|
||||
Err(_) => fallback(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_enabled(disabled: &HashSet<String>, id: &str) -> bool {
|
||||
!disabled.contains(id)
|
||||
}
|
||||
|
||||
fn save_disabled(app: &AppHandle, disabled: &HashSet<String>) -> Result<(), String> {
|
||||
let dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|e| format!("获取数据目录失败: {e}"))?;
|
||||
let payload = ModuleStatesFile {
|
||||
disabled: disabled.iter().cloned().collect(),
|
||||
};
|
||||
let text = serde_json::to_string_pretty(&payload)
|
||||
.map_err(|e| format!("序列化模块状态失败: {e}"))?;
|
||||
std::fs::write(file_path(&dir), text).map_err(|e| format!("写入模块状态失败: {e}"))
|
||||
}
|
||||
|
||||
/// 前端启动完成 / 切换模块后调用:持久化禁用列表并同步 Rust 侧副作用。
|
||||
///
|
||||
/// 幂等:重复调用等价于「按当前状态重新应用一次」,不会留下重复注册。
|
||||
///
|
||||
/// `setup` 尚未返回时(应用启动阶段)只落盘并暂存,副作用延后到
|
||||
/// [`finish_setup`]:启动期间主线程忙于创建隐藏窗口,此处若同步创建窗口
|
||||
/// 会与主线程互等,导致整个界面卡在「进程在但窗口不显示」。
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn module_sync_states(app: AppHandle, disabled: Vec<String>) -> Result<(), String> {
|
||||
let disabled: HashSet<String> = disabled.into_iter().collect();
|
||||
save_disabled(&app, &disabled)?;
|
||||
|
||||
if !SETUP_DONE.load(Ordering::SeqCst) {
|
||||
let mut pending = PENDING_DISABLED.lock().unwrap_or_else(|e| e.into_inner());
|
||||
*pending = Some(disabled.into_iter().collect());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
apply_all(&app, &disabled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `setup` 末尾调用:标记启动完成,并补应用启动期间收到的模块状态。
|
||||
pub fn finish_setup(app: &AppHandle) {
|
||||
SETUP_DONE.store(true, Ordering::SeqCst);
|
||||
|
||||
let pending = PENDING_DISABLED
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.take();
|
||||
if let Some(pending) = pending {
|
||||
let disabled: HashSet<String> = pending.into_iter().collect();
|
||||
apply_all(app, &disabled);
|
||||
}
|
||||
}
|
||||
|
||||
/// 按禁用列表同步全部 Rust 侧副作用(快捷键 / 后台服务 / 预创建窗口)。
|
||||
fn apply_all(app: &AppHandle, disabled: &HashSet<String>) {
|
||||
apply_clipboard(app, is_enabled(disabled, "clipboard"));
|
||||
apply_quickpanel(app, is_enabled(disabled, "quickpanel"));
|
||||
apply_translate(app, is_enabled(disabled, "translate"));
|
||||
apply_editor(app, is_enabled(disabled, "editor"));
|
||||
apply_diff(app, is_enabled(disabled, "diff"));
|
||||
|
||||
crate::logger::log_info(
|
||||
"module",
|
||||
&format!(
|
||||
"模块状态已同步,禁用: [{}]",
|
||||
disabled.iter().cloned().collect::<Vec<_>>().join(", ")
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
fn log_err(module: &str, result: Result<(), String>) {
|
||||
if let Err(e) = result {
|
||||
crate::logger::log_warn(module, &format!("模块启停同步失败: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// 剪贴板:监听线程 + 快捷弹窗快捷键 + 预创建弹窗。
|
||||
pub fn apply_clipboard(app: &AppHandle, enabled: bool) {
|
||||
let Some(manager) = app.try_state::<ClipboardManager>() else {
|
||||
return;
|
||||
};
|
||||
if enabled {
|
||||
if manager.get_settings().enabled {
|
||||
manager.start(app);
|
||||
}
|
||||
let shortcut = manager.get_settings().shortcut;
|
||||
if !shortcut.trim().is_empty() {
|
||||
log_err(
|
||||
"clipboard",
|
||||
crate::shortcut::register_shortcut(app, "剪贴板", &shortcut, |a| {
|
||||
crate::clipboard::popup::show_popup(a)
|
||||
}),
|
||||
);
|
||||
// 预创建弹窗窗口(隐藏),首次按快捷键时直接 show,避免首次创建时序问题
|
||||
crate::clipboard::popup::ensure_popup_window(app);
|
||||
crate::clipboard::popup::ensure_preview_window(app);
|
||||
}
|
||||
} else {
|
||||
manager.stop();
|
||||
crate::shortcut::unregister_shortcut(app, "剪贴板");
|
||||
crate::clipboard::popup::hide_popup(app);
|
||||
crate::clipboard::popup::hide_preview(app);
|
||||
}
|
||||
}
|
||||
|
||||
/// 快速面板:全局快捷键 + 预创建弹窗窗口。
|
||||
pub fn apply_quickpanel(app: &AppHandle, enabled: bool) {
|
||||
if enabled {
|
||||
let settings = crate::quickpanel::load_settings(app);
|
||||
if !settings.shortcut.trim().is_empty() {
|
||||
log_err(
|
||||
"quickpanel",
|
||||
crate::shortcut::register_shortcut(app, "快速面板", &settings.shortcut, |a| {
|
||||
crate::quickpanel::popup::show_popup(a)
|
||||
}),
|
||||
);
|
||||
// 预创建弹窗窗口(隐藏),首次按快捷键时直接 show,避免首次创建时序问题
|
||||
crate::quickpanel::ensure_window(app);
|
||||
}
|
||||
} else {
|
||||
crate::shortcut::unregister_shortcut(app, "快速面板");
|
||||
crate::quickpanel::popup::hide_popup(app);
|
||||
}
|
||||
}
|
||||
|
||||
/// 翻译:面板全局快捷键 + 预创建悬浮窗。
|
||||
pub fn apply_translate(app: &AppHandle, enabled: bool) {
|
||||
if enabled {
|
||||
crate::translate::init_on_launch(app);
|
||||
} else {
|
||||
crate::translate::disable_on_module_off(app);
|
||||
}
|
||||
}
|
||||
|
||||
/// 编辑器:新建笔记 / 打开编辑器两个全局快捷键。
|
||||
pub fn apply_editor(app: &AppHandle, enabled: bool) {
|
||||
let Some(manager) = app.try_state::<EditorManager>() else {
|
||||
return;
|
||||
};
|
||||
if enabled {
|
||||
manager.init_on_launch(app);
|
||||
} else {
|
||||
crate::shortcut::unregister_shortcut(app, "editor-new-note");
|
||||
crate::shortcut::unregister_shortcut(app, "editor-open-editor");
|
||||
}
|
||||
}
|
||||
|
||||
/// 对比工具:打开对比窗口全局快捷键。
|
||||
pub fn apply_diff(app: &AppHandle, enabled: bool) {
|
||||
let Some(manager) = app.try_state::<DiffManager>() else {
|
||||
return;
|
||||
};
|
||||
if enabled {
|
||||
manager.init_on_launch(app);
|
||||
} else {
|
||||
crate::shortcut::unregister_shortcut(app, "diff-open-window");
|
||||
}
|
||||
}
|
||||
+51
-57
@@ -47,6 +47,12 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
.app_data_dir()
|
||||
.unwrap_or_else(|_| std::path::PathBuf::from("."));
|
||||
|
||||
// ===== 模块启停状态:Rust 侧镜像 =====
|
||||
// 前端每次切换模块都会写回这份文件;启动阶段先读它,避免为已禁用模块
|
||||
// 注册全局快捷键、自动拉起后台服务或预创建常驻窗口。
|
||||
let disabled_modules = crate::module_state::load_disabled(&app_data_dir);
|
||||
let module_enabled = |id: &str| crate::module_state::is_enabled(&disabled_modules, id);
|
||||
|
||||
// ===== 代理模块:MihomoManager =====
|
||||
let mihomo = MihomoManager::new(app_data_dir.clone());
|
||||
app.manage(mihomo);
|
||||
@@ -63,7 +69,10 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
app.manage(music);
|
||||
|
||||
// ===== 手机互联:按设置自启(RemoteManager 本体在 lib.rs 平级 manage)=====
|
||||
crate::music::init_on_launch(app.handle());
|
||||
// 音乐模块禁用时不恢复手机遥控连接。
|
||||
if module_enabled("music") {
|
||||
crate::music::init_on_launch(app.handle());
|
||||
}
|
||||
|
||||
// ===== AI 模块:AiManager(全局供应商配置,主设置 → AI 服务)=====
|
||||
// 迁移必须在建 State 之前跑:把旧版存在翻译设置里的 AI 引擎(含密钥)搬过来,
|
||||
@@ -84,9 +93,9 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 仅注册状态:库扫描与读写都在命令调用时按需触发,启动阶段只创建目录结构。
|
||||
let notes = EditorManager::new(app_data_dir.clone());
|
||||
let _ = notes.load_settings();
|
||||
// 按设置注册「新建笔记 / 打开编辑器」两个全局快捷键(失败只记日志,不阻断启动)
|
||||
notes.init_on_launch(app.handle());
|
||||
app.manage(notes);
|
||||
// 按模块启停状态注册「新建笔记 / 打开编辑器」两个全局快捷键(失败只记日志,不阻断启动)
|
||||
crate::module_state::apply_editor(app.handle(), module_enabled("editor"));
|
||||
// 「用 Thing 打开」的**冷启动**路径:命令行里带了 .md 就记下来。
|
||||
// 不在这里 `emit` —— 此时 WebView 还没加载、前端还没注册监听,事件会丢掉。
|
||||
// 前端注册完监听后会主动调 `editor_take_pending_file` 取走(见 editor/args.rs)。
|
||||
@@ -99,8 +108,8 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 只承担设置的读写与「打开对比窗口」全局快捷键(默认 Alt+C)的注册;
|
||||
// 左右目标(比哪两个文件 / 目录)是前端会话状态,Rust 侧不需要知道。
|
||||
let diff = DiffManager::new(app_data_dir.clone());
|
||||
diff.init_on_launch(app.handle());
|
||||
app.manage(diff);
|
||||
crate::module_state::apply_diff(app.handle(), module_enabled("diff"));
|
||||
|
||||
// ===== 智能家居模块:HaManager(Home Assistant 对接) =====
|
||||
// 仅注册状态:连接与令牌都在命令调用时按需读取,**启动阶段不发任何网络请求**。
|
||||
@@ -109,7 +118,8 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
app.manage(smarthome);
|
||||
// P4:用户上次开着「实时推送」或「本地规则总开关」时,启动后恢复 WS 连接。
|
||||
// 放在后台任务里(不阻塞启动),且**只有用户显式开过才会连** —— 与"启动不发请求"一致。
|
||||
{
|
||||
// 模块被禁用时跳过;重新启用时由该模块 onEnable 调 smarthome_ws_start 恢复。
|
||||
if module_enabled("smarthome") {
|
||||
let handle = app.handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let manager = handle.state::<HaManager>();
|
||||
@@ -122,9 +132,9 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// (模型可用性校验因此改为懒校验:首次翻译失败时解释原因 + 设置页手动拉取模型列表)。
|
||||
let translate = TranslateManager::new(app_data_dir.clone());
|
||||
app.manage(translate);
|
||||
// 按设置注册「翻译取词 / 翻译剪贴板」两个全局快捷键并预创建悬浮窗。
|
||||
// 按设置注册翻译面板全局快捷键并预创建悬浮窗;模块禁用时注销并隐藏。
|
||||
// 失败只记日志(快捷键被占用不该阻断启动)。
|
||||
crate::translate::init_on_launch(app.handle());
|
||||
crate::module_state::apply_translate(app.handle(), module_enabled("translate"));
|
||||
|
||||
// ===== 终端模块:TerminalManager =====
|
||||
// 仅注册状态 + 做一次 Shell 探测,**不建立任何 SSH 连接**
|
||||
@@ -150,54 +160,28 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let settings = engine.get_settings();
|
||||
app.manage(engine.clone());
|
||||
|
||||
let server_engine = engine.clone();
|
||||
let server_port = settings.extension_port;
|
||||
let server_secret = settings.extension_secret.clone();
|
||||
let server_app = app.handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
ExtensionServer::start(server_engine, server_port, server_secret, server_app).await;
|
||||
});
|
||||
// 扩展 HTTP 服务只在下载模块启用时监听:模块禁用后不应继续接受浏览器扩展请求。
|
||||
// 注:运行期重新启用下载模块不会补起该服务(需要重启应用),这是当前服务的生命周期限制。
|
||||
if module_enabled("downloader") {
|
||||
let server_engine = engine.clone();
|
||||
let server_port = settings.extension_port;
|
||||
let server_secret = settings.extension_secret.clone();
|
||||
let server_app = app.handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
ExtensionServer::start(server_engine, server_port, server_secret, server_app).await;
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 剪贴板模块:监听 + 快捷键 + 预创建弹窗 =====
|
||||
let clipboard = crate::clipboard::ClipboardManager::new(app_data_dir.clone());
|
||||
// 应用启动时若已启用则自动开始监听
|
||||
if clipboard.get_settings().enabled {
|
||||
clipboard.start(&app.handle());
|
||||
}
|
||||
// 应用启动时注册快捷弹窗全局快捷键(共享工具模块)
|
||||
let shortcut = clipboard.get_settings().shortcut.clone();
|
||||
if !shortcut.trim().is_empty() {
|
||||
let app_handle = app.handle().clone();
|
||||
if let Err(e) = crate::shortcut::register_shortcut(&app_handle, "剪贴板", &shortcut, |a| {
|
||||
crate::clipboard::popup::show_popup(a)
|
||||
}) {
|
||||
crate::logger::log_error("clipboard", &format!("快捷键注册失败: {}", e));
|
||||
}
|
||||
// 预创建弹窗窗口(隐藏),首次按快捷键时直接 show,避免首次创建时序问题
|
||||
crate::clipboard::popup::ensure_popup_window(&app_handle);
|
||||
// 同时预创建独立预览窗口(隐藏),弹窗悬停条目时直接显示
|
||||
crate::clipboard::popup::ensure_preview_window(&app_handle);
|
||||
}
|
||||
app.manage(clipboard);
|
||||
// 监听线程 + 快捷键 + 预创建弹窗统一由模块状态决定(禁用时不占快捷键、不建窗口)
|
||||
crate::module_state::apply_clipboard(app.handle(), module_enabled("clipboard"));
|
||||
|
||||
// ===== 快速面板:快捷键 + 预创建弹窗 =====
|
||||
// defaultEnabled:true 假设启用;用户在设置页禁用模块时由前端 onDisable 钩子注销快捷键。
|
||||
// 文件索引 DB 连接改为懒加载(首次搜索/构建时由 commands 中的 ensure_initialized 触发),
|
||||
// 避免应用启动时即打开 SQLite 连接,降低启动 IO 开销。
|
||||
let qp_settings = crate::quickpanel::load_settings(&app.handle());
|
||||
if !qp_settings.shortcut.trim().is_empty() {
|
||||
let app_handle = app.handle().clone();
|
||||
if let Err(e) = crate::shortcut::register_shortcut(
|
||||
&app_handle,
|
||||
"快速面板",
|
||||
&qp_settings.shortcut,
|
||||
|a| crate::quickpanel::popup::show_popup(a),
|
||||
) {
|
||||
crate::logger::log_error("quickpanel", &format!("快捷键注册失败: {}", e));
|
||||
}
|
||||
// 预创建弹窗窗口(隐藏),首次按快捷键时直接 show,避免首次创建时序问题
|
||||
crate::quickpanel::ensure_window(&app_handle);
|
||||
}
|
||||
crate::module_state::apply_quickpanel(app.handle(), module_enabled("quickpanel"));
|
||||
|
||||
// ===== 托盘菜单 =====
|
||||
crate::tray_menu::create_tray_menu(app.handle())?;
|
||||
@@ -208,25 +192,35 @@ pub fn init(app: &mut App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// ===== 代理:自动切换节点后台调度(独立于模块激活状态) =====
|
||||
crate::mihomo_manager::start_auto_switch_loop(app.handle().clone());
|
||||
|
||||
// ===== 自动启动(随应用启动,不依赖模块启用) =====
|
||||
// mihomo:用户在设置中开启"自动启动"时随应用启动
|
||||
if let Some(mihomo) = app.try_state::<MihomoManager>() {
|
||||
if let Some(pm) = app.try_state::<ProcessManager>() {
|
||||
mihomo.auto_start_on_launch(app.handle(), &pm);
|
||||
// ===== 自动启动(仅对已启用模块生效) =====
|
||||
// mihomo:模块启用且用户在设置中开启"自动启动"时随应用启动
|
||||
if module_enabled("proxy") {
|
||||
if let Some(mihomo) = app.try_state::<MihomoManager>() {
|
||||
if let Some(pm) = app.try_state::<ProcessManager>() {
|
||||
mihomo.auto_start_on_launch(app.handle(), &pm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// monitor Kernel:用户在设置中开启"自动启动"时随应用启动
|
||||
if let Some(monitor) = app.try_state::<MonitorKernel>() {
|
||||
monitor.auto_start_on_launch(app.handle());
|
||||
// monitor Kernel:模块启用且用户开启"自动启动"时随应用启动
|
||||
if module_enabled("monitor") {
|
||||
if let Some(monitor) = app.try_state::<MonitorKernel>() {
|
||||
monitor.auto_start_on_launch(app.handle());
|
||||
}
|
||||
}
|
||||
|
||||
// dsh:开启"自动启动"且已安装时拉起 Web 服务(后台线程执行就绪探测,不阻塞启动)。
|
||||
// dsh:模块启用、开启"自动启动"且已安装时拉起 Web 服务(后台线程执行就绪探测,不阻塞启动)。
|
||||
// 「打开独立窗口」快捷键由前端 dshStore 启动时注册(同截图模块约定)。
|
||||
crate::dsh::autostart_if_enabled(app.handle());
|
||||
if module_enabled("dsh") {
|
||||
crate::dsh::autostart_if_enabled(app.handle());
|
||||
}
|
||||
|
||||
// 截图快捷键由前端 screenshotStore 启动时调用 screenshot_register_shortcut 注册
|
||||
// (支持自定义,默认 F3),此处不再硬编码注册
|
||||
|
||||
// 启动阶段的窗口创建已全部完成:解除 module_sync_states 的延后标记,
|
||||
// 并补应用前端在启动过程中同步过来的模块状态(此前只落盘、不产生副作用)。
|
||||
crate::module_state::finish_setup(app.handle());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -85,6 +85,12 @@ pub fn init_on_launch(app: &tauri::AppHandle) {
|
||||
}
|
||||
}
|
||||
|
||||
/// 模块被禁用时注销面板快捷键并隐藏悬浮窗(与 [`init_on_launch`] 对称)。
|
||||
pub fn disable_on_module_off(app: &tauri::AppHandle) {
|
||||
crate::shortcut::unregister_shortcut(app, "翻译面板");
|
||||
popup::hide(app);
|
||||
}
|
||||
|
||||
/// 读取某引擎实例的 API Key(未配置或读取失败 → 空串)。
|
||||
///
|
||||
/// AI 引擎(kind = "ai")的密钥在 `ai-provider-*`,走 [`crate::ai::provider_api_key`];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "thing",
|
||||
"version": "26.10.1",
|
||||
"version": "26.10.2",
|
||||
"identifier": "thing.lfeng.me",
|
||||
"build": {
|
||||
"beforeDevCommand": "bun run dev",
|
||||
|
||||
Reference in new issue
Block a user