Skip to content

Commit

Permalink
feat: handle quit on close setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Feb 19, 2025
1 parent 349349a commit 8bd6e4e
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/stremio_app/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use native_windows_derive::NwgUi;
use native_windows_gui as nwg;
use rand::Rng;
use serde::Deserialize;
use serde_json;
use std::{
cell::RefCell,
Expand Down Expand Up @@ -29,6 +30,12 @@ use crate::stremio_app::{

use super::stremio_server::StremioServer;

#[derive(Default, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Settings {
pub quit_on_close: bool,
}

#[derive(Default, NwgUi)]
pub struct MainWindow {
pub command: String,
Expand All @@ -41,6 +48,7 @@ pub struct MainWindow {
pub release_candidate: bool,
pub autoupdater_setup_file: Arc<Mutex<Option<PathBuf>>>,
pub saved_window_style: RefCell<WindowStyle>,
pub settings: Arc<Mutex<Settings>>,
#[nwg_resource]
pub embed: nwg::EmbedResource,
#[nwg_resource(source_embed: Some(&data.embed), source_embed_str: Some("MAINICON"))]
Expand Down Expand Up @@ -223,6 +231,8 @@ impl MainWindow {
let hide_splash_sender = self.hide_splash_notice.sender();
let focus_sender = self.focus_notice.sender();
let autoupdater_setup_mutex = self.autoupdater_setup_file.clone();
let app_settings = self.settings.clone();

thread::spawn(move || loop {
if let Some(msg) = web_rx
.recv()
Expand Down Expand Up @@ -250,6 +260,18 @@ impl MainWindow {
web_tx_web.send(RPCResponse::open_media(command_ref)).ok();
}
}
Some("update_settings") => {
if let Some(arg) = msg.get_params() {
match serde_json::from_value::<Settings>(arg.to_owned()) {
Ok(settings) => {
let mut app_settings = app_settings.lock().unwrap();

Check warning on line 267 in src/stremio_app/app.rs

View workflow job for this annotation

GitHub Actions / test

Diff in \\?\D:\a\stremio-shell-ng\stremio-shell-ng\src\stremio_app\app.rs

Check warning on line 267 in src/stremio_app/app.rs

View workflow job for this annotation

GitHub Actions / test

Diff in \\?\D:\a\stremio-shell-ng\stremio-shell-ng\src\stremio_app\app.rs
*app_settings = settings;
println!("App settings updated.");
},
Err(e) => eprintln!("Failed to deserialize settings object: {e}")
}
}
}
Some("app-error") => {
hide_splash_sender.notice();
if let Some(arg) = msg.get_params() {
Expand Down Expand Up @@ -396,8 +418,14 @@ impl MainWindow {
if let nwg::EventData::OnWindowClose(data) = data {
data.close(false);
}
self.window.set_visible(false);
self.tray.tray_show_hide.set_checked(self.window.visible());
self.transmit_window_full_screen_change(false, false);

let settings = self.settings.lock().unwrap();
if settings.quit_on_close {
self.quit_notice.sender().notice();
} else {
self.window.set_visible(false);
self.tray.tray_show_hide.set_checked(self.window.visible());
self.transmit_window_full_screen_change(false, false);
}
}
}

0 comments on commit 8bd6e4e

Please sign in to comment.