From 7365a8bada697602f6c57bd6bbf09b697fba2146 Mon Sep 17 00:00:00 2001 From: eight Date: Mon, 25 Sep 2017 18:43:55 +0800 Subject: [PATCH] Fix: various fixes --- background/usercss-helper.js | 20 +------------------- edit/edit.js | 3 +-- install-usercss/install-usercss.js | 7 ++----- js/messaging.js | 9 +++++++++ 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/background/usercss-helper.js b/background/usercss-helper.js index 5dd09d59..eda62a50 100644 --- a/background/usercss-helper.js +++ b/background/usercss-helper.js @@ -97,28 +97,10 @@ var usercssHelper = (function () { } function openInstallPage(tabId, request) { - // FIXME: openURL doesn't reuse old page? const url = '/install-usercss.html' + '?updateUrl=' + encodeURIComponent(request.updateUrl) + '&tabId=' + tabId; - const pending = openURL({url}) - .then(tab => { - // FIXME: need a reliable way to check if a new tab is created - if (tab.url) { - chrome.runtime.onMessage.addListener(function _({method}, sender, sendResponse) { - if (method !== 'usercssInstallPageReady') { - return; - } - if (sender.tab.id !== tab.id) { - return; - } - chrome.runtime.onMessage.removeListener(_); - wrapReject(Promise.resolve(request)).then(sendResponse); - return true; - }); - } - }); - return wrapReject(pending); + return wrapReject(openURL({url})); } return {build, save, findDup, openInstallPage}; diff --git a/edit/edit.js b/edit/edit.js index 0c45ea80..a9e195bb 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1977,8 +1977,7 @@ function onRuntimeMessage(request) { case 'styleDeleted': if (styleId && styleId === request.id || editor && editor.getStyle().id === request.id) { window.onbeforeunload = () => {}; - // FIXME: Scripts may not close windows that were not opened by script. - window.close(); + closeCurrentTab(); break; } break; diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index f824bfa2..ea9ac6ef 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -21,10 +21,7 @@ break; } }); - port.onDisconnect.addListener(() => { - // FIXME: Firefox: 1) window.close doesn't work. 2) onDisconnect is fired only if the tab is closed. - window.close(); - }); + port.onDisconnect.addListener(closeCurrentTab); const cm = CodeMirror.fromTextArea($('.code textarea'), {readOnly: true}); @@ -152,7 +149,7 @@ const externalLink = makeExternalLink(); if (externalLink) { - $('.external-link').appendChild(); + $('.external-link').appendChild(externalLink); } function makeExternalLink() { diff --git a/js/messaging.js b/js/messaging.js index 52c2ef71..a51500a4 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -438,3 +438,12 @@ function openEditor(id) { openURL({url}); } } + + +function closeCurrentTab() { + chrome.tabs.getCurrent(tab => { + if (tab) { + chrome.tabs.remove(tab.id); + } + }); +}