Add: close source tab after install
This commit is contained in:
parent
c0514a6699
commit
f194155830
|
@ -1,6 +1,6 @@
|
||||||
/* global dbExec, getStyles, saveStyle */
|
/* global dbExec, getStyles, saveStyle */
|
||||||
/* global handleCssTransitionBug */
|
/* global handleCssTransitionBug */
|
||||||
/* global usercssHelper */
|
/* global usercssHelper openEditor */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
|
@ -334,9 +334,36 @@ function onRuntimeMessage(request, sender, sendResponse) {
|
||||||
case 'initUsercssInstallPage':
|
case 'initUsercssInstallPage':
|
||||||
usercssHelper.initInstallPage(sender.tab.id, request).then(sendResponse);
|
usercssHelper.initInstallPage(sender.tab.id, request).then(sendResponse);
|
||||||
return KEEP_CHANNEL_OPEN;
|
return KEEP_CHANNEL_OPEN;
|
||||||
|
|
||||||
|
case 'closeTab':
|
||||||
|
closeTab(sender.tab.id, request).then(sendResponse);
|
||||||
|
return KEEP_CHANNEL_OPEN;
|
||||||
|
|
||||||
|
case 'openEditor':
|
||||||
|
openEditor(request.id);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeTab(tabId, request) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (request.tabId) {
|
||||||
|
tabId = request.tabId;
|
||||||
|
}
|
||||||
|
chrome.tabs.remove(tabId, () => {
|
||||||
|
const {lastError} = chrome.runtime;
|
||||||
|
if (lastError) {
|
||||||
|
resolve({
|
||||||
|
status: 'error',
|
||||||
|
error: lastError.message || String(lastError)
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve({status: 'success'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function injectContent(tabId, {files}) {
|
function injectContent(tabId, {files}) {
|
||||||
return Promise.all(files.map(inject))
|
return Promise.all(files.map(inject))
|
||||||
.then(() => ({status: 'success'}))
|
.then(() => ({status: 'success'}))
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/* global LZString */
|
/* global LZString */
|
||||||
/* global openEditor */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -457,10 +456,6 @@ function saveStyle(style) {
|
||||||
style, codeIsUpdated, reason,
|
style, codeIsUpdated, reason,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (style.usercssData && !existed && reason === 'update') {
|
|
||||||
// open the editor for usercss with the first install?
|
|
||||||
openEditor(style.id);
|
|
||||||
}
|
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,14 @@ function initUsercssInstall() {
|
||||||
case 'liveReloadStop':
|
case 'liveReloadStop':
|
||||||
watcher.stop();
|
watcher.stop();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'closeTab':
|
||||||
|
if (history.length > 1) {
|
||||||
|
history.back();
|
||||||
|
} else {
|
||||||
|
runtimeSend({method: 'closeTab'});
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -184,6 +184,12 @@
|
||||||
|
|
||||||
updateMeta(result);
|
updateMeta(result);
|
||||||
|
|
||||||
|
runtimeSend({method: 'openEditor', id: result.id});
|
||||||
|
|
||||||
|
if (!liveReload) {
|
||||||
|
port.postMessage({method: 'closeTab'});
|
||||||
|
}
|
||||||
|
|
||||||
window.dispatchEvent(new CustomEvent('installed'));
|
window.dispatchEvent(new CustomEvent('installed'));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user