Generate the default_preferences.json file from AppOptions

Currently any editing of the preferences require updates in *three* separate files, which isn't a great developer experience to say the least.

This has annoyed me sufficiently to write this patch, which moves the definition of all preferences into `AppOptions` and adds a new `gulp` task to generate the `default_preferences.json` file for the builds where it's needed.
This commit is contained in:
Jonas Jenwald 2019-02-13 14:00:23 +01:00
parent 81f5835cd7
commit 0f0650f426
6 changed files with 141 additions and 74 deletions

View file

@ -18,20 +18,25 @@ function getDefaultPreferences() {
if (!defaultPreferences) {
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
defaultPreferences = Promise.resolve(
PDFJSDev.json('$ROOT/web/default_preferences.json'));
PDFJSDev.json('$ROOT/build/default_preferences.json'));
} else {
defaultPreferences = new Promise(function (resolve) {
let xhr = new XMLHttpRequest();
xhr.open('GET', 'default_preferences.json');
xhr.onload = xhr.onerror = function loaded() {
defaultPreferences = new Promise(function(resolve, reject) {
if (typeof SystemJS === 'object') {
SystemJS.import('./app_options').then(resolve, reject);
} else if (typeof require === 'function') {
try {
resolve(JSON.parse(xhr.responseText));
} catch (e) {
console.error(`Unable to load default preferences: ${e}`);
resolve({});
resolve(require('./app_options.js'));
} catch (ex) {
reject(ex);
}
};
xhr.send();
} else {
reject(new Error(
'SystemJS or CommonJS must be used to load AppOptions.'));
}
}).then(function({ AppOptions, OptionKind, }) {
return AppOptions.getAll(OptionKind.PREFERENCE);
}, function(reason) {
console.error(reason);
});
}
}