Gui switches to a different workspace when current workspace is emptied
Rather than just quitting the app and potentially silently killing off a number of panes that might be running in other workspaces, we now will pick one of those workspaces and activate it. refs: #1531
This commit is contained in:
1 parent
180e72a673
commit
76a213f7ab
2 files changed
+26
-7
No files matched your search
+9
-5
@@ -419,14 +419,18 @@ impl Mux {
|
||||
.unwrap_or_else(|| DEFAULT_WORKSPACE.to_string())
|
||||
}
|
||||
|
||||
pub fn set_active_workspace_for_client(&self, ident: &Arc<ClientId>, workspace: &str) {
|
||||
let mut clients = self.clients.borrow_mut();
|
||||
if let Some(info) = clients.get_mut(&ident) {
|
||||
info.active_workspace.replace(workspace.to_string());
|
||||
self.notify(MuxNotification::ActiveWorkspaceChanged(ident.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Assigns the active workspace name for the current identity
|
||||
pub fn set_active_workspace(&self, workspace: &str) {
|
||||
if let Some(ident) = self.identity.borrow().clone() {
|
||||
let mut clients = self.clients.borrow_mut();
|
||||
if let Some(info) = clients.get_mut(&ident) {
|
||||
info.active_workspace.replace(workspace.to_string());
|
||||
self.notify(MuxNotification::ActiveWorkspaceChanged(ident));
|
||||
}
|
||||
self.set_active_workspace_for_client(&ident, workspace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,8 +62,23 @@ impl GuiFrontEnd {
|
||||
let mux = Mux::get().expect("mux started and running on main thread");
|
||||
let workspace = mux.active_workspace_for_client(&client_id);
|
||||
if mux.is_workspace_empty(&workspace) {
|
||||
log::trace!("Mux workspace is empty, terminate gui");
|
||||
Connection::get().unwrap().terminate_message_loop();
|
||||
// We don't want to silently kill off things that might
|
||||
// be running in other workspaces, so let's pick one
|
||||
// and activate it
|
||||
let workspaces = mux.iter_workspaces();
|
||||
if let Some(workspace) = workspaces.get(0).map(|s| s.to_string()) {
|
||||
let activity = mux::activity::Activity::new();
|
||||
let client_id = client_id.clone();
|
||||
promise::spawn::spawn(async move {
|
||||
let mux = Mux::get().expect("mux started and running on main thread");
|
||||
mux.set_active_workspace_for_client(&client_id, &workspace);
|
||||
switch_workspace(&workspace);
|
||||
drop(activity);
|
||||
}).detach();
|
||||
} else {
|
||||
log::trace!("Mux workspace is empty, terminate gui");
|
||||
Connection::get().unwrap().terminate_message_loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user