Center approval popup over focused window to avoid macOS Space switch
check / check (push) Failing after 3h10m55s
check / check (push) Failing after 3h10m55s
Use getLastFocused to find the current Chrome window and position the approval popup centered over it. This keeps the popup on the same macOS virtual desktop instead of switching Spaces.
This commit is contained in:
1 parent
dce561464d
commit
dce3b4aa08
1 file changed
+21
-8
+21
-8
@@ -89,19 +89,32 @@ function requestApproval(origin, hostname) {
|
||||
pendingApprovals[id] = { origin, hostname, resolve };
|
||||
|
||||
const popupUrl = runtime.getURL("src/popup/index.html?approval=" + id);
|
||||
windowsApi.create(
|
||||
{
|
||||
const popupWidth = 400;
|
||||
const popupHeight = 500;
|
||||
|
||||
// Center the popup over the focused window so macOS keeps it
|
||||
// on the same Space instead of switching desktops.
|
||||
windowsApi.getLastFocused((currentWin) => {
|
||||
const opts = {
|
||||
url: popupUrl,
|
||||
type: "popup",
|
||||
width: 400,
|
||||
height: 500,
|
||||
},
|
||||
(win) => {
|
||||
width: popupWidth,
|
||||
height: popupHeight,
|
||||
};
|
||||
if (currentWin) {
|
||||
opts.left = Math.round(
|
||||
currentWin.left + (currentWin.width - popupWidth) / 2,
|
||||
);
|
||||
opts.top = Math.round(
|
||||
currentWin.top + (currentWin.height - popupHeight) / 2,
|
||||
);
|
||||
}
|
||||
windowsApi.create(opts, (win) => {
|
||||
if (win) {
|
||||
pendingApprovals[id].windowId = win.id;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user