Allow to open Manager in a popup

Closes #47
This commit is contained in:
Nils Maier 2019-09-12 14:43:22 +02:00
parent 33de1cbce9
commit 84fea3ba35
5 changed files with 33 additions and 3 deletions

View File

@ -585,6 +585,10 @@
"description": "Preferences/General; group text",
"message": "Manager"
},
"pref_manager_in_popup": {
"description": "checkbox text",
"message": "Open manager in a new popup window"
},
"pref_manager_tooltip": {
"description": "Preferences/General",
"message": "Show tooltips in Manager tabs"

View File

@ -1,5 +1,6 @@
{
"button-type": "popup",
"manager-in-popup": false,
"concurrent": 4,
"queue-notification": true,
"finish-notification": true,

View File

@ -2,8 +2,9 @@
// License: MIT
import { windows, tabs, runtime } from "../lib/browser";
import {getManager} from "./manager/man";
import { getManager } from "./manager/man";
import DEFAULT_ICONS from "../data/icons.json";
import { Prefs } from "./prefs";
const DONATE_URL = "https://www.downthemall.org/howto/donate/";
const MANAGER_URL = "/windows/manager.html";
@ -93,11 +94,33 @@ export async function openManager(focus = true) {
catch (ex) {
console.error(ex.toString(), ex);
}
const url = runtime.getURL(MANAGER_URL);
const openInPopup = await Prefs.get("manager-in-popup");
if (openInPopup) {
const etabs = await tabs.query({
url
});
if (etabs.length) {
if (!focus) {
return;
}
const tab = etabs.pop();
await tabs.update(tab.id, {active: true});
await windows.update(tab.windowId, {focused: true});
return;
}
const windowOptions = {
url,
type: "popup",
};
await windows.create(windowOptions);
return;
}
if (focus) {
await openInTabOrFocus(await runtime.getURL(MANAGER_URL), false);
await openInTabOrFocus(runtime.getURL(MANAGER_URL), false);
}
else {
await maybeOpenInTab(await runtime.getURL(MANAGER_URL), false);
await maybeOpenInTab(runtime.getURL(MANAGER_URL), false);
}
}

View File

@ -51,6 +51,7 @@
<label><input type="radio" name="pref-button-type" value="manager"> <span data-i18n="pref-button-type-manager"></span></label>
</div>
<hr>
<label><input type="checkbox" id="pref-manager-in-popup"> <span data-i18n="pref-manager-in-popup"></span></label>
<label><input type="checkbox" id="pref-finish-notification"> <span data-i18n="pref-finish-notification"></span></label>
<label><input type="checkbox" id="pref-sounds"> <span data-i18n="pref-sounds"></span></label>
<label><input type="checkbox" id="pref-hide-context"> <span data-i18n="pref-hide-context"></span></label>

View File

@ -554,6 +554,7 @@ addEventListener("DOMContentLoaded", async () => {
await localize(document.documentElement);
// General
new BoolPref("pref-manager-in-popup", "manager-in-popup");
new BoolPref("pref-queue-notification", "queue-notification");
new BoolPref("pref-finish-notification", "finish-notification");
new BoolPref("pref-sounds", "sounds");