Fix: various fixes

This commit is contained in:
eight 2017-09-25 18:43:55 +08:00
parent 587feb3817
commit 7365a8bada
4 changed files with 13 additions and 26 deletions

View File

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

View File

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

View File

@ -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() {

View File

@ -438,3 +438,12 @@ function openEditor(id) {
openURL({url});
}
}
function closeCurrentTab() {
chrome.tabs.getCurrent(tab => {
if (tab) {
chrome.tabs.remove(tab.id);
}
});
}