Skip to content

Commit

Permalink
perf: activate last frontmost app when closing query window if settin…
Browse files Browse the repository at this point in the history
…gs window is not showing
  • Loading branch information
tisfeng committed Feb 17, 2024
1 parent 51b5792 commit 792769e
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,7 @@ - (void)showFloatingWindow:(EZBaseQueryWindow *)window atPoint:(CGPoint)point {
return;
}

EZPreferencesWindowController *preferencesWindowController = [EZPreferencesWindowController shared];
if (preferencesWindowController.isShowing) {
[preferencesWindowController.window close];
}

// Workaround for SwiftUI Settings window
// https://github.com/tisfeng/Easydict/issues/362
for (NSWindow *window in [NSApp windows]) {
if ([window.identifier isEqualToString:@"com_apple_SwiftUI_Settings_window"]) {
[window close];
}
}
[[self currentShowingSettingsWindow] close];

// get safe window position
CGPoint safeLocation = [EZCoordinateUtils getFrameSafePoint:window.frame moveToPoint:point inScreen:self.screen];
Expand All @@ -445,6 +434,22 @@ - (void)showFloatingWindow:(EZBaseQueryWindow *)window atPoint:(CGPoint)point {
[self updateFloatingWindowType:window.windowType];
}

- (nullable NSWindow *)currentShowingSettingsWindow {
EZPreferencesWindowController *preferencesWindowController = [EZPreferencesWindowController shared];
if (preferencesWindowController.isShowing) {
return preferencesWindowController.window;
}

// Workaround for SwiftUI Settings window, fix https://github.com/tisfeng/Easydict/issues/362
for (NSWindow *window in [NSApp windows]) {
if ([window.identifier isEqualToString:@"com_apple_SwiftUI_Settings_window"] && window.visible) {
return window;
}
}

return nil;
}

- (void)updateFloatingWindowType:(EZWindowType)floatingWindowType {
NSNumber *windowType = @(floatingWindowType);
[self.floatingWindowTypeArray removeObject:windowType];
Expand Down Expand Up @@ -912,6 +917,11 @@ - (void)closeFloatingWindow {
self.floatingWindow.titleBar.pin = NO;
[self.floatingWindow close];

if (![self currentShowingSettingsWindow]) {
// recover last app.
[self activeLastFrontmostApplication];
}

if ([EZMainQueryWindow isAlive]) {
[self.mainWindow orderBack:nil];
}
Expand Down

0 comments on commit 792769e

Please sign in to comment.