fix(macos): focus the last-used workspace on Dock activation by ker2xu · Pull Request #889 · spacering-net/codeg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src-tauri/src/commands/windows.rs
46 changes: 46 additions & 0 deletions src-tauri/src/commands/workspace_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,52 @@ mod tests {
}
}

#[test]
fn activation_prefers_the_most_recent_existing_workspace() {
let mut state = SessionState::default();
state.mark_open(LOCAL);
state.mark_open(remote(1));
state.mark_open(remote(2));
assert_eq!(state.activation_target(|_| true), Some(remote(2)));
assert_eq!(
state.activation_target(|window| window != remote(2)),
Some(remote(1))
);
state.mark_open(LOCAL);
assert_eq!(state.activation_target(|_| true), Some(LOCAL));
}

#[test]
fn activation_does_not_reopen_a_closed_local_workspace() {
let mut state = SessionState::default();
state.mark_open(LOCAL);
state.mark_open(remote(1));
state.mark_closed(LOCAL);
// main still physically exists, hidden to tray; it must stay hidden.
assert_eq!(state.activation_target(|_| true), Some(remote(1)));
state.mark_closed(remote(1));
assert_eq!(state.activation_target(|_| true), Some(LOCAL));
}

#[test]
fn activation_waits_for_a_remote_only_restore() {
// As `begin_restore` leaves it: the remembered front is still pending.
let mut state = SessionState {
pending: vec![remote(1)],
restoring: true,
restore_front: Some(remote(1)),
..SessionState::default()
};
assert_eq!(state.activation_target(|window| window == LOCAL), None);
state.mark_open(remote(1));
assert_eq!(state.activation_target(|_| true), Some(remote(1)));
assert_eq!(state.snapshot(), vec![remote(1)]);
// Still restoring, but nothing is left pending to wait for: with the
// restored window closed again, local is the only workspace left.
state.mark_closed(remote(1));
assert_eq!(state.activation_target(|_| true), Some(LOCAL));
}

#[test]
fn stored_list_round_trips() {
let windows = [remote(4), LOCAL, remote(2)];
Expand Down
10 changes: 7 additions & 3 deletions src-tauri/src/lib.rs
Loading