Skip to content

Commit

Permalink
Fix so macOS can run kiosk
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode committed Sep 26, 2024
1 parent d301c1c commit c91c77c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 77 deletions.
11 changes: 4 additions & 7 deletions psst-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -37,10 +37,7 @@ fn main() {
let mut state = AppState::default_with_config(config);

let args: Vec<String> = 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(),
Expand All @@ -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);
Expand Down
52 changes: 24 additions & 28 deletions psst-gui/src/ui/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ pub fn home_widget() -> impl Widget<AppState> {
}

fn simple_title_label(title: &str) -> impl Widget<AppState> {
Flex::column()
.with_default_spacer()
.with_child(Label::new(title)
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0))
Flex::column().with_default_spacer().with_child(
Label::new(title)
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0)),
)
}

pub fn made_for_you() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -64,7 +63,7 @@ pub fn made_for_you() -> impl Widget<AppState> {
}

pub fn recommended_stations() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -82,27 +81,24 @@ pub fn recommended_stations() -> impl Widget<AppState> {

fn uniquely_yours_results_widget() -> impl Widget<WithCtx<MixedView>> {
Either::new(
|results: &WithCtx<MixedView>, _| {
results.data.playlists.is_empty()
},
|results: &WithCtx<MixedView>, _| results.data.playlists.is_empty(),
Empty,
Flex::column().with_default_spacer()
.with_child(Label::new("Uniquely yours")
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0))
).with_child(
Scroll::new(
Flex::row()
.with_child(playlist_results_widget())
Flex::column()
.with_default_spacer()
.with_child(
Label::new("Uniquely yours")
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0)),
)
.align_left(),
),
.with_child(
Scroll::new(Flex::row().with_child(playlist_results_widget())).align_left(),
),
)
}

pub fn uniquely_yours() -> impl Widget<AppState> {
Async::new(spinner_widget, uniquely_yours_results_widget, || {Empty})
Async::new(spinner_widget, uniquely_yours_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -119,7 +115,7 @@ pub fn uniquely_yours() -> impl Widget<AppState> {
}

pub fn user_top_mixes() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -136,7 +132,7 @@ pub fn user_top_mixes() -> impl Widget<AppState> {
}

pub fn best_of_artists() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -153,7 +149,7 @@ pub fn best_of_artists() -> impl Widget<AppState> {
}

pub fn your_shows() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -170,7 +166,7 @@ pub fn your_shows() -> impl Widget<AppState> {
}

pub fn jump_back_in() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -187,7 +183,7 @@ pub fn jump_back_in() -> impl Widget<AppState> {
}

pub fn shows_that_you_might_like() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget, || {Empty})
Async::new(spinner_widget, loaded_results_widget, || Empty)
.lens(
Ctx::make(
AppState::common_ctx,
Expand Down
46 changes: 30 additions & 16 deletions psst-gui/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -42,19 +43,31 @@ pub mod user;
pub mod utils;

pub fn main_window(config: &Config) -> WindowDesc<AppState> {
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 {
Expand All @@ -63,7 +76,7 @@ pub fn main_window(config: &Config) -> WindowDesc<AppState> {
}

pub fn preferences_window(config: &Config) -> WindowDesc<AppState> {
// Change this
// Change this
let win_size = (theme::grid(50.0), theme::grid(55.0));

// On Windows, the window size includes the titlebar.
Expand All @@ -81,10 +94,11 @@ pub fn preferences_window(config: &Config) -> WindowDesc<AppState> {
.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)
}
Expand Down Expand Up @@ -148,7 +162,7 @@ fn kiosk_setup_widget() -> impl Widget<AppState> {
)
}

fn root_widget() -> impl Widget<AppState> {
fn root_widget(config: &Config) -> impl Widget<AppState> {
let playlists = Scroll::new(playlist::list_widget())
.vertical()
.expand_height();
Expand All @@ -158,8 +172,8 @@ fn root_widget() -> impl Widget<AppState> {
.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
Expand Down
43 changes: 25 additions & 18 deletions psst-gui/src/ui/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,11 @@ fn general_tab_widget() -> impl Widget<AppState> {
.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
}
Expand Down Expand Up @@ -323,13 +324,16 @@ fn account_tab_widget(tab: AccountTab) -> impl Widget<AppState> {
);

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))
Expand Down Expand Up @@ -481,10 +485,11 @@ fn cache_tab_widget() -> impl Widget<AppState> {
}
},
));
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)
Expand Down Expand Up @@ -578,7 +583,9 @@ fn about_tab_widget() -> impl Widget<AppState> {
.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)),
)
}
17 changes: 9 additions & 8 deletions psst-gui/src/ui/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,13 +54,11 @@ pub fn user_widget() -> impl Widget<AppState> {
.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<T: Data>(svg: &SvgIcon) -> impl Widget<T> {
Expand Down

0 comments on commit c91c77c

Please sign in to comment.