mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-25 10:48:36 +00:00
feat: remember window size on close
This commit is contained in:
parent
872247b1da
commit
74dd0b4e49
2 changed files with 19 additions and 1 deletions
|
@ -2,11 +2,17 @@ use crate::{constants::CMD_NAME, file_utils::get_writer, paths::get_config_dir,
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fs::File, io::BufReader};
|
use std::{fs::File, io::BufReader};
|
||||||
|
|
||||||
|
fn default_win_size() -> [i32; 2] {
|
||||||
|
[360, 400]
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub selected_profile_uuid: String,
|
pub selected_profile_uuid: String,
|
||||||
pub debug_view_enabled: bool,
|
pub debug_view_enabled: bool,
|
||||||
pub user_profiles: Vec<Profile>,
|
pub user_profiles: Vec<Profile>,
|
||||||
|
#[serde(default = "default_win_size")]
|
||||||
|
pub win_size: [i32; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
@ -16,6 +22,7 @@ impl Default for Config {
|
||||||
selected_profile_uuid: "".to_string(),
|
selected_profile_uuid: "".to_string(),
|
||||||
debug_view_enabled: false,
|
debug_view_enabled: false,
|
||||||
user_profiles: vec![],
|
user_profiles: vec![],
|
||||||
|
win_size: default_win_size(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ pub enum Msg {
|
||||||
SaveProfile(Profile),
|
SaveProfile(Profile),
|
||||||
RunSetCap,
|
RunSetCap,
|
||||||
OpenLibsurviveSetup,
|
OpenLibsurviveSetup,
|
||||||
|
SaveWinSize(i32, i32),
|
||||||
Quit,
|
Quit,
|
||||||
ProcessDevicesLog(Vec<String>),
|
ProcessDevicesLog(Vec<String>),
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,7 @@ impl SimpleComponent for App {
|
||||||
#[root]
|
#[root]
|
||||||
adw::ApplicationWindow {
|
adw::ApplicationWindow {
|
||||||
set_title: Some(APP_NAME),
|
set_title: Some(APP_NAME),
|
||||||
set_default_size: (400, 300),
|
set_default_size: (win_size[0], win_size[1]),
|
||||||
gtk::Box {
|
gtk::Box {
|
||||||
set_orientation: gtk::Orientation::Vertical,
|
set_orientation: gtk::Orientation::Vertical,
|
||||||
set_hexpand: true,
|
set_hexpand: true,
|
||||||
|
@ -213,6 +214,10 @@ impl SimpleComponent for App {
|
||||||
model.debug_view.widget(),
|
model.debug_view.widget(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
connect_close_request[sender] => move |win| {
|
||||||
|
sender.input(Msg::SaveWinSize(win.width(), win.height()));
|
||||||
|
gtk::Inhibit(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,7 +492,12 @@ impl SimpleComponent for App {
|
||||||
))
|
))
|
||||||
.expect("Failed to present Libsurvive Setup Window");
|
.expect("Failed to present Libsurvive Setup Window");
|
||||||
}
|
}
|
||||||
|
Msg::SaveWinSize(w, h) => {
|
||||||
|
self.config.win_size = [w, h];
|
||||||
|
self.config.save();
|
||||||
|
}
|
||||||
Msg::Quit => {
|
Msg::Quit => {
|
||||||
|
sender.input(Msg::SaveWinSize(self.app_win.width(), self.app_win.height()));
|
||||||
self.application.quit();
|
self.application.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,6 +509,7 @@ impl SimpleComponent for App {
|
||||||
sender: ComponentSender<Self>,
|
sender: ComponentSender<Self>,
|
||||||
) -> ComponentParts<Self> {
|
) -> ComponentParts<Self> {
|
||||||
let config = Config::get_config();
|
let config = Config::get_config();
|
||||||
|
let win_size = config.win_size.clone();
|
||||||
let profiles = Self::profiles_list(&config);
|
let profiles = Self::profiles_list(&config);
|
||||||
let dependencies_dialog = adw::MessageDialog::builder()
|
let dependencies_dialog = adw::MessageDialog::builder()
|
||||||
.modal(true)
|
.modal(true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue