Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): use unique identifier for window focus restoration #5898

Closedmohamedmastouri-hue(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5898/headopened View on GitHub

Showing 1 changed file with 25 additions and 0 deletions.

x
0 of 1 viewed, 1 left
25 additions and 0 deletionsapps/desktop/src/preview/Manager.tsModified
View file
@@ -3008,6 +3008,7 @@
() => webContents.getFocusedWebContents(),
let keyDownAttempted = false;
+ const focusRestoreId = `__t3_focus_${Math.random().toString(36).slice(2)}`;
const releaseInput = Effect.gen(function* () {
if (keyDownAttempted) {
yield* sendCleanup("Input.dispatchKeyEvent", keySequence.keyUp).pipe(Effect.ignore);
@@ -3024,6 +3025,17 @@
() => previouslyFocused.focus(),
).pipe(Effect.ignore);
+ yield* attemptPromise(
+ {
+ operation: "automationPress.restoreActiveElement",
+ tabId,
+ webContentsId: previouslyFocused.id,
+ },
+ () =>
+ previouslyFocused.executeJavaScript(
+ `if (window['${focusRestoreId}'] && typeof window['${focusRestoreId}'].focus === 'function') { window['${focusRestoreId}'].focus(); } delete window['${focusRestoreId}'];`,
+ ),
+ ).pipe(Effect.ignore);
@@ -3032,6 +3044,19 @@
// changing which thread is mounted in the UI. Restore the previous renderer