feat: appwide darkmode toggle and daemon connection check
This commit is contained in:
@@ -3,8 +3,5 @@
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
]
|
||||
"permissions": ["core:default", "opener:default"]
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
{
|
||||
"identifier": "desktop-capability",
|
||||
"platforms": [
|
||||
"macOS",
|
||||
"windows",
|
||||
"linux"
|
||||
],
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"global-shortcut:default"
|
||||
]
|
||||
}
|
||||
"platforms": ["macOS", "windows", "linux"],
|
||||
"windows": ["main", "dashboard", "popup"],
|
||||
"permissions": ["global-shortcut:default", "core:event:allow-listen"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use serde::Serialize;
|
||||
use tauri::{Emitter, Manager, State};
|
||||
|
||||
use feshared::{
|
||||
@@ -113,3 +114,26 @@ pub async fn daemon_state(state: State<'_, AppState>) -> Result<DaemonState, Str
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize)]
|
||||
struct DarkMode {
|
||||
is_dark_mode: bool,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn toggle_dark_mode(
|
||||
state: State<'_, AppState>,
|
||||
handle: tauri::AppHandle,
|
||||
) -> Result<bool, String> {
|
||||
let mut config = state.config.lock().await;
|
||||
config.dark_mode = !config.dark_mode;
|
||||
handle
|
||||
.emit(
|
||||
"dark-mode-changed",
|
||||
DarkMode {
|
||||
is_dark_mode: config.dark_mode,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
Ok(config.dark_mode)
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@ mod commands;
|
||||
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use commands::{chat, chat_history, daemon_state, toggle_popup};
|
||||
use commands::{chat, chat_history, daemon_state, toggle_dark_mode, toggle_popup};
|
||||
use shared::ai::ai_daemon_client::AiDaemonClient;
|
||||
|
||||
pub struct AppConfig {
|
||||
dark_mode: bool,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
grpc_client: Mutex<AiDaemonClient<tonic::transport::Channel>>,
|
||||
current_chat: Mutex<Option<i64>>,
|
||||
config: Mutex<AppConfig>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -22,14 +26,15 @@ async fn main() {
|
||||
tauri::Builder::default()
|
||||
.manage(AppState {
|
||||
grpc_client: Mutex::new(client),
|
||||
current_chat: Mutex::new(None),
|
||||
config: Mutex::new(AppConfig { dark_mode: true }),
|
||||
})
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
toggle_popup,
|
||||
chat_history,
|
||||
chat,
|
||||
daemon_state
|
||||
daemon_state,
|
||||
toggle_dark_mode,
|
||||
])
|
||||
.setup(|app| {
|
||||
/* Auto-hide popup when focus is lost
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
"label": "popup",
|
||||
"title": "AI Quick Action",
|
||||
"url": "/popup",
|
||||
"width": 800,
|
||||
"height": 400,
|
||||
"width": 960,
|
||||
"height": 720,
|
||||
"decorations": false,
|
||||
"transparent": true,
|
||||
"alwaysOnTop": true,
|
||||
|
||||
Reference in New Issue
Block a user