mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Better handling of null values in settings
This commit is contained in:
parent
8de5b4219d
commit
adc5885980
@ -90,8 +90,8 @@ android {
|
||||
applicationId "net.cozic.joplin"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 22
|
||||
versionCode 84
|
||||
versionName "0.10.69"
|
||||
versionCode 85
|
||||
versionName "0.10.70"
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "x86"
|
||||
}
|
||||
|
@ -242,7 +242,9 @@ class Setting extends BaseModel {
|
||||
if (md.type == Setting.TYPE_BOOL) return value ? '1' : '0';
|
||||
if (md.type == Setting.TYPE_ARRAY) return value ? JSON.stringify(value) : '[]';
|
||||
if (md.type == Setting.TYPE_OBJECT) return value ? JSON.stringify(value) : '{}';
|
||||
return value;
|
||||
if (md.type == Setting.TYPE_STRING) return value ? value + '' : '';
|
||||
|
||||
throw new Error('Unhandled value type: ' + md.type);
|
||||
}
|
||||
|
||||
static formatValue(key, value) {
|
||||
@ -274,7 +276,12 @@ class Setting extends BaseModel {
|
||||
return {};
|
||||
}
|
||||
|
||||
return value;
|
||||
if (md.type === Setting.TYPE_STRING) {
|
||||
if (!value) return '';
|
||||
return value + '';
|
||||
}
|
||||
|
||||
throw new Error('Unhandled value type: ' + md.type);
|
||||
}
|
||||
|
||||
static value(key) {
|
||||
@ -283,6 +290,7 @@ class Setting extends BaseModel {
|
||||
// and object and change a key, the objects will be detected as equal. By returning a copy
|
||||
// we avoid this problem.
|
||||
function copyIfNeeded(value) {
|
||||
if (value === null || value === undefined) return value;
|
||||
if (Array.isArray(value)) return value.slice();
|
||||
if (typeof value === 'object') return Object.assign({}, value);
|
||||
return value;
|
||||
|
@ -80,7 +80,17 @@ reg.scheduleSync = async (delay = null) => {
|
||||
|
||||
const contextKey = 'sync.' + syncTargetId + '.context';
|
||||
let context = Setting.value(contextKey);
|
||||
try {
|
||||
context = context ? JSON.parse(context) : {};
|
||||
} catch (error) {
|
||||
// Clearing the context is inefficient since it means all items are going to be re-downloaded
|
||||
// however it won't result in duplicate items since the synchroniser is going to compare each
|
||||
// item to the current state.
|
||||
reg.logger().warn('Could not parse JSON sync context ' + contextKey + ':', context);
|
||||
reg.logger().info('Clearing context and starting from scratch');
|
||||
context = null;
|
||||
}
|
||||
|
||||
try {
|
||||
reg.logger().info('Starting scheduled sync');
|
||||
let newContext = await sync.start({ context: context });
|
||||
|
@ -166,7 +166,6 @@ class Synchronizer {
|
||||
let error = new Error(_('Synchronisation is already in progress. State: %s', this.state()));
|
||||
error.code = 'alreadyStarted';
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
this.state_ = 'in_progress';
|
||||
|
Loading…
Reference in New Issue
Block a user