From 222e67d833e3ae4df24f3b6a6eb885b8d982bf97 Mon Sep 17 00:00:00 2001 From: Mikael Kristiansson Date: Fri, 6 Sep 2024 11:52:10 +0200 Subject: [PATCH] feat: update the ui and add compact mode (#24) --- index.html | 6 +- package.json | 2 +- src-tauri/Cargo.lock | 17 ++- src-tauri/Cargo.toml | 19 ++- src-tauri/src/main.rs | 202 ++++++++++++++-------------- src-tauri/tauri.conf.json | 6 +- src/components/Footer.svelte | 21 +-- src/components/Login.svelte | 54 +++----- src/components/Reviews.svelte | 236 +++++++++++++++++++-------------- src/components/Settings.svelte | 42 +++--- src/lib/api.ts | 31 +++-- src/lib/auth.ts | 7 +- src/lib/window-size.ts | 11 ++ src/types.ts | 7 +- 14 files changed, 361 insertions(+), 300 deletions(-) create mode 100644 src/lib/window-size.ts diff --git a/index.html b/index.html index 2f55359..511973d 100644 --- a/index.html +++ b/index.html @@ -1,12 +1,12 @@ - + Gitbar - -
+ +
diff --git a/package.json b/package.json index 553f318..30597df 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gitbar", "private": true, - "version": "0.4.4", + "version": "0.5.0", "type": "module", "scripts": { "dev": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a1613c0..d5d924e 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -905,7 +905,7 @@ dependencies = [ [[package]] name = "gitbar" -version = "0.4.4" +version = "0.5.0" dependencies = [ "auto-launch", "cocoa", @@ -914,6 +914,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-positioner", "thiserror", ] @@ -2777,6 +2778,20 @@ dependencies = [ "tauri-utils", ] +[[package]] +name = "tauri-plugin-positioner" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1c491af3aaa053d6e85d95b516bdaa20ae7c6ebb36cbdae2988dea68f57f27e" +dependencies = [ + "log", + "serde", + "serde_json", + "serde_repr", + "tauri", + "thiserror", +] + [[package]] name = "tauri-runtime" version = "0.12.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 91b85fb..5e7194b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "gitbar" -version = "0.4.4" +version = "0.5.0" description = "Github review counter" authors = ["mikael.kristiansson"] license = "MIT" repository = "https://github.com/mikaelkristiansson/gitbar" default-run = "gitbar" edition = "2021" -rust-version = "1.57" +rust-version = "1.67" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -18,8 +18,17 @@ tauri-build = { version = "1.2.1", features = [] } serde_json = "1.0" auto-launch = "0.3" thiserror = "1.0" +tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] } serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2.3", features = [ "updater", "http-request", "icon-png", "notification-all", "shell-open", "system-tray"] } +tauri = { version = "1.2.3", features = [ + "window-set-size", + "updater", + "http-request", + "icon-png", + "notification-all", + "shell-open", + "system-tray", +] } [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.24" @@ -28,7 +37,7 @@ objc = "0.2.7" [features] # by default Tauri runs in production mode # when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL -default = [ "custom-protocol" ] +default = ["custom-protocol"] # this feature is used used for production builds where `devPath` points to the filesystem # DO NOT remove this -custom-protocol = [ "tauri/custom-protocol" ] +custom-protocol = ["tauri/custom-protocol"] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8761360..1bef440 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,10 +1,11 @@ #![cfg_attr( - all(not(debug_assertions), target_os = "windows"), - windows_subsystem = "windows" + all(not(debug_assertions), target_os = "windows"), + windows_subsystem = "windows" )] -use tauri::Manager; -use tauri::{CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu, PhysicalPosition}; +use tauri::{CustomMenuItem, Menu, MenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu}; +use tauri::{Manager, Submenu}; +use tauri_plugin_positioner::{Position, WindowExt as WindowExtTrait}; mod auto_start; @@ -42,7 +43,8 @@ impl WindowExt for Window { if remove_tool_bar { let close_button = id.standardWindowButton_(NSWindowButton::NSWindowCloseButton); let _: () = msg_send![close_button, setHidden: YES]; - let min_button = id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton); + let min_button = + id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton); let _: () = msg_send![min_button, setHidden: YES]; let zoom_button = id.standardWindowButton_(NSWindowButton::NSWindowZoomButton); let _: () = msg_send![zoom_button, setHidden: YES]; @@ -65,100 +67,104 @@ impl WindowExt for Window { #[tauri::command] fn set_review_count(app_handle: tauri::AppHandle, count: &str) { - let mut rev_count = count.to_string(); - rev_count.insert_str(0, " "); - #[cfg(target_os = "macos")] - app_handle - .tray_handle() - .set_title(&rev_count) - .unwrap(); + let mut rev_count = count.to_string(); + let count_number = count.parse::().unwrap_or_default(); + if count_number > 0 { + rev_count.insert_str(0, " "); + } + #[cfg(target_os = "macos")] + app_handle.tray_handle().set_title(&rev_count).unwrap(); } fn main() { - let quit = CustomMenuItem::new("quit".to_string(), "Quit"); - let tray_menu = SystemTrayMenu::new() - .add_item(quit); - let system_tray = SystemTray::new() - .with_menu(tray_menu); - - tauri::Builder::default() - .system_tray(system_tray) - .on_system_tray_event(move |app, event| match event { - SystemTrayEvent::LeftClick { - position, - size, - .. - } => { - let w = app.get_window("main").unwrap(); - let visible = w.is_visible().unwrap(); - if visible { - w.hide().unwrap(); - } else { - let window_size = w.outer_size().unwrap(); - let physical_pos = PhysicalPosition { - x: position.x as i32 + (size.width as i32 / 2) - (window_size.width as i32 / 2), - y: position.y as i32 - window_size.height as i32 - }; - - let _ = w.set_position(tauri::Position::Physical(physical_pos)); - w.show().unwrap(); - w.set_focus().unwrap(); - } - } - SystemTrayEvent::RightClick { - position: _, - size: _, - .. - } => { - println!("system tray received a right click"); - } - SystemTrayEvent::DoubleClick { - position: _, - size: _, - .. - } => { - println!("system tray received a double click"); - } - SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { - "quit" => { - std::process::exit(0); - } - _ => {} - }, - _ => {} - }) - .on_window_event(|event| match event.event() { - tauri::WindowEvent::CloseRequested { api, .. } => { - // don't kill the app when the user clicks close. this is important - event.window().hide().unwrap(); - api.prevent_close(); - } - tauri::WindowEvent::Focused(false) => { - // hide the window automatically when the user - // clicks out. this is for a matter of taste. - event.window().hide().unwrap(); - } - _ => {} - }) - .invoke_handler(tauri::generate_handler![set_review_count]) - .plugin(auto_start::init( - None, - )) - .setup(|app| { - #[cfg(target_os = "macos")] - // don't show on the taskbar/springboard - app.set_activation_policy(tauri::ActivationPolicy::Accessory); - - let window = app.get_window("main").unwrap(); - #[cfg(target_os = "macos")] - window.set_transparent_titlebar(true, true); - - // this is a workaround for the window to always show in current workspace. - // see https://github.com/tauri-apps/tauri/issues/2801 - window.set_always_on_top(true).unwrap(); - - Ok(()) - }) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + let quit = CustomMenuItem::new("quit".to_string(), "Quit"); + let tray_menu = SystemTrayMenu::new().add_item(quit); + let system_tray = SystemTray::new().with_menu(tray_menu); + let edit_menu = Submenu::new( + "Edit", + Menu::new() + .add_native_item(MenuItem::Undo) + .add_native_item(MenuItem::Redo) + .add_native_item(MenuItem::Separator) + .add_native_item(MenuItem::Cut) + .add_native_item(MenuItem::Copy) + .add_native_item(MenuItem::Paste) + .add_native_item(MenuItem::SelectAll), + ); + + let menu = Menu::new().add_submenu(edit_menu); + + tauri::Builder::default() + .plugin(tauri_plugin_positioner::init()) + .on_system_tray_event(|app, event| { + tauri_plugin_positioner::on_tray_event(app, &event); + }) + .menu(menu) + .system_tray(system_tray) + .on_system_tray_event(move |app, event| match event { + SystemTrayEvent::LeftClick { .. } => { + let w = app.get_window("main").unwrap(); + let visible = w.is_visible().unwrap(); + if visible { + w.hide().unwrap(); + } else { + let _ = w.move_window(Position::TrayCenter); + w.show().unwrap(); + w.set_focus().unwrap(); + } + } + SystemTrayEvent::RightClick { + position: _, + size: _, + .. + } => { + println!("system tray received a right click"); + } + SystemTrayEvent::DoubleClick { + position: _, + size: _, + .. + } => { + println!("system tray received a double click"); + } + SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { + "quit" => { + std::process::exit(0); + } + _ => {} + }, + _ => {} + }) + .on_window_event(|event| match event.event() { + tauri::WindowEvent::CloseRequested { api, .. } => { + // don't kill the app when the user clicks close. this is important + event.window().hide().unwrap(); + api.prevent_close(); + } + tauri::WindowEvent::Focused(false) => { + // hide the window automatically when the user + // clicks out. this is for a matter of taste. + event.window().hide().unwrap(); + } + _ => {} + }) + .invoke_handler(tauri::generate_handler![set_review_count]) + .plugin(auto_start::init(None)) + .setup(|app| { + #[cfg(target_os = "macos")] + // don't show on the taskbar/springboard + app.set_activation_policy(tauri::ActivationPolicy::Accessory); + + let window = app.get_window("main").unwrap(); + #[cfg(target_os = "macos")] + window.set_transparent_titlebar(true, true); + + // this is a workaround for the window to always show in current workspace. + // see https://github.com/tauri-apps/tauri/issues/2801 + window.set_always_on_top(true).unwrap(); + + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ea9906d..0967821 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -7,8 +7,7 @@ "distDir": "../dist" }, "package": { - "productName": "GitBar", - "version": "0.4.4" + "productName": "GitBar" }, "tauri": { "allowlist": { @@ -21,6 +20,9 @@ }, "shell": { "open": true + }, + "window": { + "setSize": true } }, "bundle": { diff --git a/src/components/Footer.svelte b/src/components/Footer.svelte index 8b79707..e62ab65 100644 --- a/src/components/Footer.svelte +++ b/src/components/Footer.svelte @@ -24,15 +24,10 @@ } -