Ok, this seems to work great for my needs. The rootWindow is never 0, even when maximized, so I give it ~20px of variability for Windows since it's dumb and adds weird padding on everything. I might increase this just to be safe, but it seems to catch my test scenarios.
const displays = await chrome.system.display.getInfo()
const displayWithOurWindow = await displays.find(display => {
if (
rootWindow.top >= (display.bounds.top - 20) ||
rootWindow.top <= (display.bounds.top + 20) ||
rootWindow.left >= (display.bounds.left - 20) ||
rootWindow.left <= (display.bounds.left + 20)
) return display
})
if (!displayWithOurWindow) { // output debug info if there is an issue.
console.error(rootWindow)
console.error(displays)
}
if (rootWindow.state !== 'normal') { // resize it if it's maximized
await chrome.windows.update(rootWindow.id, {
top: Math.floor(displayWithOurWindow.bounds.height / 7),
left: Math.floor(displayWithOurWindow.bounds.width / 5),
width: Math.floor(displayWithOurWindow.bounds.width - (displayWithOurWindow.bounds.width / 2)),
height: Math.floor(displayWithOurWindow.bounds.height - (displayWithOurWindow.bounds.height / 3)),
state: 'normal'
})
rootWindow = await chrome.windows.getCurrent()
await generalHelpers.sleep(300) // avoids Invalid value for bounds. Bounds must be at least 50% within visible screen space.
vltWindow = await chrome.windows.create({
url: "vlt-panel/vlt-panel.html",
type: "popup",
width: storageCache['VLT_defaultPanelWidth'],
height: rootWindow.height,
top: rootWindow.top,
left: rootWindow.left - storageCache['VLT_defaultPanelWidth'],
focused: true
})
. . .