Skip to content

Commit

Permalink
Disable window hiding
Browse files Browse the repository at this point in the history
See #181
  • Loading branch information
4JX committed Nov 17, 2024
1 parent 2ab9a19 commit 37d7eae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
7 changes: 6 additions & 1 deletion app/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ pub fn try_cli() -> Result<GuiCommand, CliError> {
let output = parse_cli()?;

match output {
CliOutput::Gui { hide_window, output } => Ok(GuiCommand::Start { hide_window, output }),
CliOutput::Gui { hide_window, output } => {
if hide_window {
println!("Window hiding is currently not supported. See https://github.com/4JX/L5P-Keyboard-RGB/issues/181");
}
Ok(GuiCommand::Start { hide_window, output })
}
CliOutput::Cli(output) => {
let manager_result = effects::EffectManager::new(effects::OperationMode::Cli);

Expand Down
20 changes: 9 additions & 11 deletions app/src/gui/menu_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use crate::{effects::custom_effect::CustomEffect, gui::modals, profile::Profile}
use super::{CustomEffectState, GuiMessage};

pub struct MenuBarState {
// TODO: Re-enable when upstream fixes window visibility
#[allow(dead_code)]
gui_sender: Sender<GuiMessage>,
opened_file: Option<PathBuf>,
open_file_dialog: Option<FileDialog>,
file_kind: Option<FileOperation>,
toasts: Toasts,
}

impl MenuBarState {
Expand All @@ -26,7 +27,6 @@ impl MenuBarState {
opened_file: None,
open_file_dialog: None,
file_kind: None,
toasts: Toasts::default(),
}
}
}
Expand All @@ -38,9 +38,7 @@ enum FileOperation {
}

impl MenuBarState {
pub fn show(&mut self, ctx: &Context, ui: &mut egui::Ui, current_profile: &mut Profile, current_effect: &mut CustomEffectState, changed: &mut bool) {
self.toasts.show(ctx);

pub fn show(&mut self, ctx: &Context, ui: &mut egui::Ui, current_profile: &mut Profile, current_effect: &mut CustomEffectState, changed: &mut bool, toasts: &mut Toasts) {
self.show_menu(ctx, ui);

if let Some(dialog) = &mut self.open_file_dialog {
Expand All @@ -55,7 +53,7 @@ impl MenuBarState {
*changed = true;
}
Err(_) => {
self.toasts.error("Could not load profile.").set_duration(Some(Duration::from_millis(5000))).set_closable(true);
toasts.error("Could not load profile.").set_duration(Some(Duration::from_millis(5000))).set_closable(true);
}
},
FileOperation::LoadEffect => match CustomEffect::from_file(path) {
Expand All @@ -64,12 +62,12 @@ impl MenuBarState {
*changed = true;
}
Err(_) => {
self.toasts.error("Could not load custom effect.").set_duration(Some(Duration::from_millis(5000))).set_closable(true);
toasts.error("Could not load custom effect.").set_duration(Some(Duration::from_millis(5000))).set_closable(true);
}
},
FileOperation::SaveProfile => {
if current_profile.save_profile(path).is_err() {
self.toasts.error("Could not save profile.").set_duration(Some(Duration::from_millis(5000))).set_closable(true);
toasts.error("Could not save profile.").set_duration(Some(Duration::from_millis(5000))).set_closable(true);
};
}
}
Expand Down Expand Up @@ -118,9 +116,9 @@ impl MenuBarState {
open::that("https://www.buymeacoffee.com/4JXdev").unwrap();
}

if ui.button("Exit").clicked() {
self.gui_sender.send(GuiMessage::Quit).unwrap();
}
// if ui.button("Exit").clicked() {
// self.gui_sender.send(GuiMessage::Quit).unwrap();
// }

#[cfg(target_os = "windows")]
{
Expand Down
19 changes: 16 additions & 3 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use eframe::{
CreationContext,
};

use egui_notify::Toasts;
use strum::IntoEnumIterator;
use tray_icon::menu::MenuEvent;

Expand Down Expand Up @@ -53,6 +54,7 @@ pub struct App {
effect_options: EffectOptions,
global_rgb: [u8; 3],
theme: Theme,
toasts: Toasts,
}

pub enum GuiMessage {
Expand Down Expand Up @@ -107,6 +109,7 @@ impl App {
effect_options: EffectOptions::default(),
global_rgb: [0; 3],
theme: Theme::default(),
toasts: Toasts::default(),
};

// Update the state according to the option chosen by the user
Expand Down Expand Up @@ -183,6 +186,17 @@ impl eframe::App for App {
}
}

// Show active toast messages
self.toasts.show(ctx);

// TODO: Remove when upstream fixes window hiding
if !self.visible.load(Ordering::SeqCst) {
self.visible.store(true, Ordering::SeqCst);
self.toasts
.warning("Window hiding is currently not supported.\nSee https://github.com/4JX/L5P-Keyboard-RGB/issues/181")
.set_duration(None);
}

if self.instance_not_unique && modals::unique_instance(ctx) {
self.exit_app();
};
Expand All @@ -192,10 +206,9 @@ impl eframe::App for App {
self.exit_app();
};

// frame.set_visible(!self.hide_window);

TopBottomPanel::top("top-panel").show(ctx, |ui| {
self.menu_bar.show(ctx, ui, &mut self.settings.current_profile, &mut self.custom_effect, &mut self.profile_changed);
self.menu_bar
.show(ctx, ui, &mut self.settings.current_profile, &mut self.custom_effect, &mut self.profile_changed, &mut self.toasts);
});

CentralPanel::default()
Expand Down
28 changes: 6 additions & 22 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ mod profile;
mod tray;
mod util;

use std::{
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};

use cli::{GuiCommand, OutputType};
use color_eyre::{eyre::eyre, Result};
use eframe::{egui::IconData, epaint::Vec2, App};
use eframe::{egui::IconData, epaint::Vec2};
use gui::App;

const APP_ICON: &'static [u8; 14987] = include_bytes!("../res/trayIcon.ico");
Expand Down Expand Up @@ -123,22 +120,9 @@ fn start_ui(output_type: OutputType, hide_window: bool) {
});
}

if has_tray.load(Ordering::SeqCst) {
while has_tray.load(Ordering::SeqCst) {
while !visible.load(Ordering::SeqCst) {
std::thread::sleep(Duration::from_millis(100));
}
if visible.load(Ordering::SeqCst) {
let app = App::new(output_type.clone(), has_tray.clone(), visible.clone());
let app = App::new(output_type, has_tray.clone(), visible.clone());

eframe::run_native("Legion RGB", native_options.clone(), Box::new(move |cc| Ok(Box::new(app.init(cc))))).unwrap();
}
}
} else {
let app = App::new(output_type, has_tray.clone(), visible.clone());

eframe::run_native("Legion RGB", native_options, Box::new(move |cc| Ok(Box::new(app.init(cc))))).unwrap();
}
eframe::run_native("Legion RGB", native_options, Box::new(move |cc| Ok(Box::new(app.init(cc))))).unwrap();
}

#[must_use]
Expand Down

0 comments on commit 37d7eae

Please sign in to comment.