1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Minor CLI bug fixes and improvements

This commit is contained in:
Laurent Cozic
2017-07-26 22:07:27 +01:00
parent 76a9264239
commit 89f1d5e6e7
10 changed files with 113 additions and 38 deletions

View File

@@ -134,7 +134,12 @@ class Setting extends BaseModel {
const md = this.settingMetadata(key);
if (md.type == Setting.TYPE_INT) return Math.floor(Number(value));
if (md.type == Setting.TYPE_BOOL) {
if (typeof value === 'string') value = Number(value);
if (typeof value === 'string') {
value = value.toLowerCase();
if (value === 'true') return true;
if (value === 'false') return false;
value = Number(value);
}
return !!value;
}
return value;

View File

@@ -236,7 +236,10 @@ class OneDriveApi {
}
async refreshAccessToken() {
if (!this.auth_) throw new Error('Cannot refresh token: authentication data is missing');
if (!this.auth_ || !this.auth_.refresh_token) {
this.setAuth(null);
throw new Error('Cannot refresh token: authentication data is missing');
}
let body = new shim.FormData();
body.append('client_id', this.clientId());

View File

@@ -97,7 +97,7 @@ reg.synchronizer = async (syncTargetId) => {
return sync;
}
reg.syncHasAuth = async (syncTargetId) => {
reg.syncHasAuth = (syncTargetId) => {
if (syncTargetId == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
return false;
}
@@ -121,7 +121,7 @@ reg.scheduleSync = async (delay = null) => {
const syncTargetId = Setting.value('sync.target');
if (!reg.syncHasAuth()) {
if (!reg.syncHasAuth(syncTargetId)) {
reg.logger().info('Synchronizer is missing credentials - manual sync required to authenticate.');
return;
}
@@ -135,7 +135,7 @@ reg.scheduleSync = async (delay = null) => {
Setting.setValue('sync.context', JSON.stringify(newContext));
} catch (error) {
if (error.code == 'alreadyStarted') {
reg.logger.info(error.message);
reg.logger().info(error.message);
} else {
throw error;
}
@@ -152,8 +152,9 @@ reg.scheduleSync = async (delay = null) => {
}
reg.syncStarted = async () => {
if (!reg.syncHasAuth()) return false;
const sync = await reg.synchronizer(Setting.value('sync.target'));
const syncTarget = Setting.value('sync.target');
if (!reg.syncHasAuth(syncTarget)) return false;
const sync = await reg.synchronizer(syncTarget);
return sync.state() != 'idle';
}