perf(arc): replace tab iteration loop with AppleScript whose filter#26969
perf(arc): replace tab iteration loop with AppleScript whose filter#26969hua86430 wants to merge 3 commits intoraycast:mainfrom
whose filter#26969Conversation
Replace manual `repeat` loop that iterates through every tab to find a matching ID with AppleScript's native `whose` clause for direct lookup. This eliminates O(n) sequential tab scanning, improving responsiveness especially when many tabs are open.
|
Thank you for your first contribution! 🎉 🔔 @thomaspaulmann @zach-fuller @ankitchouhan1020 @pernielsentikaer @danpalmer @rgrunberg @tleo19 @loris @bdsqqq @xilopaint @jayeshbhole @hinzed1127 @omar-salama @underscoregeb @ridemountainpig @nebbles @alanxmay @gdsmith @EasyKey5 @Pavelas @mchoun you might want to have a look. You can use this guide to learn how to check out the Pull Request locally in order to test it. 📋 Quick checkout commandsBRANCH="fix/arc-enhance-tab-lookup-performance"
FORK_URL="https://github.com/hua86430/extensions.git"
EXTENSION_NAME="arc"
REPO_NAME="extensions"
git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run devWe're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days. |
Greptile SummaryThis PR replaces the O(n)
Confidence Score: 3/5Merging as-is changes error-handling behavior — a missing tab now throws where it previously returned silently. One P1 finding: the extensions/arc/src/arc.ts — specifically the Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/arc/src/arc.ts
Line: 121-123
Comment:
**Redundant window guard after `ensureArcIsRunning()`**
The `ensureArcIsRunning()` call on line 118 already guarantees at least one window exists (see lines 17–19 of the same file where the same `if (count of windows) is 0 then make new window` guard runs). This block is therefore unreachable and can be removed.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: extensions/arc/src/arc.ts
Line: 125
Comment:
**`whose` clause throws when no tab matches**
If no tab with `tabId` exists in the first window (e.g., the tab was closed between when the list was fetched and this action runs), `first tab whose id is "..."` raises an AppleScript error. The old loop silently returned nothing in that case. `runAppleScript` will surface this as a thrown JavaScript error, and callers (`selectTab`, `closeTab`, `reloadTab`) have no try/catch, changing the observable behaviour from a silent no-op to an uncaught exception.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "docs(arc): add changelog entry for tab l..." | Re-trigger Greptile |
…ssing tab - Remove `if (count of windows) is 0` check since `ensureArcIsRunning()` already guarantees a window exists - Wrap `whose` clause in try/end try to gracefully handle cases where the tab no longer exists
pernielsentikaer
left a comment
There was a problem hiding this comment.
Hi @hua86430 👋
Would you consider moving activate inside the try block so Arc doesn't activate when the tab wasn't found (preserving old behavior)
I converted this PR into a draft until it's ready for the review, please press the button Ready for review when it's ready and we'll have a look 😊
Description
Replace manual
repeatloop inrunAppleScriptActionOnTabwith AppleScript's nativewhoseclause for direct tab lookup.Before (O(n) loop)
After (direct lookup)
This eliminates O(n) sequential tab scanning, improving responsiveness especially when many tabs are open. The
try/end tryblock gracefully handles cases where the tab no longer exists.Checklist
npm run buildand tested this distribution build in Raycastassetsfolder are used by the extension itselfREADMEare placed outside of themetadatafolder