Skip to content

Commit

Permalink
Introduced dialog notification for unsuccessful config file parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko19907 committed Dec 29, 2023
1 parent 88f329d commit 4043c7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ impl Controller {
return Controller::default();
}

/// Sets the settings manager for the controller
pub fn set_settings(controller: Arc<Mutex<Self>>, settings: SettingsManager) {
let mut controller = controller.lock().unwrap();
controller.settings_manager = settings;
controller.update_max_move();
}

pub fn run(controller: Arc<Mutex<Self>>) {
thread::Builder::new().name("mover_thread".to_string()).spawn(move || {
let interval = controller.lock().unwrap().get_interval() as u64;
Expand Down
13 changes: 13 additions & 0 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ impl SystemTray {
self.tray.show("OLEDShift", Some("OLEDShift is running in the system tray"), Some(flags), Some(&self.icon));
}

/// Shows the failed to parse the config file error message
fn show_config_parse_failed_message(&self, error_message: &str) {
let message = format!("Failed to parse the config file!\nThe default settings will be used instead.\n\nError: {}", error_message);
nwg::modal_error_message(&self.window, "Config parsing failed", &message);
}

fn do_delay(&self, delay: Delays) {
match delay {
Delays::ThirtySeconds => self.controller.lock().unwrap().set_interval(Delays::ThirtySeconds as i32),
Expand Down Expand Up @@ -246,6 +252,7 @@ mod system_tray_ui {
use std::cell::RefCell;
use std::ops::Deref;
use crate::controller::{Controller, Delays, Distances};
use crate::settings::SettingsManager;
use crate::view::{ICON, SystemTray};

pub struct SystemTrayUi {
Expand Down Expand Up @@ -370,6 +377,12 @@ mod system_tray_ui {
default_handler: Default::default(),
};

// Setup the controller
let settings_manager = SettingsManager::new().unwrap_or_else(|(err, manager)| {
ui.inner.show_config_parse_failed_message(&err);
return manager;
});
Controller::set_settings(ui.inner.controller.clone(), settings_manager);
// Start the controller
Controller::run(ui.inner.controller.clone());

Expand Down

0 comments on commit 4043c7b

Please sign in to comment.