diff --git a/src/background/index.html b/src/background/index.html index 687b28b3..8cc923c4 100644 --- a/src/background/index.html +++ b/src/background/index.html @@ -6,8 +6,10 @@ - + + diff --git a/src/background/menu.js b/src/background/menu.js index a3fc630c..79cd39c6 100644 --- a/src/background/menu.js +++ b/src/background/menu.js @@ -40,10 +40,10 @@ const handleClick = async function (info) { const urls = await aggregate(info); await cast(info.menuItemId, urls); } catch (err) { - notify(err); + await notify(err); } } else if (!info.wasChecked) { - browser.storage.local.set({ + await browser.storage.local.set({ "server-active": Number.parseInt(info.menuItemId, 10), }); } diff --git a/src/background/migrate.js b/src/background/migrate.js index 3666a149..4560a517 100644 --- a/src/background/migrate.js +++ b/src/background/migrate.js @@ -2,7 +2,10 @@ * @module */ -browser.storage.local.get().then((current) => { +browser.storage.local.get().then(async (current) => { + // Vider la configuration pour enlever les éventuelles propriétés obsolètes. + await browser.storage.local.clear(); + if ("config-version" in current) { let config = current; if (1 === config["config-version"]) { @@ -14,10 +17,6 @@ browser.storage.local.get().then((current) => { .filter(([k, v]) => k.startsWith("contexts-") && v) .map(([k]) => k.slice(9)); - // Nettoyer la configuration pour garder seulement les propriétés - // nécessaire. - browser.storage.local.clear(); - config = { "config-version": 2, "server-mode": "single", @@ -46,10 +45,9 @@ browser.storage.local.get().then((current) => { config["youtube-order"] = ""; } - browser.storage.local.set(config); + await browser.storage.local.set(config); } else { - browser.storage.local.clear(); - browser.storage.local.set({ + await browser.storage.local.set({ "config-version": 4, "server-mode": "single", "server-list": [{ address: "", name: "" }], diff --git a/src/core/notify.js b/src/core/notify.js index dffa4285..18d387fd 100644 --- a/src/core/notify.js +++ b/src/core/notify.js @@ -8,14 +8,16 @@ import { PebkacError } from "./pebkac.js"; * Notifie l'utilisateur d'un message d'erreur. * * @param {PebkacError|Error} err L'erreur affichée dans la notification. + * @returns {Promise} Une promesse contenant l'identifiant de la + * notification. */ export const notify = function (err) { // Ne pas ajouter un bouton vers la configuration car cette fonctionnalité - // n'est pas encore implémentée. + // n'est pas encore implémentée dans Firefox. // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681 - browser.notifications.create({ + return browser.notifications.create({ type: "basic", - iconUrl: "img/icon.svg", + iconUrl: "/img/icon.svg", title: err instanceof PebkacError ? err.title : browser.i18n.getMessage("notifications_unknown_title"), diff --git a/test/unit/core/notify.js b/test/unit/core/notify.js index 52e59536..6964bba2 100644 --- a/test/unit/core/notify.js +++ b/test/unit/core/notify.js @@ -13,7 +13,7 @@ describe("core/notify.js", function () { assert.strictEqual(stub.callCount, 1); assert.deepStrictEqual(stub.firstCall.args, [{ type: "basic", - iconUrl: "img/icon.svg", + iconUrl: "/img/icon.svg", title: "Unknown error", message: "foo", }]); @@ -29,7 +29,7 @@ describe("core/notify.js", function () { assert.strictEqual(stub.callCount, 1); assert.deepStrictEqual(stub.firstCall.args, [{ type: "basic", - iconUrl: "img/icon.svg", + iconUrl: "/img/icon.svg", title: "Unsupported link", message: "Link foo is invalid.", }]);