feat: add global-shortcut plugin and mini timer window commands
This commit is contained in:
5884
src-tauri/Cargo.lock
generated
Normal file
5884
src-tauri/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@ tauri-plugin-shell = "2"
|
|||||||
tauri-plugin-dialog = "2"
|
tauri-plugin-dialog = "2"
|
||||||
tauri-plugin-fs = "2"
|
tauri-plugin-fs = "2"
|
||||||
tauri-plugin-notification = "2"
|
tauri-plugin-notification = "2"
|
||||||
|
tauri-plugin-global-shortcut = "2"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
rusqlite = { version = "0.32", features = ["bundled"] }
|
rusqlite = { version = "0.32", features = ["bundled"] }
|
||||||
@@ -25,6 +26,20 @@ chrono = { version = "0.4", features = ["serde"] }
|
|||||||
tauri-plugin-window-state = "2"
|
tauri-plugin-window-state = "2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
|
png = "0.17"
|
||||||
|
|
||||||
|
[dependencies.windows]
|
||||||
|
version = "0.58"
|
||||||
|
features = [
|
||||||
|
"Win32_UI_WindowsAndMessaging",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_SystemInformation",
|
||||||
|
"Win32_UI_Input_KeyboardAndMouse",
|
||||||
|
"Win32_UI_Shell",
|
||||||
|
"Win32_Graphics_Gdi",
|
||||||
|
"Win32_Storage_FileSystem",
|
||||||
|
"Win32_Foundation",
|
||||||
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"identifier": "default",
|
"identifier": "default",
|
||||||
"description": "Default capabilities for the app",
|
"description": "Default capabilities for the app",
|
||||||
"windows": ["main"],
|
"windows": ["main", "mini-timer"],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"core:default",
|
"core:default",
|
||||||
"core:window:allow-close",
|
"core:window:allow-close",
|
||||||
@@ -25,6 +25,10 @@
|
|||||||
"fs:allow-write-text-file",
|
"fs:allow-write-text-file",
|
||||||
"notification:allow-is-permission-granted",
|
"notification:allow-is-permission-granted",
|
||||||
"notification:allow-request-permission",
|
"notification:allow-request-permission",
|
||||||
"notification:allow-notify"
|
"notification:allow-notify",
|
||||||
|
"global-shortcut:allow-register",
|
||||||
|
"global-shortcut:allow-unregister",
|
||||||
|
"global-shortcut:allow-unregister-all",
|
||||||
|
"global-shortcut:allow-is-registered"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::AppState;
|
|||||||
use crate::os_detection;
|
use crate::os_detection;
|
||||||
use rusqlite::params;
|
use rusqlite::params;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tauri::State;
|
use tauri::{Manager, State};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
@@ -885,7 +885,7 @@ pub fn get_timesheet_data(state: State<AppState>, week_start: String) -> Result<
|
|||||||
"color": color,
|
"color": color,
|
||||||
"task_id": task_id,
|
"task_id": task_id,
|
||||||
"task_name": task_name,
|
"task_name": task_name,
|
||||||
"days": [0i64; 7]
|
"days": vec![0i64; 7]
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
// Find which day index this entry_date corresponds to
|
// 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)
|
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_dialog::init())
|
||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
.plugin(tauri_plugin_notification::init())
|
.plugin(tauri_plugin_notification::init())
|
||||||
|
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||||
.manage(AppState { db: Mutex::new(conn) })
|
.manage(AppState { db: Mutex::new(conn) })
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
commands::get_clients,
|
commands::get_clients,
|
||||||
@@ -82,6 +83,8 @@ pub fn run() {
|
|||||||
commands::get_timesheet_data,
|
commands::get_timesheet_data,
|
||||||
commands::import_entries,
|
commands::import_entries,
|
||||||
commands::import_json_data,
|
commands::import_json_data,
|
||||||
|
commands::open_mini_timer,
|
||||||
|
commands::close_mini_timer,
|
||||||
])
|
])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
#[cfg(desktop)]
|
#[cfg(desktop)]
|
||||||
|
|||||||
Reference in New Issue
Block a user