properly update hash when closing UI

This commit is contained in:
tophf 2022-03-03 05:23:34 +03:00
parent bcc98d913b
commit 9e009726c5
2 changed files with 4 additions and 2 deletions

View File

@ -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);
},

View File

@ -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');