From 9e0a708011a4e1cdc44bbc288691e07594620a78 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 12 Mar 2026 15:35:55 -0700 Subject: [PATCH] Font size and other fixes --- apps/yaak-proxy/components/ExchangesTable.tsx | 50 ++++--- apps/yaak-proxy/components/ProxyLayout.tsx | 27 ++-- apps/yaak-proxy/font-size.ts | 2 + apps/yaak-proxy/index.html | 1 + crates-tauri/yaak-app-proxy/src/lib.rs | 53 ++++++- .../yaak-app-proxy/src/window_menu.rs | 138 ++++++++++++++++++ 6 files changed, 231 insertions(+), 40 deletions(-) create mode 100644 apps/yaak-proxy/font-size.ts create mode 100644 crates-tauri/yaak-app-proxy/src/window_menu.rs diff --git a/apps/yaak-proxy/components/ExchangesTable.tsx b/apps/yaak-proxy/components/ExchangesTable.tsx index d24b3a83..2124f8d8 100644 --- a/apps/yaak-proxy/components/ExchangesTable.tsx +++ b/apps/yaak-proxy/components/ExchangesTable.tsx @@ -22,30 +22,34 @@ export function ExchangesTable({ exchanges, style, className }: Props) { } return ( - - - - Method - URL - Status - Type - - - - {exchanges.map((ex) => ( - - {ex.method} - {ex.url} - - - - - {getContentType(ex.resHeaders)} - +
+
+ + + Method + URL + Status + Type - ))} - -
+ + + {exchanges.map((ex) => ( + + {ex.method} + + {ex.url} + + + + + + {getContentType(ex.resHeaders)} + + + ))} + + + ); } diff --git a/apps/yaak-proxy/components/ProxyLayout.tsx b/apps/yaak-proxy/components/ProxyLayout.tsx index 642543ce..9c60e466 100644 --- a/apps/yaak-proxy/components/ProxyLayout.tsx +++ b/apps/yaak-proxy/components/ProxyLayout.tsx @@ -55,28 +55,29 @@ export function ProxyLayout() { }} /> -
+
Yaak Proxy
- - {isRunning ? 'Running on :9090' : 'Stopped'} - {isRunning ? ( - + <> + Running :9090 + + ) : ( )}
diff --git a/apps/yaak-proxy/font-size.ts b/apps/yaak-proxy/font-size.ts new file mode 100644 index 00000000..5272e52a --- /dev/null +++ b/apps/yaak-proxy/font-size.ts @@ -0,0 +1,2 @@ +// Hardcode font size for now. In the future, this could be configurable. +document.documentElement.style.fontSize = '15px'; diff --git a/apps/yaak-proxy/index.html b/apps/yaak-proxy/index.html index c94dd2ab..60d85901 100644 --- a/apps/yaak-proxy/index.html +++ b/apps/yaak-proxy/index.html @@ -21,6 +21,7 @@
+ diff --git a/crates-tauri/yaak-app-proxy/src/lib.rs b/crates-tauri/yaak-app-proxy/src/lib.rs index 0055681e..6cd23350 100644 --- a/crates-tauri/yaak-app-proxy/src/lib.rs +++ b/crates-tauri/yaak-app-proxy/src/lib.rs @@ -1,9 +1,53 @@ -use log::error; -use tauri::{Emitter, Manager, RunEvent, State}; +use log::{error, info, warn}; +use tauri::{Emitter, Manager, RunEvent, State, WebviewWindow}; +use tauri::Runtime; use yaak_proxy_lib::ProxyCtx; use yaak_rpc::{RpcEventEmitter, RpcRouter}; use yaak_window::window::CreateWindowConfig; +mod window_menu; + +fn setup_window_menu(win: &WebviewWindow) { + #[allow(unused_variables)] + let menu = match window_menu::app_menu(win.app_handle()) { + Ok(m) => m, + Err(e) => { + warn!("Failed to create menu: {e:?}"); + return; + } + }; + + // This causes the window to not be clickable (in AppImage), so disable on Linux + #[cfg(not(target_os = "linux"))] + win.app_handle().set_menu(menu).expect("Failed to set app menu"); + + let webview_window = win.clone(); + win.on_menu_event(move |w, event| { + if !w.is_focused().unwrap() { + return; + } + + let event_id = event.id().0.as_str(); + match event_id { + "hacked_quit" => { + w.webview_windows().iter().for_each(|(_, w)| { + info!("Closing window {}", w.label()); + let _ = w.close(); + }); + } + "dev.refresh" => webview_window.eval("location.reload()").unwrap(), + "dev.toggle_devtools" => { + if webview_window.is_devtools_open() { + webview_window.close_devtools(); + } else { + webview_window.open_devtools(); + } + } + _ => {} + } + }); +} + #[tauri::command] fn rpc( router: State<'_, RpcRouter>, @@ -52,8 +96,9 @@ pub fn run() { hide_titlebar: true, ..Default::default() }; - if let Err(e) = yaak_window::window::create_window(app_handle, config) { - error!("Failed to create proxy window: {e:?}"); + match yaak_window::window::create_window(app_handle, config) { + Ok(win) => setup_window_menu(&win), + Err(e) => error!("Failed to create proxy window: {e:?}"), } } }); diff --git a/crates-tauri/yaak-app-proxy/src/window_menu.rs b/crates-tauri/yaak-app-proxy/src/window_menu.rs new file mode 100644 index 00000000..b71433af --- /dev/null +++ b/crates-tauri/yaak-app-proxy/src/window_menu.rs @@ -0,0 +1,138 @@ +pub use tauri::AppHandle; +use tauri::Runtime; +use tauri::menu::{ + AboutMetadata, HELP_SUBMENU_ID, Menu, MenuItemBuilder, PredefinedMenuItem, Submenu, + WINDOW_SUBMENU_ID, +}; + +pub fn app_menu(app_handle: &AppHandle) -> tauri::Result> { + let pkg_info = app_handle.package_info(); + let config = app_handle.config(); + let about_metadata = AboutMetadata { + name: Some(pkg_info.name.clone()), + version: Some(pkg_info.version.to_string()), + copyright: config.bundle.copyright.clone(), + authors: config.bundle.publisher.clone().map(|p| vec![p]), + ..Default::default() + }; + + let window_menu = Submenu::with_id_and_items( + app_handle, + WINDOW_SUBMENU_ID, + "Window", + true, + &[ + &PredefinedMenuItem::minimize(app_handle, None)?, + &PredefinedMenuItem::maximize(app_handle, None)?, + #[cfg(target_os = "macos")] + &PredefinedMenuItem::separator(app_handle)?, + &PredefinedMenuItem::close_window(app_handle, None)?, + ], + )?; + + #[cfg(target_os = "macos")] + { + window_menu.set_as_windows_menu_for_nsapp()?; + } + + let help_menu = Submenu::with_id_and_items( + app_handle, + HELP_SUBMENU_ID, + "Help", + true, + &[ + #[cfg(not(target_os = "macos"))] + &PredefinedMenuItem::about(app_handle, None, Some(about_metadata.clone()))?, + ], + )?; + + #[cfg(target_os = "macos")] + { + help_menu.set_as_windows_menu_for_nsapp()?; + } + + let menu = Menu::with_items( + app_handle, + &[ + #[cfg(target_os = "macos")] + &Submenu::with_items( + app_handle, + pkg_info.name.clone(), + true, + &[ + &PredefinedMenuItem::about(app_handle, None, Some(about_metadata))?, + &PredefinedMenuItem::separator(app_handle)?, + &PredefinedMenuItem::services(app_handle, None)?, + &PredefinedMenuItem::separator(app_handle)?, + &PredefinedMenuItem::hide(app_handle, None)?, + &PredefinedMenuItem::hide_others(app_handle, None)?, + &PredefinedMenuItem::separator(app_handle)?, + &MenuItemBuilder::with_id( + "hacked_quit".to_string(), + format!("Quit {}", app_handle.package_info().name), + ) + .accelerator("CmdOrCtrl+q") + .build(app_handle)?, + ], + )?, + #[cfg(not(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + )))] + &Submenu::with_items( + app_handle, + "File", + true, + &[ + &PredefinedMenuItem::close_window(app_handle, None)?, + #[cfg(not(target_os = "macos"))] + &PredefinedMenuItem::quit(app_handle, None)?, + ], + )?, + &Submenu::with_items( + app_handle, + "Edit", + true, + &[ + &PredefinedMenuItem::undo(app_handle, None)?, + &PredefinedMenuItem::redo(app_handle, None)?, + &PredefinedMenuItem::separator(app_handle)?, + &PredefinedMenuItem::cut(app_handle, None)?, + &PredefinedMenuItem::copy(app_handle, None)?, + &PredefinedMenuItem::paste(app_handle, None)?, + &PredefinedMenuItem::select_all(app_handle, None)?, + ], + )?, + &Submenu::with_items( + app_handle, + "View", + true, + &[ + #[cfg(target_os = "macos")] + &PredefinedMenuItem::fullscreen(app_handle, None)?, + ], + )?, + &window_menu, + &help_menu, + #[cfg(dev)] + &Submenu::with_items( + app_handle, + "Develop", + true, + &[ + &MenuItemBuilder::with_id("dev.refresh".to_string(), "Refresh") + .accelerator("CmdOrCtrl+Shift+r") + .build(app_handle)?, + &MenuItemBuilder::with_id("dev.toggle_devtools".to_string(), "Open Devtools") + .accelerator("CmdOrCtrl+Option+i") + .build(app_handle)?, + ], + )?, + ], + )?; + + Ok(menu) +}