-
-
Notifications
You must be signed in to change notification settings - Fork 102
Add support for activating tabs with window focus #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eee27bd
9bec60e
efa6081
03276bc
446b198
955ac36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,10 +8,11 @@ | |||||||
|
|
||||||||
| #import "App.h" | ||||||||
| #import "chrome.h" | ||||||||
| #import <ApplicationServices/ApplicationServices.h> | ||||||||
|
|
||||||||
|
|
||||||||
| static NSInteger const kMaxLaunchTimeInSeconds = 15; | ||||||||
| static NSString * const kVersion = @"1.10.3"; | ||||||||
| static NSString * const kVersion = @"1.11.0"; | ||||||||
| static NSString * const kJsPrintSource = @"(function() { return document.getElementsByTagName('html')[0].outerHTML })();"; | ||||||||
|
|
||||||||
|
|
||||||||
|
|
@@ -411,34 +412,41 @@ - (void)goForwardInTab:(Arguments *)args { | |||||||
| } | ||||||||
|
|
||||||||
| - (void)activateTab:(Arguments *)args { | ||||||||
| // Support two forms: | ||||||||
| // Support legacy and explicit forms: | ||||||||
| // 1) <tabId> | ||||||||
| // 2) <windowId>:<tabId> | ||||||||
| // 2) <windowId>:<tabId> (prefer window match, fallback to scanning) | ||||||||
| NSString *rawId = [args asString:@"id"]; | ||||||||
| if (!rawId || rawId.length == 0) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| NSRange sep = [rawId rangeOfString:@":"]; | ||||||||
| if (sep.location != NSNotFound) { | ||||||||
| // window-specific activation | ||||||||
| NSString *winStr = [rawId substringToIndex:sep.location]; | ||||||||
| NSString *tabStr = [rawId substringFromIndex:sep.location + 1]; | ||||||||
|
|
||||||||
| NSInteger windowId = [winStr integerValue]; | ||||||||
| NSInteger tabId = [tabStr integerValue]; | ||||||||
|
|
||||||||
| BOOL done = NO; | ||||||||
| chromeWindow *window = [self findWindow:windowId]; | ||||||||
| if (!window) { | ||||||||
| return; | ||||||||
| } else { | ||||||||
| chromeTab *tabInWindow = [self findTab:tabId inWindow:window]; | ||||||||
| if (tabInWindow) { | ||||||||
| [self setTabActive:tabInWindow inWindow:window]; | ||||||||
| done = YES; | ||||||||
| } else { | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| chromeTab *tab = [self findTab:tabId inWindow:window]; | ||||||||
| if (!tab) { | ||||||||
| return; | ||||||||
| if (!done) { | ||||||||
| chromeTab *tabAny = [self findTab:tabId]; | ||||||||
| chromeWindow *winAny = tabAny ? [self findWindowWithTab:tabAny] : nil; | ||||||||
| if (tabAny && winAny) { | ||||||||
| [self setTabActive:tabAny inWindow:winAny]; | ||||||||
| } else { | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| [self setTabActive:tab inWindow:window]; | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -449,6 +457,30 @@ - (void)activateTab:(Arguments *)args { | |||||||
| [self setTabActive:tab inWindow:window]; | ||||||||
| } | ||||||||
|
|
||||||||
| // Same parsing as activateTab:, but ensures the window is brought to the foreground | ||||||||
| - (void)activateTabAndFocus:(Arguments *)args { | ||||||||
| [self activateTab:args]; | ||||||||
|
|
||||||||
| NSString *rawId = [args asString:@"id"]; | ||||||||
| if (!rawId || rawId.length == 0) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| // Determine tabId and attempt to focus the window containing it with retries | ||||||||
| NSInteger tabId = 0; | ||||||||
| NSRange sep = [rawId rangeOfString:@":"]; | ||||||||
| if (sep.location != NSNotFound) { | ||||||||
| NSString *tabStr = [rawId substringFromIndex:sep.location + 1]; | ||||||||
| tabId = [tabStr integerValue]; | ||||||||
| } else { | ||||||||
| tabId = [rawId integerValue]; | ||||||||
| } | ||||||||
|
Comment on lines
+461
to
+477
|
||||||||
|
|
||||||||
| BOOL focused = [self focusWindowContainingTabId:tabId maxAttempts:12 sleepMs:150]; | ||||||||
| if (!focused) { | ||||||||
| } | ||||||||
|
Comment on lines
+480
to
+481
|
||||||||
| if (!focused) { | |
| } | |
| // If not focused, no action is taken. |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty else block serves no purpose. Consider removing this empty block or adding a comment explaining why no action is needed when the window focus verification fails.
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty else blocks at lines 439 and 448 make the code unclear. Consider removing these empty blocks or adding comments explaining why no action is needed in these cases.