feat: add global-shortcut plugin and mini timer window commands
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::AppState;
|
||||
use crate::os_detection;
|
||||
use rusqlite::params;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::State;
|
||||
use tauri::{Manager, State};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Client {
|
||||
@@ -885,7 +885,7 @@ pub fn get_timesheet_data(state: State<AppState>, week_start: String) -> Result<
|
||||
"color": color,
|
||||
"task_id": task_id,
|
||||
"task_name": task_name,
|
||||
"days": [0i64; 7]
|
||||
"days": vec![0i64; 7]
|
||||
})
|
||||
});
|
||||
// Find which day index this entry_date corresponds to
|
||||
@@ -1052,3 +1052,33 @@ pub fn import_json_data(state: State<AppState>, data: serde_json::Value) -> Resu
|
||||
|
||||
Ok(counts)
|
||||
}
|
||||
|
||||
// Mini timer window commands
|
||||
#[tauri::command]
|
||||
pub fn open_mini_timer(app: tauri::AppHandle) -> Result<(), String> {
|
||||
use tauri::WebviewUrl;
|
||||
|
||||
if app.get_webview_window("mini-timer").is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tauri::WebviewWindowBuilder::new(&app, "mini-timer", WebviewUrl::App("/mini-timer".into()))
|
||||
.title("Timer")
|
||||
.inner_size(300.0, 64.0)
|
||||
.always_on_top(true)
|
||||
.decorations(false)
|
||||
.resizable(false)
|
||||
.skip_taskbar(true)
|
||||
.build()
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn close_mini_timer(app: tauri::AppHandle) -> Result<(), String> {
|
||||
if let Some(window) = app.get_webview_window("mini-timer") {
|
||||
window.close().map_err(|e| e.to_string())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_notification::init())
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.manage(AppState { db: Mutex::new(conn) })
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::get_clients,
|
||||
@@ -82,6 +83,8 @@ pub fn run() {
|
||||
commands::get_timesheet_data,
|
||||
commands::import_entries,
|
||||
commands::import_json_data,
|
||||
commands::open_mini_timer,
|
||||
commands::close_mini_timer,
|
||||
])
|
||||
.setup(|app| {
|
||||
#[cfg(desktop)]
|
||||
|
||||
Reference in New Issue
Block a user