Add: better relog message in options page
This commit is contained in:
parent
0c0240e26d
commit
cef9fd7188
|
@ -1141,6 +1141,9 @@
|
||||||
"optionsSyncStatusDisconnected": {
|
"optionsSyncStatusDisconnected": {
|
||||||
"message": "Disconnected"
|
"message": "Disconnected"
|
||||||
},
|
},
|
||||||
|
"optionsSyncStatusRelogin": {
|
||||||
|
"message": "Session is expired. Please login again."
|
||||||
|
},
|
||||||
"paginationCurrent": {
|
"paginationCurrent": {
|
||||||
"message": "Current page",
|
"message": "Current page",
|
||||||
"description": "Tooltip for the current page index in search results"
|
"description": "Tooltip for the current page index in search results"
|
||||||
|
|
|
@ -88,6 +88,7 @@ const syncMan = (() => {
|
||||||
async start(name, fromPref = false) {
|
async start(name, fromPref = false) {
|
||||||
if (ready.then) await ready;
|
if (ready.then) await ready;
|
||||||
if (!ctrl) await initController();
|
if (!ctrl) await initController();
|
||||||
|
|
||||||
if (currentDrive) return;
|
if (currentDrive) return;
|
||||||
currentDrive = getDrive(name);
|
currentDrive = getDrive(name);
|
||||||
ctrl.use(currentDrive);
|
ctrl.use(currentDrive);
|
||||||
|
@ -96,7 +97,9 @@ const syncMan = (() => {
|
||||||
status.currentDriveName = currentDrive.name;
|
status.currentDriveName = currentDrive.name;
|
||||||
emitStatusChange();
|
emitStatusChange();
|
||||||
|
|
||||||
if (!fromPref) {
|
if (fromPref) {
|
||||||
|
status.login = true;
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
await syncMan.login(name);
|
await syncMan.login(name);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -108,6 +111,8 @@ const syncMan = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await ctrl.init();
|
||||||
|
|
||||||
await syncMan.syncNow(name);
|
await syncMan.syncNow(name);
|
||||||
prefs.set('sync.enabled', name);
|
prefs.set('sync.enabled', name);
|
||||||
status.state = STATES.connected;
|
status.state = STATES.connected;
|
||||||
|
@ -136,9 +141,11 @@ const syncMan = (() => {
|
||||||
|
|
||||||
async syncNow() {
|
async syncNow() {
|
||||||
if (ready.then) await ready;
|
if (ready.then) await ready;
|
||||||
if (!currentDrive || !status.login) throw new Error('cannot sync when disconnected');
|
if (!currentDrive || !status.login) {
|
||||||
|
console.warn('cannot sync when disconnected');
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await ctrl.init();
|
|
||||||
await ctrl.syncNow();
|
await ctrl.syncNow();
|
||||||
status.errorMessage = null;
|
status.errorMessage = null;
|
||||||
lastError = null;
|
lastError = null;
|
||||||
|
@ -198,20 +205,22 @@ const syncMan = (() => {
|
||||||
function emitStatusChange() {
|
function emitStatusChange() {
|
||||||
msg.broadcastExtension({method: 'syncStatusUpdate', status});
|
msg.broadcastExtension({method: 'syncStatusUpdate', status});
|
||||||
|
|
||||||
if (status.state !== STATES.connected || !lastError || isNetworkError(lastError)) {
|
if (status.state !== STATES.connected) {
|
||||||
iconMan.overrideBadge({});
|
iconMan.overrideBadge({});
|
||||||
} else if (isGrantError(lastError)) {
|
} else if (!status.login) {
|
||||||
iconMan.overrideBadge({
|
iconMan.overrideBadge({
|
||||||
text: 'x',
|
text: 'x',
|
||||||
color: '#F00',
|
color: '#F00',
|
||||||
title: chrome.i18n.getMessage('syncErrorRelogin'),
|
title: chrome.i18n.getMessage('syncErrorRelogin'),
|
||||||
});
|
});
|
||||||
} else {
|
} else if (lastError && !isNetworkError(lastError)) {
|
||||||
iconMan.overrideBadge({
|
iconMan.overrideBadge({
|
||||||
text: 'x',
|
text: 'x',
|
||||||
color: '#F00',
|
color: '#F00',
|
||||||
title: chrome.i18n.getMessage('syncError'),
|
title: chrome.i18n.getMessage('syncError'),
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
iconMan.overrideBadge({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ document.onclick = e => {
|
||||||
[elCloud, isDisconnected],
|
[elCloud, isDisconnected],
|
||||||
[elStart, isDisconnected && elCloud.value !== 'none'],
|
[elStart, isDisconnected && elCloud.value !== 'none'],
|
||||||
[elStop, isConnected && !status.syncing],
|
[elStop, isConnected && !status.syncing],
|
||||||
[elSyncNow, isConnected && !status.syncing],
|
[elSyncNow, isConnected && !status.syncing && status.login],
|
||||||
]) {
|
]) {
|
||||||
el.disabled = !enable;
|
el.disabled = !enable;
|
||||||
}
|
}
|
||||||
|
@ -156,19 +156,22 @@ document.onclick = e => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatusText() {
|
function getStatusText() {
|
||||||
let res;
|
|
||||||
if (status.syncing) {
|
if (status.syncing) {
|
||||||
const {phase, loaded, total} = status.progress || {};
|
const {phase, loaded, total} = status.progress || {};
|
||||||
res = phase
|
return phase
|
||||||
? t(`optionsSyncStatus${capitalize(phase)}`, [loaded + 1, total], false) ||
|
? t(`optionsSyncStatus${capitalize(phase)}`, [loaded + 1, total], false) ||
|
||||||
`${phase} ${loaded} / ${total}`
|
`${phase} ${loaded} / ${total}`
|
||||||
: t('optionsSyncStatusSyncing');
|
: t('optionsSyncStatusSyncing');
|
||||||
} else {
|
|
||||||
const {state, errorMessage, STATES} = status;
|
|
||||||
res = (state === STATES.connected || state === STATES.disconnected) && errorMessage ||
|
|
||||||
t(`optionsSyncStatus${capitalize(state)}`, null, false) || state;
|
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
const {state, errorMessage, STATES} = status;
|
||||||
|
if (errorMessage && (state === STATES.connected || state === STATES.disconnected)) {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
if (state === STATES.connected && !status.login) {
|
||||||
|
return t('optionsSyncStatusRelogin');
|
||||||
|
}
|
||||||
|
return t(`optionsSyncStatus${capitalize(state)}`, null, false) || state;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user