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) { function openInstallPage(tabId, request) {
// FIXME: openURL doesn't reuse old page?
const url = '/install-usercss.html' + const url = '/install-usercss.html' +
'?updateUrl=' + encodeURIComponent(request.updateUrl) + '?updateUrl=' + encodeURIComponent(request.updateUrl) +
'&tabId=' + tabId; '&tabId=' + tabId;
const pending = openURL({url}) return wrapReject(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 {build, save, findDup, openInstallPage}; return {build, save, findDup, openInstallPage};

View File

@ -1977,8 +1977,7 @@ function onRuntimeMessage(request) {
case 'styleDeleted': case 'styleDeleted':
if (styleId && styleId === request.id || editor && editor.getStyle().id === request.id) { if (styleId && styleId === request.id || editor && editor.getStyle().id === request.id) {
window.onbeforeunload = () => {}; window.onbeforeunload = () => {};
// FIXME: Scripts may not close windows that were not opened by script. closeCurrentTab();
window.close();
break; break;
} }
break; break;

View File

@ -21,10 +21,7 @@
break; break;
} }
}); });
port.onDisconnect.addListener(() => { port.onDisconnect.addListener(closeCurrentTab);
// FIXME: Firefox: 1) window.close doesn't work. 2) onDisconnect is fired only if the tab is closed.
window.close();
});
const cm = CodeMirror.fromTextArea($('.code textarea'), {readOnly: true}); const cm = CodeMirror.fromTextArea($('.code textarea'), {readOnly: true});
@ -152,7 +149,7 @@
const externalLink = makeExternalLink(); const externalLink = makeExternalLink();
if (externalLink) { if (externalLink) {
$('.external-link').appendChild(); $('.external-link').appendChild(externalLink);
} }
function makeExternalLink() { function makeExternalLink() {

View File

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