mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-09-24 23:10:56 +08:00
fix: Windows 最小化到托盘无效 (#30)
- 添加 minimize_to_tray 配置字段到 Config 结构体 - 添加 on_window_event 处理器拦截窗口关闭事件 - 前端设置页面支持保存最小化到托盘选项 - 默认启用最小化到托盘功能 Closes #30
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "proxycast",
|
||||
"private": true,
|
||||
"version": "0.17.2",
|
||||
"version": "0.17.3",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Generated
+1
-1
@@ -3377,7 +3377,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proxycast"
|
||||
version = "0.17.2"
|
||||
version = "0.17.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-stream",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "proxycast"
|
||||
version = "0.17.2"
|
||||
version = "0.17.3"
|
||||
description = "AI API Proxy Desktop App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
@@ -308,6 +308,13 @@ pub struct Config {
|
||||
/// 允许为不同的客户端端点(CC/Codex)配置不同的 Provider
|
||||
#[serde(default)]
|
||||
pub endpoint_providers: EndpointProvidersConfig,
|
||||
/// 关闭时最小化到托盘(而不是退出应用)
|
||||
#[serde(default = "default_minimize_to_tray")]
|
||||
pub minimize_to_tray: bool,
|
||||
}
|
||||
|
||||
fn default_minimize_to_tray() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// 服务器配置
|
||||
@@ -771,6 +778,7 @@ impl Default for Config {
|
||||
proxy_url: None,
|
||||
ampcode: AmpConfig::default(),
|
||||
endpoint_providers: EndpointProvidersConfig::default(),
|
||||
minimize_to_tray: default_minimize_to_tray(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1687,6 +1687,31 @@ pub fn run() {
|
||||
.manage(bookmark_manager_state)
|
||||
.manage(enhanced_stats_service_state)
|
||||
.manage(batch_operations_state)
|
||||
.on_window_event(move |window, event| {
|
||||
// 处理窗口关闭事件
|
||||
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
|
||||
// 获取配置,检查是否启用最小化到托盘
|
||||
let app_handle = window.app_handle();
|
||||
if let Some(app_state) = app_handle.try_state::<AppState>() {
|
||||
// 使用 block_on 同步获取配置
|
||||
let minimize_to_tray = tauri::async_runtime::block_on(async {
|
||||
let state = app_state.read().await;
|
||||
state.config.minimize_to_tray
|
||||
});
|
||||
|
||||
if minimize_to_tray {
|
||||
// 阻止默认关闭行为
|
||||
api.prevent_close();
|
||||
// 隐藏窗口而不是关闭
|
||||
if let Err(e) = window.hide() {
|
||||
tracing::error!("[窗口] 隐藏窗口失败: {}", e);
|
||||
} else {
|
||||
tracing::info!("[窗口] 窗口已最小化到托盘");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.setup(move |app| {
|
||||
// 初始化托盘管理器
|
||||
// Requirements 1.4: 应用启动时显示停止状态图标
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "ProxyCast",
|
||||
"version": "0.17.2",
|
||||
"version": "0.17.3",
|
||||
"identifier": "com.proxycast.app",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
|
||||
@@ -38,6 +38,8 @@ export function GeneralSettings() {
|
||||
const c = await getConfig();
|
||||
setConfig(c);
|
||||
setProxyUrl(c.proxy_url || "");
|
||||
// 加载最小化到托盘设置
|
||||
setMinimizeToTray(c.minimize_to_tray ?? true);
|
||||
} catch (e) {
|
||||
console.error("加载配置失败:", e);
|
||||
} finally {
|
||||
@@ -248,7 +250,20 @@ export function GeneralSettings() {
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={minimizeToTray}
|
||||
onChange={(e) => setMinimizeToTray(e.target.checked)}
|
||||
onChange={async (e) => {
|
||||
const newValue = e.target.checked;
|
||||
setMinimizeToTray(newValue);
|
||||
if (config) {
|
||||
try {
|
||||
await saveConfig({ ...config, minimize_to_tray: newValue });
|
||||
setConfig({ ...config, minimize_to_tray: newValue });
|
||||
} catch (err) {
|
||||
console.error("保存最小化到托盘设置失败:", err);
|
||||
// 恢复原值
|
||||
setMinimizeToTray(!newValue);
|
||||
}
|
||||
}
|
||||
}}
|
||||
className="w-4 h-4 rounded border-gray-300"
|
||||
/>
|
||||
</label>
|
||||
|
||||
@@ -146,6 +146,8 @@ export interface Config {
|
||||
ampcode: AmpConfig;
|
||||
credential_pool: CredentialPoolConfig;
|
||||
proxy_url: string | null;
|
||||
/** 关闭时最小化到托盘(而不是退出应用) */
|
||||
minimize_to_tray: boolean;
|
||||
}
|
||||
|
||||
export interface LogEntry {
|
||||
|
||||
Reference in New Issue
Block a user