diff --git a/src/background/index.js b/src/background/index.js index 46314e7..fc1e330 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -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; } - }, - ); + }); + }); }); }