From 9e009726c5a5cd42583f7f10ed9763b43050aa55 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 3 Mar 2022 05:23:34 +0300 Subject: [PATCH] properly update hash when closing UI --- js/router.js | 4 +++- manage/manage.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/router.js b/js/router.js index 1fd3d7dc..76aa4c70 100644 --- a/js/router.js +++ b/js/router.js @@ -11,14 +11,16 @@ const router = { return new URLSearchParams(location.search).get(key); }, + /** When showing the UI, `showHide` function must resolve only when the UI is closed */ makeToggle(hashId, showHide, deps) { const hash = '#' + hashId; - const selector = '.' + hash.slice(1); + const selector = '.' + hashId; router.watch({hash}, async state => { const el = $(selector); if (!state === !el) return; if (state && deps) await require(deps); await showHide(state, el, selector); + if (state) router.updateHash(''); }); return router.updateHash.bind(router, hash); }, diff --git a/manage/manage.js b/manage/manage.js index 90003b42..fcf9e3c2 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -108,7 +108,6 @@ newUI.renderClass(); })(); msg.onExtension(onRuntimeMessage); -window.on('closeOptions', () => router.updateHash('')); function onRuntimeMessage(msg) { switch (msg.method) { @@ -135,6 +134,7 @@ async function toggleEmbeddedOptions(show, el, selector) { if (show) { $.root.appendChild($create('iframe' + selector, {src: '/options.html'})) .focus(); + await new Promise(resolve => window.on('closeOptions', resolve, {once: true})); } else { el.contentDocument.body.classList.add('scaleout'); await animateElement(el, 'fadeout');