Center approval popup over focused window to avoid macOS Space switch
Some checks failed
check / check (push) Failing after 3h10m55s
Some checks failed
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:
@@ -89,19 +89,32 @@ function requestApproval(origin, hostname) {
|
|||||||
pendingApprovals[id] = { origin, hostname, resolve };
|
pendingApprovals[id] = { origin, hostname, resolve };
|
||||||
|
|
||||||
const popupUrl = runtime.getURL("src/popup/index.html?approval=" + id);
|
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,
|
url: popupUrl,
|
||||||
type: "popup",
|
type: "popup",
|
||||||
width: 400,
|
width: popupWidth,
|
||||||
height: 500,
|
height: popupHeight,
|
||||||
},
|
};
|
||||||
(win) => {
|
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) {
|
if (win) {
|
||||||
pendingApprovals[id].windowId = win.id;
|
pendingApprovals[id].windowId = win.id;
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user