From 2ba48fbc14fa5f276ec7e012b8e7d1ce768a22be Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Wed, 25 Sep 2024 20:33:37 +0100 Subject: [PATCH 01/10] Initial commit --- psst-gui/src/data/config.rs | 2 ++ psst-gui/src/delegate.rs | 6 ++-- psst-gui/src/main.rs | 17 ++++++++++-- psst-gui/src/ui/menu.rs | 4 +-- psst-gui/src/ui/mod.rs | 51 ++++++++++++++++++++++++++++++---- psst-gui/src/ui/preferences.rs | 49 +++++++++++++++++++++++++++++++- psst-gui/src/ui/user.rs | 10 +++++-- 7 files changed, 123 insertions(+), 16 deletions(-) diff --git a/psst-gui/src/data/config.rs b/psst-gui/src/data/config.rs index cbb897f4..5852fdc2 100644 --- a/psst-gui/src/data/config.rs +++ b/psst-gui/src/data/config.rs @@ -100,6 +100,7 @@ pub struct Config { pub sort_criteria: SortCriteria, pub paginated_limit: usize, pub seek_duration: usize, + pub kiosk_mode: bool, } impl Default for Config { @@ -118,6 +119,7 @@ impl Default for Config { sort_criteria: Default::default(), paginated_limit: 500, seek_duration: 10, + kiosk_mode: false, } } } diff --git a/psst-gui/src/delegate.rs b/psst-gui/src/delegate.rs index 96fe24ed..40359183 100644 --- a/psst-gui/src/delegate.rs +++ b/psst-gui/src/delegate.rs @@ -71,13 +71,13 @@ impl Delegate { } } - fn show_preferences(&mut self, ctx: &mut DelegateCtx) { + fn show_preferences(&mut self, config: &Config, ctx: &mut DelegateCtx) { match self.preferences_window { Some(id) => { ctx.submit_command(commands::SHOW_WINDOW.to(id)); } None => { - let window = ui::preferences_window(); + let window = ui::preferences_window(config); self.preferences_window.replace(window.id); ctx.new_window(window); } @@ -113,7 +113,7 @@ impl AppDelegate for Delegate { self.show_account_setup(ctx); Handled::Yes } else if cmd.is(commands::SHOW_PREFERENCES) { - self.show_preferences(ctx); + self.show_preferences(&data.config, ctx); Handled::Yes } else if cmd.is(cmd::CLOSE_ALL_WINDOWS) { self.close_all_windows(ctx); diff --git a/psst-gui/src/main.rs b/psst-gui/src/main.rs index 8832a3ac..453d26b9 100644 --- a/psst-gui/src/main.rs +++ b/psst-gui/src/main.rs @@ -13,6 +13,7 @@ mod widget; use druid::AppLauncher; use env_logger::{Builder, Env}; use webapi::WebApi; +use std::env; use crate::{ data::{AppState, Config}, @@ -33,7 +34,14 @@ fn main() { let config = Config::load().unwrap_or_default(); let paginated_limit = config.paginated_limit; - let state = AppState::default_with_config(config); + let mut state = AppState::default_with_config(config); + + let args: Vec = env::args().collect(); + state.config.kiosk_mode = false; + if !args.is_empty() && (args.contains(&"-k".to_string()) || args.contains(&"-kiosk".to_string())) { + state.config.kiosk_mode = true; + } + WebApi::new( state.session.clone(), Config::proxy().as_deref(), @@ -54,7 +62,12 @@ fn main() { WebApi::global().load_local_tracks(state.config.username().unwrap()); } else { // No configured credentials, open the account setup. - let window = ui::account_setup_window(); + let mut window = ui::account_setup_window(); + + if state.config.kiosk_mode { + window = ui::kiosk_setup_window(); + } + delegate = Delegate::with_preferences(window.id); launcher = AppLauncher::with_window(window).configure_env(ui::theme::setup); }; diff --git a/psst-gui/src/ui/menu.rs b/psst-gui/src/ui/menu.rs index 76bd16fe..ecaa4a13 100644 --- a/psst-gui/src/ui/menu.rs +++ b/psst-gui/src/ui/menu.rs @@ -5,8 +5,8 @@ use crate::{ data::{AppState, Nav}, }; -pub fn main_menu(_window: Option, _data: &AppState, _env: &Env) -> Menu { - if cfg!(target_os = "macos") { +pub fn main_menu(_window: Option, data: &AppState, _env: &Env) -> Menu { + if cfg!(target_os = "macos") && !data.config.kiosk_mode { Menu::empty().entry(mac_app_menu()) } else { Menu::empty() diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index fcf9612d..6cb2f063 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -3,7 +3,7 @@ use std::time::Duration; use druid::{ im::Vector, widget::{CrossAxisAlignment, Either, Flex, Label, List, Scroll, Slider, Split, ViewSwitcher}, - Color, Env, Insets, Key, LensExt, Menu, MenuItem, Selector, Widget, WidgetExt, WindowDesc, + Color, Env, Insets, Key, LensExt, Menu, MenuItem, Selector, Widget, WidgetExt, WindowDesc, WindowState, }; use druid_shell::Cursor; @@ -43,12 +43,19 @@ pub mod user; pub mod utils; pub fn main_window(config: &Config) -> WindowDesc { - let win = WindowDesc::new(root_widget()) + let mut win = WindowDesc::new(root_widget()) .title(compute_main_window_title) - .with_min_size((theme::grid(65.0), theme::grid(50.0))) .window_size(config.window_size) .show_title(false) .transparent_titlebar(true); + if config.kiosk_mode { + win = win.set_window_state(WindowState::Maximized) + .resizable(false) + .show_titlebar(false); + } else { + win = win.with_min_size((theme::grid(65.0), theme::grid(50.0))) + + } if cfg!(target_os = "macos") { win.menu(menu::main_menu) } else { @@ -56,7 +63,8 @@ pub fn main_window(config: &Config) -> WindowDesc { } } -pub fn preferences_window() -> WindowDesc { +pub fn preferences_window(config: &Config) -> WindowDesc { + // Change this let win_size = (theme::grid(50.0), theme::grid(55.0)); // On Windows, the window size includes the titlebar. @@ -67,12 +75,20 @@ pub fn preferences_window() -> WindowDesc { win_size }; - let win = WindowDesc::new(preferences_widget()) + let mut win = WindowDesc::new(preferences_widget()) .title("Preferences") - .window_size(win_size) .resizable(false) .show_title(false) .transparent_titlebar(true); + + if config.kiosk_mode { + win = win.set_window_state(WindowState::Maximized) + .resizable(false) + .set_always_on_top(true) + .show_titlebar(false); + } else { + win = win.window_size(win_size) + } if cfg!(target_os = "macos") { win.menu(menu::main_menu) } else { @@ -83,9 +99,24 @@ pub fn preferences_window() -> WindowDesc { pub fn account_setup_window() -> WindowDesc { let win = WindowDesc::new(account_setup_widget()) .title("Login") + .resizable(false) + .show_title(false) .window_size((theme::grid(50.0), theme::grid(45.0))) + .transparent_titlebar(true); + if cfg!(target_os = "macos") { + win.menu(menu::main_menu) + } else { + win + } +} + +pub fn kiosk_setup_window() -> WindowDesc { + let win = WindowDesc::new(kiosk_setup_widget()) + .title("Setup") .resizable(false) .show_title(false) + .set_window_state(WindowState::Maximized) + .show_titlebar(false) .transparent_titlebar(true); if cfg!(target_os = "macos") { win.menu(menu::main_menu) @@ -110,6 +141,14 @@ fn account_setup_widget() -> impl Widget { ) } +fn kiosk_setup_widget() -> impl Widget { + ThemeScope::new( + preferences::kiosk_setup_widget() + .background(theme::BACKGROUND_DARK) + .expand(), + ) +} + fn root_widget() -> impl Widget { let playlists = Scroll::new(playlist::list_widget()) .vertical() diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index d9c5d403..c6f4436d 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -47,6 +47,29 @@ pub fn account_setup_widget() -> impl Widget { .padding(theme::grid(4.0)) } +pub fn kiosk_setup_widget() -> impl Widget { + Flex::column() + .must_fill_main_axis(true) + .cross_axis_alignment(CrossAxisAlignment::Start) + .with_spacer(theme::grid(2.0)) + .with_child( + Label::new("Please insert your Spotify Premium credentials.") + .with_font(theme::UI_FONT_MEDIUM) + .with_line_break_mode(LineBreaking::WordWrap), + ) + .with_spacer(theme::grid(2.0)) + .with_child( + Label::new( + "Psst connects only to the official servers, and does not store your password.", + ) + .with_text_color(theme::PLACEHOLDER_COLOR) + .with_line_break_mode(LineBreaking::WordWrap), + ) + .with_spacer(theme::grid(6.0)) + .with_child(account_tab_widget(AccountTab::KioskSetup).expand_width()) + .padding(theme::grid(4.0)) +} + pub fn preferences_widget() -> impl Widget { const PROPAGATE_FLAGS: Selector = Selector::new("app.preferences.propagate-flags"); @@ -247,6 +270,11 @@ fn general_tab_widget() -> impl Widget { .lens(AppState::config.then(Config::paginated_limit)), ); + col = col.with_default_spacer() + .with_child(Button::new("Done") + .align_right() + .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})); + col } @@ -254,12 +282,14 @@ fn general_tab_widget() -> impl Widget { enum AccountTab { FirstSetup, InPreferences, + KioskSetup, } fn account_tab_widget(tab: AccountTab) -> impl Widget { let mut col = Flex::column().cross_axis_alignment(match tab { AccountTab::FirstSetup => CrossAxisAlignment::Center, AccountTab::InPreferences => CrossAxisAlignment::Start, + AccountTab::KioskSetup => CrossAxisAlignment::Start, }); if matches!(tab, AccountTab::InPreferences) { @@ -295,7 +325,11 @@ fn account_tab_widget(tab: AccountTab) -> impl Widget { if matches!(tab, AccountTab::InPreferences) { col = col.with_child(Button::new("Log Out").on_left_click(|ctx, _, _, _| { ctx.submit_command(cmd::LOG_OUT); - })) + })) + .with_default_spacer() + .with_child(Button::new("Done") + .align_right() + .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})) } col.controller(Authenticate::new(tab)) @@ -391,6 +425,11 @@ impl> Controller for Authenticate { AccountTab::InPreferences => { ctx.submit_command(cmd::SESSION_CONNECT); } + AccountTab::KioskSetup => { + ctx.submit_command(cmd::SHOW_MAIN); + ctx.submit_command(commands::CLOSE_WINDOW); + ctx.submit_command(commands::SHOW_PREFERENCES); + } } } data.preferences.auth.access_token.clear(); @@ -442,6 +481,10 @@ fn cache_tab_widget() -> impl Widget { } }, )); + col = col.with_default_spacer() + .with_child(Button::new("Done") + .align_right() + .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})); col.controller(MeasureCacheSize::new()) .lens(AppState::preferences) @@ -534,4 +577,8 @@ fn about_tab_widget() -> impl Widget { .with_child(commit_hash) .with_child(build_time) .with_child(remote_url) + .with_default_spacer() + .with_child(Button::new("Done") + .align_right() + .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})) } diff --git a/psst-gui/src/ui/user.rs b/psst-gui/src/ui/user.rs index 5ba2c88f..68fe6350 100644 --- a/psst-gui/src/ui/user.rs +++ b/psst-gui/src/ui/user.rs @@ -7,7 +7,7 @@ use druid::{ use crate::{ data::{AppState, Library, UserProfile}, webapi::WebApi, - widget::{icons, icons::SvgIcon, Async, Empty, MyWidgetExt}, + widget::{icons::{self, SvgIcon}, Async, Empty, MyWidgetExt}, }; use super::theme; @@ -51,7 +51,13 @@ pub fn user_widget() -> impl Widget { .with_child(user_profile) .padding(theme::grid(1.0)), ) - .with_child(preferences_widget(&icons::PREFERENCES)) + .with_child( + Either::new( + |data: &AppState, _| !data.config.kiosk_mode, + preferences_widget(&icons::PREFERENCES), + Empty, + ) + ) } fn preferences_widget(svg: &SvgIcon) -> impl Widget { From f40c12cd8abf823516c940138a676ca279875c5e Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Wed, 25 Sep 2024 20:36:27 +0100 Subject: [PATCH 02/10] add extra - --- psst-gui/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psst-gui/src/main.rs b/psst-gui/src/main.rs index 453d26b9..31ba05a3 100644 --- a/psst-gui/src/main.rs +++ b/psst-gui/src/main.rs @@ -38,7 +38,7 @@ fn main() { let args: Vec = env::args().collect(); state.config.kiosk_mode = false; - if !args.is_empty() && (args.contains(&"-k".to_string()) || args.contains(&"-kiosk".to_string())) { + if !args.is_empty() && (args.contains(&"-k".to_string()) || args.contains(&"--kiosk".to_string())) { state.config.kiosk_mode = true; } From 1084426b17a86b19afec89e4dceeb414b07d815a Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Thu, 26 Sep 2024 13:26:06 -0700 Subject: [PATCH 03/10] Fix so macOS can run kiosk --- psst-gui/src/main.rs | 11 +++----- psst-gui/src/ui/mod.rs | 46 ++++++++++++++++++++++------------ psst-gui/src/ui/preferences.rs | 43 ++++++++++++++++++------------- psst-gui/src/ui/user.rs | 17 +++++++------ 4 files changed, 68 insertions(+), 49 deletions(-) diff --git a/psst-gui/src/main.rs b/psst-gui/src/main.rs index 31ba05a3..009d3f9d 100644 --- a/psst-gui/src/main.rs +++ b/psst-gui/src/main.rs @@ -12,8 +12,8 @@ mod widget; use druid::AppLauncher; use env_logger::{Builder, Env}; -use webapi::WebApi; use std::env; +use webapi::WebApi; use crate::{ data::{AppState, Config}, @@ -37,10 +37,7 @@ fn main() { let mut state = AppState::default_with_config(config); let args: Vec = env::args().collect(); - state.config.kiosk_mode = false; - if !args.is_empty() && (args.contains(&"-k".to_string()) || args.contains(&"--kiosk".to_string())) { - state.config.kiosk_mode = true; - } + state.config.kiosk_mode = args.iter().any(|arg| arg == "-k" || arg == "--kiosk"); WebApi::new( state.session.clone(), @@ -63,10 +60,10 @@ fn main() { } else { // No configured credentials, open the account setup. let mut window = ui::account_setup_window(); - + if state.config.kiosk_mode { window = ui::kiosk_setup_window(); - } + } delegate = Delegate::with_preferences(window.id); launcher = AppLauncher::with_window(window).configure_env(ui::theme::setup); diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index 6cb2f063..94de3f3a 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -3,7 +3,8 @@ use std::time::Duration; use druid::{ im::Vector, widget::{CrossAxisAlignment, Either, Flex, Label, List, Scroll, Slider, Split, ViewSwitcher}, - Color, Env, Insets, Key, LensExt, Menu, MenuItem, Selector, Widget, WidgetExt, WindowDesc, WindowState, + Color, Env, Insets, Key, LensExt, Menu, MenuItem, Selector, Widget, WidgetExt, WindowDesc, + WindowState, }; use druid_shell::Cursor; @@ -43,19 +44,31 @@ pub mod user; pub mod utils; pub fn main_window(config: &Config) -> WindowDesc { - let mut win = WindowDesc::new(root_widget()) + let mut win = WindowDesc::new(root_widget(config)) .title(compute_main_window_title) - .window_size(config.window_size) .show_title(false) .transparent_titlebar(true); + if config.kiosk_mode { - win = win.set_window_state(WindowState::Maximized) - .resizable(false) - .show_titlebar(false); + win = win + .set_window_state(WindowState::Maximized) + .resizable(false) + .show_titlebar(false) + .set_always_on_top(true); + + // Set the window size to the primary monitor's work area and position it at (0, 0) + if let Some(monitor) = druid::Screen::get_monitors().first() { + let work_area = monitor.virtual_work_rect(); + win = win + .window_size(work_area.size()) + .set_position(druid::Point::new(0.0, 0.0)); + } } else { - win = win.with_min_size((theme::grid(65.0), theme::grid(50.0))) - + win = win + .window_size(config.window_size) + .with_min_size((theme::grid(65.0), theme::grid(50.0))); } + if cfg!(target_os = "macos") { win.menu(menu::main_menu) } else { @@ -64,7 +77,7 @@ pub fn main_window(config: &Config) -> WindowDesc { } pub fn preferences_window(config: &Config) -> WindowDesc { - // Change this + // Change this let win_size = (theme::grid(50.0), theme::grid(55.0)); // On Windows, the window size includes the titlebar. @@ -82,10 +95,11 @@ pub fn preferences_window(config: &Config) -> WindowDesc { .transparent_titlebar(true); if config.kiosk_mode { - win = win.set_window_state(WindowState::Maximized) - .resizable(false) - .set_always_on_top(true) - .show_titlebar(false); + win = win + .set_window_state(WindowState::Maximized) + .resizable(false) + .set_always_on_top(true) + .show_titlebar(false); } else { win = win.window_size(win_size) } @@ -149,7 +163,7 @@ fn kiosk_setup_widget() -> impl Widget { ) } -fn root_widget() -> impl Widget { +fn root_widget(config: &Config) -> impl Widget { let playlists = Scroll::new(playlist::list_widget()) .vertical() .expand_height(); @@ -159,8 +173,8 @@ fn root_widget() -> impl Widget { .with_child(sidebar_menu_widget()) .with_default_spacer() .with_flex_child(playlists, 1.0) - .padding(if cfg!(target_os = "macos") { - // Accommodate the window controls on Mac. + .padding(if cfg!(target_os = "macos") && !config.kiosk_mode { + // Accommodate the window controls on macOS Insets::new(0.0, 24.0, 0.0, 0.0) } else { Insets::ZERO diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index c6f4436d..07782f67 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -270,10 +270,11 @@ fn general_tab_widget() -> impl Widget { .lens(AppState::config.then(Config::paginated_limit)), ); - col = col.with_default_spacer() - .with_child(Button::new("Done") - .align_right() - .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})); + col = col.with_default_spacer().with_child( + Button::new("Done") + .align_right() + .on_click(|ctx, _, _| ctx.submit_command(commands::CLOSE_WINDOW)), + ); col } @@ -323,13 +324,16 @@ fn account_tab_widget(tab: AccountTab) -> impl Widget { ); if matches!(tab, AccountTab::InPreferences) { - col = col.with_child(Button::new("Log Out").on_left_click(|ctx, _, _, _| { - ctx.submit_command(cmd::LOG_OUT); - })) - .with_default_spacer() - .with_child(Button::new("Done") - .align_right() - .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})) + col = col + .with_child(Button::new("Log Out").on_left_click(|ctx, _, _, _| { + ctx.submit_command(cmd::LOG_OUT); + })) + .with_default_spacer() + .with_child( + Button::new("Done") + .align_right() + .on_click(|ctx, _, _| ctx.submit_command(commands::CLOSE_WINDOW)), + ) } col.controller(Authenticate::new(tab)) @@ -481,10 +485,11 @@ fn cache_tab_widget() -> impl Widget { } }, )); - col = col.with_default_spacer() - .with_child(Button::new("Done") - .align_right() - .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})); + col = col.with_default_spacer().with_child( + Button::new("Done") + .align_right() + .on_click(|ctx, _, _| ctx.submit_command(commands::CLOSE_WINDOW)), + ); col.controller(MeasureCacheSize::new()) .lens(AppState::preferences) @@ -578,7 +583,9 @@ fn about_tab_widget() -> impl Widget { .with_child(build_time) .with_child(remote_url) .with_default_spacer() - .with_child(Button::new("Done") - .align_right() - .on_click(|ctx, _, _| {ctx.submit_command(commands::CLOSE_WINDOW)})) + .with_child( + Button::new("Done") + .align_right() + .on_click(|ctx, _, _| ctx.submit_command(commands::CLOSE_WINDOW)), + ) } diff --git a/psst-gui/src/ui/user.rs b/psst-gui/src/ui/user.rs index 68fe6350..f0a4efa3 100644 --- a/psst-gui/src/ui/user.rs +++ b/psst-gui/src/ui/user.rs @@ -7,7 +7,10 @@ use druid::{ use crate::{ data::{AppState, Library, UserProfile}, webapi::WebApi, - widget::{icons::{self, SvgIcon}, Async, Empty, MyWidgetExt}, + widget::{ + icons::{self, SvgIcon}, + Async, Empty, MyWidgetExt, + }, }; use super::theme; @@ -51,13 +54,11 @@ pub fn user_widget() -> impl Widget { .with_child(user_profile) .padding(theme::grid(1.0)), ) - .with_child( - Either::new( - |data: &AppState, _| !data.config.kiosk_mode, - preferences_widget(&icons::PREFERENCES), - Empty, - ) - ) + .with_child(Either::new( + |data: &AppState, _| !data.config.kiosk_mode, + preferences_widget(&icons::PREFERENCES), + Empty, + )) } fn preferences_widget(svg: &SvgIcon) -> impl Widget { From b7bab6ae3d12890e8d06cea29bb95c39b06dbbaa Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Fri, 27 Sep 2024 14:36:42 +0100 Subject: [PATCH 04/10] This should make preferences large --- psst-gui/src/ui/mod.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index 94de3f3a..182a784f 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -53,8 +53,7 @@ pub fn main_window(config: &Config) -> WindowDesc { win = win .set_window_state(WindowState::Maximized) .resizable(false) - .show_titlebar(false) - .set_always_on_top(true); + .show_titlebar(false); // Set the window size to the primary monitor's work area and position it at (0, 0) if let Some(monitor) = druid::Screen::get_monitors().first() { @@ -95,6 +94,13 @@ pub fn preferences_window(config: &Config) -> WindowDesc { .transparent_titlebar(true); if config.kiosk_mode { + if let Some(monitor) = druid::Screen::get_monitors().first() { + let work_area = monitor.virtual_work_rect(); + win = win + .window_size(work_area.size()) + .set_position(druid::Point::new(0.0, 0.0)); + } + win = win .set_window_state(WindowState::Maximized) .resizable(false) @@ -125,13 +131,22 @@ pub fn account_setup_window() -> WindowDesc { } pub fn kiosk_setup_window() -> WindowDesc { - let win = WindowDesc::new(kiosk_setup_widget()) + + let mut win = WindowDesc::new(kiosk_setup_widget()) .title("Setup") .resizable(false) .show_title(false) .set_window_state(WindowState::Maximized) .show_titlebar(false) .transparent_titlebar(true); + + if let Some(monitor) = druid::Screen::get_monitors().first() { + let work_area = monitor.virtual_work_rect(); + win = win + .window_size(work_area.size()) + .set_position(druid::Point::new(0.0, 0.0)); + } + if cfg!(target_os = "macos") { win.menu(menu::main_menu) } else { From 5f408f6caf0c7863caaa5e4bd5feeee884209307 Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Fri, 27 Sep 2024 14:38:42 +0100 Subject: [PATCH 05/10] Change line of where resizeable is --- psst-gui/src/ui/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index 182a784f..443bef9e 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -89,7 +89,6 @@ pub fn preferences_window(config: &Config) -> WindowDesc { let mut win = WindowDesc::new(preferences_widget()) .title("Preferences") - .resizable(false) .show_title(false) .transparent_titlebar(true); @@ -108,6 +107,7 @@ pub fn preferences_window(config: &Config) -> WindowDesc { .show_titlebar(false); } else { win = win.window_size(win_size) + .resizable(false) } if cfg!(target_os = "macos") { win.menu(menu::main_menu) @@ -131,10 +131,8 @@ pub fn account_setup_window() -> WindowDesc { } pub fn kiosk_setup_window() -> WindowDesc { - let mut win = WindowDesc::new(kiosk_setup_widget()) .title("Setup") - .resizable(false) .show_title(false) .set_window_state(WindowState::Maximized) .show_titlebar(false) @@ -144,7 +142,8 @@ pub fn kiosk_setup_window() -> WindowDesc { let work_area = monitor.virtual_work_rect(); win = win .window_size(work_area.size()) - .set_position(druid::Point::new(0.0, 0.0)); + .set_position(druid::Point::new(0.0, 0.0)) + .resizable(false); } if cfg!(target_os = "macos") { From 3c437b3d3309994c478f13dcbf80045497c21c9d Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Fri, 27 Sep 2024 17:55:49 +0100 Subject: [PATCH 06/10] Make preferences and log in small, force preference to stay always on top --- psst-gui/src/delegate.rs | 6 ++--- psst-gui/src/ui/mod.rs | 48 ++++++---------------------------- psst-gui/src/ui/preferences.rs | 2 +- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/psst-gui/src/delegate.rs b/psst-gui/src/delegate.rs index 40359183..96fe24ed 100644 --- a/psst-gui/src/delegate.rs +++ b/psst-gui/src/delegate.rs @@ -71,13 +71,13 @@ impl Delegate { } } - fn show_preferences(&mut self, config: &Config, ctx: &mut DelegateCtx) { + fn show_preferences(&mut self, ctx: &mut DelegateCtx) { match self.preferences_window { Some(id) => { ctx.submit_command(commands::SHOW_WINDOW.to(id)); } None => { - let window = ui::preferences_window(config); + let window = ui::preferences_window(); self.preferences_window.replace(window.id); ctx.new_window(window); } @@ -113,7 +113,7 @@ impl AppDelegate for Delegate { self.show_account_setup(ctx); Handled::Yes } else if cmd.is(commands::SHOW_PREFERENCES) { - self.show_preferences(&data.config, ctx); + self.show_preferences(ctx); Handled::Yes } else if cmd.is(cmd::CLOSE_ALL_WINDOWS) { self.close_all_windows(ctx); diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index 443bef9e..a48ae91f 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -75,40 +75,17 @@ pub fn main_window(config: &Config) -> WindowDesc { } } -pub fn preferences_window(config: &Config) -> WindowDesc { +pub fn preferences_window() -> WindowDesc { // Change this let win_size = (theme::grid(50.0), theme::grid(55.0)); - // On Windows, the window size includes the titlebar. - let win_size = if cfg!(target_os = "windows") { - const WINDOWS_TITLEBAR_OFFSET: f64 = 56.0; - (win_size.0, win_size.1 + WINDOWS_TITLEBAR_OFFSET) - } else { - win_size - }; - - let mut win = WindowDesc::new(preferences_widget()) + let win = WindowDesc::new(preferences_widget()) .title("Preferences") + .window_size(win_size) + .resizable(false) .show_title(false) + .set_always_on_top(true) .transparent_titlebar(true); - - if config.kiosk_mode { - if let Some(monitor) = druid::Screen::get_monitors().first() { - let work_area = monitor.virtual_work_rect(); - win = win - .window_size(work_area.size()) - .set_position(druid::Point::new(0.0, 0.0)); - } - - win = win - .set_window_state(WindowState::Maximized) - .resizable(false) - .set_always_on_top(true) - .show_titlebar(false); - } else { - win = win.window_size(win_size) - .resizable(false) - } if cfg!(target_os = "macos") { win.menu(menu::main_menu) } else { @@ -131,21 +108,12 @@ pub fn account_setup_window() -> WindowDesc { } pub fn kiosk_setup_window() -> WindowDesc { - let mut win = WindowDesc::new(kiosk_setup_widget()) + let win = WindowDesc::new(kiosk_setup_widget()) .title("Setup") + .resizable(false) .show_title(false) - .set_window_state(WindowState::Maximized) - .show_titlebar(false) + .window_size((theme::grid(50.0), theme::grid(45.0))) .transparent_titlebar(true); - - if let Some(monitor) = druid::Screen::get_monitors().first() { - let work_area = monitor.virtual_work_rect(); - win = win - .window_size(work_area.size()) - .set_position(druid::Point::new(0.0, 0.0)) - .resizable(false); - } - if cfg!(target_os = "macos") { win.menu(menu::main_menu) } else { diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index 07782f67..f276f934 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -430,9 +430,9 @@ impl> Controller for Authenticate { ctx.submit_command(cmd::SESSION_CONNECT); } AccountTab::KioskSetup => { - ctx.submit_command(cmd::SHOW_MAIN); ctx.submit_command(commands::CLOSE_WINDOW); ctx.submit_command(commands::SHOW_PREFERENCES); + ctx.submit_command(cmd::SHOW_MAIN); } } } From f57ecf8f2b3b4873ab4ddda20fe508e6bb9c9018 Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Fri, 27 Sep 2024 18:52:14 +0100 Subject: [PATCH 07/10] test --- psst-gui/src/ui/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index a48ae91f..c5a95ab7 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -46,8 +46,7 @@ pub mod utils; pub fn main_window(config: &Config) -> WindowDesc { let mut win = WindowDesc::new(root_widget(config)) .title(compute_main_window_title) - .show_title(false) - .transparent_titlebar(true); + .show_title(false); if config.kiosk_mode { win = win @@ -65,7 +64,8 @@ pub fn main_window(config: &Config) -> WindowDesc { } else { win = win .window_size(config.window_size) - .with_min_size((theme::grid(65.0), theme::grid(50.0))); + .with_min_size((theme::grid(65.0), theme::grid(50.0))) + .transparent_titlebar(true); } if cfg!(target_os = "macos") { From d6da48ef5a830aedec1df0d19b3e35ea82e61a89 Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Fri, 27 Sep 2024 19:43:16 +0100 Subject: [PATCH 08/10] Small fixes --- psst-gui/src/main.rs | 6 ++++-- psst-gui/src/ui/mod.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/psst-gui/src/main.rs b/psst-gui/src/main.rs index 009d3f9d..7ccc63e4 100644 --- a/psst-gui/src/main.rs +++ b/psst-gui/src/main.rs @@ -59,10 +59,12 @@ fn main() { WebApi::global().load_local_tracks(state.config.username().unwrap()); } else { // No configured credentials, open the account setup. - let mut window = ui::account_setup_window(); + let window = ui::account_setup_window(); if state.config.kiosk_mode { - window = ui::kiosk_setup_window(); + let window = ui::kiosk_setup_window(); + } else { + } delegate = Delegate::with_preferences(window.id); diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index c5a95ab7..b69291b7 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -76,9 +76,16 @@ pub fn main_window(config: &Config) -> WindowDesc { } pub fn preferences_window() -> WindowDesc { - // Change this let win_size = (theme::grid(50.0), theme::grid(55.0)); + // On Windows, the window size includes the titlebar. + let win_size = if cfg!(target_os = "windows") { + const WINDOWS_TITLEBAR_OFFSET: f64 = 56.0; + (win_size.0, win_size.1 + WINDOWS_TITLEBAR_OFFSET) + } else { + win_size + }; + let win = WindowDesc::new(preferences_widget()) .title("Preferences") .window_size(win_size) From 0fc437754c845dfb80252827f140249a73b35226 Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Fri, 27 Sep 2024 13:39:28 -0700 Subject: [PATCH 09/10] Linting --- psst-gui/src/main.rs | 3 +-- psst-gui/src/ui/mod.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/psst-gui/src/main.rs b/psst-gui/src/main.rs index 7ccc63e4..650693e0 100644 --- a/psst-gui/src/main.rs +++ b/psst-gui/src/main.rs @@ -62,9 +62,8 @@ fn main() { let window = ui::account_setup_window(); if state.config.kiosk_mode { - let window = ui::kiosk_setup_window(); + let window = ui::kiosk_setup_window(); } else { - } delegate = Delegate::with_preferences(window.id); diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index b69291b7..2be79678 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -85,7 +85,7 @@ pub fn preferences_window() -> WindowDesc { } else { win_size }; - + let win = WindowDesc::new(preferences_widget()) .title("Preferences") .window_size(win_size) From 68d02f55a50f45ad0e05eee883cab0ccd3401ecb Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Fri, 27 Sep 2024 13:44:53 -0700 Subject: [PATCH 10/10] Fixup linting issue --- psst-gui/src/main.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/psst-gui/src/main.rs b/psst-gui/src/main.rs index 650693e0..0e0bed1d 100644 --- a/psst-gui/src/main.rs +++ b/psst-gui/src/main.rs @@ -46,30 +46,29 @@ fn main() { paginated_limit, ) .install_as_global(); - - let delegate; - let launcher; - if state.config.has_credentials() { + let (delegate, launcher) = if state.config.has_credentials() { // Credentials are configured, open the main window. let window = ui::main_window(&state.config); - delegate = Delegate::with_main(window.id); - launcher = AppLauncher::with_window(window).configure_env(ui::theme::setup); + let delegate = Delegate::with_main(window.id); // Load user's local tracks for the WebApi. WebApi::global().load_local_tracks(state.config.username().unwrap()); - } else { - // No configured credentials, open the account setup. - let window = ui::account_setup_window(); - if state.config.kiosk_mode { - let window = ui::kiosk_setup_window(); + (delegate, AppLauncher::with_window(window)) + } else { + // No configured credentials, open the setup window. + let window = if state.config.kiosk_mode { + ui::kiosk_setup_window() } else { - } + ui::account_setup_window() + }; + let delegate = Delegate::with_preferences(window.id); - delegate = Delegate::with_preferences(window.id); - launcher = AppLauncher::with_window(window).configure_env(ui::theme::setup); + (delegate, AppLauncher::with_window(window)) }; + let launcher = launcher.configure_env(ui::theme::setup); + launcher .delegate(delegate) .launch(state)