mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
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:
parent
81f5835cd7
commit
0f0650f426
6 changed files with 141 additions and 74 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue