Fix: return promise in prefs.set

This commit is contained in:
eight 2019-09-30 18:56:26 +08:00
parent 67cad1176c
commit e257ff2985
3 changed files with 10 additions and 3 deletions

View File

@ -107,7 +107,10 @@ const prefs = (() => {
specific: new Map(), specific: new Map(),
}; };
const initializing = promisify(chrome.storage.sync.get.bind(chrome.storage.sync))('settings') const syncSet = promisify(chrome.storage.sync.set.bind(chrome.storage.sync));
const syncGet = promisify(chrome.storage.sync.get.bind(chrome.storage.sync));
const initializing = syncGet('settings')
.then(result => { .then(result => {
if (result.settings) { if (result.settings) {
setAll(result.settings, true); setAll(result.settings, true);
@ -234,7 +237,7 @@ const prefs = (() => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
timer = null; timer = null;
chrome.storage.sync.set({settings: values}) syncSet({settings: values})
.then(resolve, reject); .then(resolve, reject);
}); });
}); });

View File

@ -143,6 +143,7 @@
<label> <label>
<span>Cloud drive</span> <span>Cloud drive</span>
<select class="cloud-name"> <select class="cloud-name">
<option value="none">None</option>
<option value="dropbox">Dropbox</option> <option value="dropbox">Dropbox</option>
</select> </select>
</label> </label>

View File

@ -105,6 +105,9 @@ document.onclick = e => {
connectButton.addEventListener('click', e => { connectButton.addEventListener('click', e => {
if (validClick(e)) { if (validClick(e)) {
if (cloud.value === 'none') {
return;
}
connectButton.disabled = true; connectButton.disabled = true;
cloud.disabled = true; cloud.disabled = true;
prefs.set('sync.enabled', cloud.value) prefs.set('sync.enabled', cloud.value)
@ -124,7 +127,7 @@ document.onclick = e => {
.then(() => API.syncStop()) .then(() => API.syncStop())
.catch(console.error) .catch(console.error)
.then(() => { .then(() => {
connectButton.enabled = true; connectButton.disabled = false;
}); });
} }
}); });