feat: keep track of window size and position
This commit is contained in:
85
src/app.rs
85
src/app.rs
@@ -339,8 +339,7 @@ pub(crate) enum Message {
|
||||
ExportChatPicked(Option<PathBuf>, String),
|
||||
ModelManagerOpened(window::Id),
|
||||
WindowOpened(window::Id),
|
||||
WindowCloseRequested(window::Id),
|
||||
WindowClosed(window::Id),
|
||||
WindowEvent(window::Id, window::Event),
|
||||
RequestQuit,
|
||||
ConfirmQuit,
|
||||
CancelQuit,
|
||||
@@ -1046,33 +1045,50 @@ impl App {
|
||||
return focus_composer();
|
||||
}
|
||||
}
|
||||
Message::WindowCloseRequested(id) => {
|
||||
if id == self.main_window {
|
||||
return self.update(Message::RequestQuit);
|
||||
Message::WindowEvent(id, event) => match event {
|
||||
window::Event::Opened { position, size } if id == self.main_window => {
|
||||
self.config.interface.window_size =
|
||||
[size.width.round() as u32, size.height.round() as u32];
|
||||
self.config.interface.window_position = position
|
||||
.map(|position| [position.x.round() as i32, position.y.round() as i32]);
|
||||
}
|
||||
return window::close(id);
|
||||
}
|
||||
Message::WindowClosed(id) => {
|
||||
if self.model_manager_window == Some(id) {
|
||||
self.model_manager_window = None;
|
||||
self.pending_model_delete = None;
|
||||
window::Event::Moved(position) if id == self.main_window => {
|
||||
self.config.interface.window_position =
|
||||
Some([position.x.round() as i32, position.y.round() as i32]);
|
||||
}
|
||||
if self.preferences_window == Some(id) {
|
||||
self.preferences_window = None;
|
||||
self.preference_error = None;
|
||||
self.restore_dev_brain_confirmation = false;
|
||||
window::Event::Resized(size) if id == self.main_window => {
|
||||
self.config.interface.window_size =
|
||||
[size.width.round() as u32, size.height.round() as u32];
|
||||
}
|
||||
if self.help_window == Some(id) {
|
||||
self.help_window = None;
|
||||
window::Event::CloseRequested => {
|
||||
if id == self.main_window {
|
||||
return self.update(Message::RequestQuit);
|
||||
}
|
||||
return window::close(id);
|
||||
}
|
||||
}
|
||||
window::Event::Closed => {
|
||||
if self.model_manager_window == Some(id) {
|
||||
self.model_manager_window = None;
|
||||
self.pending_model_delete = None;
|
||||
}
|
||||
if self.preferences_window == Some(id) {
|
||||
self.preferences_window = None;
|
||||
self.preference_error = None;
|
||||
self.restore_dev_brain_confirmation = false;
|
||||
}
|
||||
if self.help_window == Some(id) {
|
||||
self.help_window = None;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Message::RequestQuit => {
|
||||
if self.active_chat_count() == 0 {
|
||||
return iced::exit();
|
||||
return self.quit();
|
||||
}
|
||||
self.quit_confirmation = true;
|
||||
}
|
||||
Message::ConfirmQuit => return iced::exit(),
|
||||
Message::ConfirmQuit => return self.quit(),
|
||||
Message::CancelQuit => self.quit_confirmation = false,
|
||||
Message::Escape(id) => {
|
||||
if self.preferences_window == Some(id) {
|
||||
@@ -1888,7 +1904,7 @@ impl App {
|
||||
// focus, so a dialog would never see it through `on_key_press`.
|
||||
iced::event::listen_with(|event, _, id| {
|
||||
matches!(
|
||||
event,
|
||||
&event,
|
||||
iced::Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key: keyboard::Key::Named(keyboard::key::Named::Escape),
|
||||
..
|
||||
@@ -1896,8 +1912,17 @@ impl App {
|
||||
)
|
||||
.then_some(Message::Escape(id))
|
||||
}),
|
||||
window::close_requests().map(Message::WindowCloseRequested),
|
||||
window::close_events().map(Message::WindowClosed),
|
||||
window::events().filter_map(|(id, event)| {
|
||||
matches!(
|
||||
event,
|
||||
window::Event::Opened { .. }
|
||||
| window::Event::Moved(_)
|
||||
| window::Event::Resized(_)
|
||||
| window::Event::CloseRequested
|
||||
| window::Event::Closed
|
||||
)
|
||||
.then_some(Message::WindowEvent(id, event))
|
||||
}),
|
||||
];
|
||||
subscriptions
|
||||
.push(iced::time::every(METRICS_SAMPLE_INTERVAL).map(|_| Message::MetricsTick));
|
||||
@@ -2071,6 +2096,20 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn quit(&mut self) -> Task<Message> {
|
||||
if self.database.is_none() {
|
||||
return iced::exit();
|
||||
}
|
||||
match self.config.save(&config_path()) {
|
||||
Ok(()) => iced::exit(),
|
||||
Err(error) => {
|
||||
self.quit_confirmation = false;
|
||||
self.error = Some(error);
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_cache_change(&mut self) {
|
||||
self.metrics.rescan_cache(&kv_cache_path());
|
||||
self.metrics_snapshot = self.metrics.snapshot();
|
||||
|
||||
Reference in New Issue
Block a user