Skip to content

Commit

Permalink
early exit
Browse files Browse the repository at this point in the history
  • Loading branch information
mastef committed Sep 26, 2024
1 parent 42e6a73 commit 0a54021
Showing 1 changed file with 44 additions and 48 deletions.
92 changes: 44 additions & 48 deletions lib/service_worker/background/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,65 +158,61 @@ export async function focusOnWindow(windowId) {
}

async function hideWindows(windowId) {
if (navigator.userAgent.search("Firefox") > -1) {
return;
}

if (!windowId || windowId < 0) {
return;
} else {
var hideWindows = await getLocalStorage("hideWindows", false);
if (!hideWindows) return;

var result = await browser.permissions.contains({permissions: ['system.display']});
if (result) {
// The extension has the permissions.
chrome.system.display.getInfo(async function (windowId, displaylayouts) {
globalDisplayInfo = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
if (navigator.userAgent.search("Firefox") > -1) return;
if (!windowId || windowId < 0) return;

var hideWindows = await getLocalStorage("hideWindows", false);
if (!hideWindows) return;

var result = await browser.permissions.contains({permissions: ['system.display']});
if (result) {
// The extension has the permissions.
chrome.system.display.getInfo(async function (windowId, displaylayouts) {
var globalDisplayInfo = context.globalDisplayInfo;
globalDisplayInfo.clear();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (let _iterator = displaylayouts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var displaylayout = _step.value;
globalDisplayInfo.push(displaylayout.bounds);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
for (let _iterator = displaylayouts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var displaylayout = _step.value;
globalDisplayInfo.push(displaylayout.bounds);
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
if (_didIteratorError) {
throw _iteratorError;
}
}
var windows = await browser.windows.getAll({populate: true});
var monitor = -1;
for (let i = windows.length - 1; i >= 0; i--) {
if (windows[i].id === windowId) {
for (let a in globalDisplayInfo) {
var result = is_in_bounds(windows[i], globalDisplayInfo[a]);
if (result) {
monitor = a;
}
}
var windows = await browser.windows.getAll({populate: true});
var monitor = -1;
for (let i = windows.length - 1; i >= 0; i--) {
if (windows[i].id === windowId) {
for (let a in globalDisplayInfo) {
var result = is_in_bounds(windows[i], globalDisplayInfo[a]);
if (result) {
monitor = a;
}
}
}
}

for (let i = windows.length - 1; i >= 0; i--) {
if (windows[i].id !== windowId) {
if (is_in_bounds(windows[i], globalDisplayInfo[monitor])) {
await browser.windows.update(windows[i].id, {"state": "minimized"});
}
for (let i = windows.length - 1; i >= 0; i--) {
if (windows[i].id !== windowId) {
if (is_in_bounds(windows[i], globalDisplayInfo[monitor])) {
await browser.windows.update(windows[i].id, {"state": "minimized"});
}
}
}.bind(null, windowId));
}
}
}.bind(null, windowId));
}
}

Expand Down

0 comments on commit 0a54021

Please sign in to comment.