Fix: move cleanup to stop function

This commit is contained in:
eight 2019-09-28 00:44:19 +08:00
parent 58949a143d
commit 0f2de4d989

View File

@ -62,11 +62,6 @@ const sync = (() => {
function start(name) {
return (currentDrive ? stop() : Promise.resolve())
.then(() => {
if (currentDrive) {
return chromeLocal.remove(`sync/state/${currentDrive.name}`);
}
})
.then(() => {
currentDrive = getDrive(name);
ctrl.use(currentDrive);
@ -92,6 +87,14 @@ const sync = (() => {
function stop() {
chrome.alarms.clear('syncNow');
return ctrl.stop();
if (!currentDrive) {
return Promise.resolve();
}
return ctrl.stop()
.then(() => tokenManager.revokeToken(currentDrive.name))
.then(() => chromeLocal.remove(`sync/state/${currentDrive.name}`))
.then(() => {
currentDrive = null;
});
}
})();