diff --git a/apps/gpgui-helper/README.md b/apps/gpgui-helper/README.md index 102e366..c12e8db 100644 --- a/apps/gpgui-helper/README.md +++ b/apps/gpgui-helper/README.md @@ -1,7 +1,36 @@ -# Tauri + React + Typescript +# GP Connect download helper -This template should help get you started developing with Tauri, React and Typescript in Vite. +The desktop supervisor launches this window when the selected GUI is missing or +has an incompatible version. It downloads the selected Tauri or Native Shell +interface and requests installation through the service. Launches require the +existing service credential and lifetime channel on stdin. -## Recommended IDE Setup +## Appearance -- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) +`--theme system|light|dark` controls this window only. The default is `system`, +which follows system appearance and changes while the window is open. Explicit +`light` and `dark` modes override system appearance for that launch. Nothing is +saved by the helper. + +Initial downloads follow the system. During Linux Tauri/Native Shell switches, +Desktop Core supplies the running app's saved theme choice to the supervisor, +which forwards it to the helper. There is no `--helper-theme` option on +`gpclient launch-gui`. + +The native window and web content use the selected appearance before the window +is shown. Browser previews follow the system when no native mode is supplied. + +## Development + +```sh +pnpm build +pnpm test +``` + +The built `dist/` assets are tracked and must be rebuilt after frontend changes. +Run Rust checks and helper tests from the `gp` repository: + +```sh +cargo check -p gpgui-helper +cargo test -p gpgui-helper --lib +``` diff --git a/apps/gpgui-helper/dist/assets/main-DZdDLhQH.js b/apps/gpgui-helper/dist/assets/main-BJvLW_Ih.js similarity index 100% rename from apps/gpgui-helper/dist/assets/main-DZdDLhQH.js rename to apps/gpgui-helper/dist/assets/main-BJvLW_Ih.js diff --git a/apps/gpgui-helper/dist/assets/main-CVTp2z3I.css b/apps/gpgui-helper/dist/assets/main-CVTp2z3I.css new file mode 100644 index 0000000..4fd3aca --- /dev/null +++ b/apps/gpgui-helper/dist/assets/main-CVTp2z3I.css @@ -0,0 +1 @@ +:root{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light;--background:#f6f5f4;--foreground:#2e3436;--muted-foreground:#5e5c64;--progress-label:#3d3846;--progress-track:#d5d3d1;--progress-fill:#3584e4;--error:#9c2f2f;--button:#1c71d8;--button-hover:#1a5fb4;--button-active:#174a8b;--focus-ring:#1a5fb4}:root[data-theme=dark]{--lightningcss-light: ;--lightningcss-dark:initial;color-scheme:dark;--background:#242424;--foreground:#fff;--muted-foreground:#c0bfbc;--progress-label:#deddda;--progress-track:#454545;--progress-fill:#78aeed;--error:#ffb4ab;--button:#1c71d8;--button-hover:#3584e4;--button-active:#1a5fb4;--focus-ring:#78aeed}html,body,#root{box-sizing:border-box;-webkit-user-select:none;user-select:none;cursor:default;height:100%;margin:0;padding:0;overflow:hidden}body{background:var(--background);color:var(--foreground);font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}button{font:inherit}.update-window{box-sizing:border-box;background:var(--background);align-items:center;gap:15px;width:100%;height:100%;padding:16px 18px;display:flex}.update-logo{flex:none;width:48px;height:48px}.update-content,.update-status{width:100%;min-width:0}.update-title{color:var(--foreground);letter-spacing:-.01em;margin:0;font-size:16px;font-weight:600;line-height:1.25}.update-description{color:var(--muted-foreground);margin:3px 0 0;font-size:12px;line-height:1.4}.progress-summary{justify-content:space-between;align-items:baseline;gap:12px;margin-top:3px;display:flex}.progress-summary .update-description{margin:0}.progress-bar{background-color:var(--progress-track);border-radius:3px;width:100%;height:6px;margin-top:9px;position:relative;overflow:hidden}.progress-fill{background:var(--progress-fill);border-radius:3px;height:100%;transition:width .18s ease-out}.progress-bar-indeterminate .progress-fill{width:35%;animation:1.4s ease-in-out infinite progress-indeterminate}@keyframes progress-indeterminate{0%{transform:translate(-110%)}to{transform:translate(300%)}}@media (prefers-reduced-motion:reduce){.progress-fill{transition:none}.progress-bar-indeterminate .progress-fill{animation:none;transform:translate(90%)}}.progress-label{color:var(--progress-label);font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap;flex:none;font-size:12px;font-weight:500}.error-status{justify-content:space-between;align-items:center;gap:16px;display:flex}.error-status .update-title{color:var(--error)}.error-copy{min-width:0}.retry-button{background:var(--button);color:#fff;cursor:default;border:0;border-radius:8px;min-width:68px;padding:4px 14px;font-size:12px;font-weight:600;line-height:1.5}.retry-button:hover{background:var(--button-hover)}.retry-button:active{background:var(--button-active)}.retry-button:focus-visible{outline:2px solid var(--focus-ring);outline-offset:2px} diff --git a/apps/gpgui-helper/dist/assets/main-DiWGniCh.css b/apps/gpgui-helper/dist/assets/main-DiWGniCh.css deleted file mode 100644 index 718afda..0000000 --- a/apps/gpgui-helper/dist/assets/main-DiWGniCh.css +++ /dev/null @@ -1 +0,0 @@ -html,body,#root{box-sizing:border-box;-webkit-user-select:none;user-select:none;cursor:default;height:100%;margin:0;padding:0;overflow:hidden}body{color:#2e3436;background:#f6f5f4;font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}button{font:inherit}.update-window{box-sizing:border-box;background:#f6f5f4;align-items:center;gap:15px;width:100%;height:100%;padding:16px 18px;display:flex}.update-logo{flex:none;width:48px;height:48px}.update-content,.update-status{width:100%;min-width:0}.update-title{color:#2e3436;letter-spacing:-.01em;margin:0;font-size:16px;font-weight:600;line-height:1.25}.update-description{color:#5e5c64;margin:3px 0 0;font-size:12px;line-height:1.4}.progress-summary{justify-content:space-between;align-items:baseline;gap:12px;margin-top:3px;display:flex}.progress-summary .update-description{margin:0}.progress-bar{background-color:#d5d3d1;border-radius:3px;width:100%;height:6px;margin-top:9px;position:relative;overflow:hidden}.progress-fill{background:#3584e4;border-radius:3px;height:100%;transition:width .18s ease-out}.progress-bar-indeterminate .progress-fill{width:35%;animation:1.4s ease-in-out infinite progress-indeterminate}@keyframes progress-indeterminate{0%{transform:translate(-110%)}to{transform:translate(300%)}}@media (prefers-reduced-motion:reduce){.progress-fill{transition:none}.progress-bar-indeterminate .progress-fill{animation:none;transform:translate(90%)}}.progress-label{color:#3d3846;font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap;flex:none;font-size:12px;font-weight:500}.error-status{justify-content:space-between;align-items:center;gap:16px;display:flex}.error-status .update-title{color:#9c2f2f}.error-copy{min-width:0}.retry-button{color:#fff;cursor:pointer;background:#1c71d8;border:0;border-radius:8px;min-width:68px;padding:4px 14px;font-size:12px;font-weight:600;line-height:1.5}.retry-button:hover{background:#1a5fb4}.retry-button:active{background:#174a8b}.retry-button:focus-visible{outline-offset:2px;outline:2px solid #1a5fb4} diff --git a/apps/gpgui-helper/dist/index.html b/apps/gpgui-helper/dist/index.html index f799e86..e8fe51e 100644 --- a/apps/gpgui-helper/dist/index.html +++ b/apps/gpgui-helper/dist/index.html @@ -2,11 +2,21 @@ + GPGUI Downloader - - + + GPGUI Downloader diff --git a/apps/gpgui-helper/package.json b/apps/gpgui-helper/package.json index 3933a29..9da7fc8 100644 --- a/apps/gpgui-helper/package.json +++ b/apps/gpgui-helper/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", + "test": "node --test tests/*.test.mjs", "preview": "vite preview", "tauri": "tauri" }, diff --git a/apps/gpgui-helper/src-tauri/src/app.rs b/apps/gpgui-helper/src-tauri/src/app.rs index 87d8aff..9d5415b 100644 --- a/apps/gpgui-helper/src-tauri/src/app.rs +++ b/apps/gpgui-helper/src-tauri/src/app.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use gpapi::service::transport::SessionCredential; +use gpapi::{gui::GuiTheme, service::transport::SessionCredential}; use log::info; use tauri::{Listener, Manager}; use tokio::sync::watch; @@ -12,6 +12,7 @@ pub struct App { credential_lease: watch::Receiver, gui_version: String, variant: gpapi::gui::GuiVariant, + theme: GuiTheme, } impl App { @@ -20,24 +21,53 @@ impl App { credential_lease: watch::Receiver, gui_version: &str, variant: gpapi::gui::GuiVariant, + theme: GuiTheme, ) -> Self { Self { credential, credential_lease, gui_version: gui_version.to_string(), variant, + theme, } } pub fn run(&self) -> anyhow::Result<()> { let gui_version = self.gui_version.clone(); let variant = self.variant; + let theme = self.theme; let credential = Arc::clone(&self.credential); let credential_lease = self.credential_lease.clone(); tauri::Builder::default() + .on_window_event(move |window, event| { + if theme == GuiTheme::System + && let tauri::WindowEvent::ThemeChanged(theme) = event + && let Some(win) = window.get_webview_window(window.label()) + && let Err(error) = win.set_background_color(Some(background_color(*theme))) + { + log::warn!("Could not update helper window background: {error}"); + } + }) .setup(move |app| { - let win = app.get_webview_window("main").expect("no main window"); + let native_theme = match theme { + GuiTheme::System => None, + GuiTheme::Light => Some(tauri::Theme::Light), + GuiTheme::Dark => Some(tauri::Theme::Dark), + }; + let config = app + .config() + .app + .windows + .iter() + .find(|window| window.label == "main") + .expect("no main window"); + let win = tauri::WebviewWindowBuilder::from_config(app, config)? + .theme(native_theme) + .initialization_script(format!("window.__GP_HELPER_THEME__ = {:?};", theme.as_str())) + .visible(false) + .build()?; + win.set_background_color(Some(background_color(win.theme()?)))?; let _ = win.hide_menu(); let notifier = ProgressNotifier::new(win.clone()); @@ -74,6 +104,8 @@ impl App { tokio::spawn(async move { updater.update().await }); }); + win.show()?; + Ok(()) }) .run(tauri::generate_context!())?; @@ -81,3 +113,10 @@ impl App { Ok(()) } } + +fn background_color(theme: tauri::Theme) -> tauri::window::Color { + match theme { + tauri::Theme::Dark => tauri::window::Color(36, 36, 36, 255), + _ => tauri::window::Color(246, 245, 244, 255), + } +} diff --git a/apps/gpgui-helper/src-tauri/src/cli.rs b/apps/gpgui-helper/src-tauri/src/cli.rs index a8a2174..7ae5e27 100644 --- a/apps/gpgui-helper/src-tauri/src/cli.rs +++ b/apps/gpgui-helper/src-tauri/src/cli.rs @@ -4,6 +4,7 @@ use std::{io::Read, sync::Arc}; use anyhow::{Context, bail}; use gpapi::{ clap::InfoLevelVerbosity, + gui::GuiTheme, service::transport::{MAX_CREDENTIAL_FRAME, SessionCredential}, utils::env_utils, }; @@ -32,6 +33,9 @@ struct Cli { #[arg(long, default_value = "tauri", value_parser = ["tauri", "nsh"])] gui_variant: String, + #[arg(long, value_enum, default_value = "system", help = "Window appearance")] + theme: GuiTheme, + #[command(flatten)] verbose: InfoLevelVerbosity, } @@ -49,7 +53,13 @@ impl Cli { variant != gpapi::gui::GuiVariant::Nsh || cfg!(target_os = "linux"), "Native Shell is available only on Linux" ); - let app = App::new(Arc::new(credential), credential_lease, &self.gui_version, variant); + let app = App::new( + Arc::new(credential), + credential_lease, + &self.gui_version, + variant, + self.theme, + ); env_utils::patch_gui_runtime_env(false); @@ -121,6 +131,22 @@ mod tests { use super::*; + #[test] + fn theme_defaults_to_system_and_accepts_explicit_modes() { + assert_eq!(Cli::try_parse_from(["gpgui-helper"]).unwrap().theme, GuiTheme::System); + for (value, expected) in [ + ("system", GuiTheme::System), + ("light", GuiTheme::Light), + ("dark", GuiTheme::Dark), + ] { + assert_eq!( + Cli::try_parse_from(["gpgui-helper", "--theme", value]).unwrap().theme, + expected + ); + } + assert!(Cli::try_parse_from(["gpgui-helper", "--theme", "invalid"]).is_err()); + } + #[test] fn credential_lease_closes_at_eof() { let (lease_tx, lease_rx) = watch::channel(true); diff --git a/apps/gpgui-helper/src-tauri/tauri.conf.json b/apps/gpgui-helper/src-tauri/tauri.conf.json index 3bb182c..4f44b38 100644 --- a/apps/gpgui-helper/src-tauri/tauri.conf.json +++ b/apps/gpgui-helper/src-tauri/tauri.conf.json @@ -25,6 +25,7 @@ "maxWidth": 460, "maxHeight": 104, "label": "main", + "create": false, "decorations": false } ] diff --git a/apps/gpgui-helper/src/components/App/styles.css b/apps/gpgui-helper/src/components/App/styles.css index 7489b62..2902225 100644 --- a/apps/gpgui-helper/src/components/App/styles.css +++ b/apps/gpgui-helper/src/components/App/styles.css @@ -1,3 +1,33 @@ +:root { + color-scheme: light; + --background: #f6f5f4; + --foreground: #2e3436; + --muted-foreground: #5e5c64; + --progress-label: #3d3846; + --progress-track: #d5d3d1; + --progress-fill: #3584e4; + --error: #9c2f2f; + --button: #1c71d8; + --button-hover: #1a5fb4; + --button-active: #174a8b; + --focus-ring: #1a5fb4; +} + +:root[data-theme="dark"] { + color-scheme: dark; + --background: #242424; + --foreground: #ffffff; + --muted-foreground: #c0bfbc; + --progress-label: #deddda; + --progress-track: #454545; + --progress-fill: #78aeed; + --error: #ffb4ab; + --button: #1c71d8; + --button-hover: #3584e4; + --button-active: #1a5fb4; + --focus-ring: #78aeed; +} + html, body, #root { @@ -12,8 +42,8 @@ body, } body { - background: #f6f5f4; - color: #2e3436; + background: var(--background); + color: var(--foreground); font-family: Inter, ui-sans-serif, @@ -35,7 +65,7 @@ button { height: 100%; padding: 16px 18px; gap: 15px; - background: #f6f5f4; + background: var(--background); } .update-logo { @@ -52,7 +82,7 @@ button { .update-title { margin: 0; - color: #2e3436; + color: var(--foreground); font-size: 16px; font-weight: 600; line-height: 1.25; @@ -61,7 +91,7 @@ button { .update-description { margin: 3px 0 0; - color: #5e5c64; + color: var(--muted-foreground); font-size: 12px; line-height: 1.4; } @@ -85,13 +115,13 @@ button { margin-top: 9px; overflow: hidden; border-radius: 3px; - background-color: #d5d3d1; + background-color: var(--progress-track); } .progress-fill { height: 100%; border-radius: 3px; - background: #3584e4; + background: var(--progress-fill); transition: width 180ms ease-out; } @@ -123,7 +153,7 @@ button { .progress-label { flex: 0 0 auto; - color: #3d3846; + color: var(--progress-label); font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 500; @@ -139,7 +169,7 @@ button { } .error-status .update-title { - color: #9c2f2f; + color: var(--error); } .error-copy { @@ -151,23 +181,23 @@ button { padding: 4px 14px; border: 0; border-radius: 8px; - background: #1c71d8; + background: var(--button); color: #ffffff; - cursor: pointer; + cursor: default; font-size: 12px; font-weight: 600; line-height: 1.5; } .retry-button:hover { - background: #1a5fb4; + background: var(--button-hover); } .retry-button:active { - background: #174a8b; + background: var(--button-active); } .retry-button:focus-visible { - outline: 2px solid #1a5fb4; + outline: 2px solid var(--focus-ring); outline-offset: 2px; } diff --git a/apps/gpgui-helper/tests/theme.test.mjs b/apps/gpgui-helper/tests/theme.test.mjs new file mode 100644 index 0000000..972ffc4 --- /dev/null +++ b/apps/gpgui-helper/tests/theme.test.mjs @@ -0,0 +1,48 @@ +import { readFileSync } from "node:fs"; +import { runInNewContext } from "node:vm"; +import { test } from "node:test"; +import assert from "node:assert/strict"; + +const html = readFileSync(new URL("../index.html", import.meta.url), "utf8"); +const script = html.match(/