Skip to content

Commit

Permalink
save application settings on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick committed Oct 17, 2024
1 parent 33f0102 commit 151c976
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
12 changes: 11 additions & 1 deletion crates/steel_core/src/ipc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ impl CoreClient {
.unwrap();
}

pub fn exit_requested(&self) {
pub fn restart_requested(&self, settings: &Settings) {
self.server
.send(AppMessageIn::UISettingsUpdated(settings.clone()))
.unwrap();
self.server.send(AppMessageIn::UIRestartRequested).unwrap();
}

pub fn exit_requested(&self, settings: &Settings) {
self.server
.send(AppMessageIn::UISettingsUpdated(settings.clone()))
.unwrap();
self.server.send(AppMessageIn::UIExitRequested).unwrap();
}

Expand Down
1 change: 1 addition & 0 deletions crates/steel_core/src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum AppMessageIn {

UIConnectRequested,
UIDisconnectRequested,
UIRestartRequested,
UIExitRequested,
UIChatOpened(String),
UIChatClosed(String),
Expand Down
2 changes: 1 addition & 1 deletion crates/steel_core/src/settings/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ impl Default for WindowGeometry {
display: 0,
}
}
}
}
9 changes: 6 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl Application {
AppMessageIn::UIDisconnectRequested => {
self.disconnect();
}

AppMessageIn::UIRestartRequested => {
crate::core::os::restart();
}

AppMessageIn::UIExitRequested => {
break;
}
Expand Down Expand Up @@ -431,9 +436,7 @@ impl Application {
.unwrap();

match state {
ChatState::Left => {
self.send_system_message(chat, "You have left the chat")
}
ChatState::Left => self.send_system_message(chat, "You have left the chat"),
ChatState::JoinInProgress => self.send_system_message(chat, "Joining the chat..."),
ChatState::Joined => match chat.is_channel() {
true => self.send_system_message(chat, "You have joined the chat"),
Expand Down
4 changes: 2 additions & 2 deletions src/gui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Menu {
ui: &mut egui::Ui,
ctx: &egui::Context,
_frame: &mut eframe::Frame,
_state: &mut UIState,
state: &UIState,
) {
ui.menu_button("application", |ui| {
if ui.button("settings").clicked() {
Expand All @@ -105,7 +105,7 @@ impl Menu {
ui.separator();

if ui.button("restart").clicked() {
crate::core::os::restart();
state.core.restart_requested(&state.settings);
ui.close_menu();
}
if ui.button("exit").clicked() {
Expand Down
10 changes: 9 additions & 1 deletion src/gui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ impl ApplicationWindow {
ctx.send_viewport_cmd(egui::ViewportCommand::Title(new_tab_title));
}

fn refresh_window_geometry_settings(&mut self, ctx: &egui::Context) {
let window = ctx.screen_rect();
self.s.settings.application.window.width = window.width() as i32;
self.s.settings.application.window.height = window.height() as i32;
}

pub fn process_pending_events(&mut self, ctx: &egui::Context) {
// If the main window is restored after having being minimized for some time, it still needs to be responsive
// enough.
Expand Down Expand Up @@ -303,9 +309,11 @@ impl eframe::App for ApplicationWindow {
if !self.menu.dialogs_visible() {
self.chat.return_focus(ctx, &self.s);
}

self.refresh_window_geometry_settings(ctx);
}

fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {
self.s.core.exit_requested();
self.s.core.exit_requested(&self.s.settings);
}
}

0 comments on commit 151c976

Please sign in to comment.