-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite 'Preferences' to make it async #4482
Conversation
Getting better, but it can be made simpler if you use promises to their fullest and remember that set: function preferencesSet(name, value) {
return this.initializedPromise.then(function () {
if (DEFAULT_PREFERENCES[name] === undefined) {
throw new Error('preferencesSet: \'' + name + '\' is undefined.');
} else if (value === undefined) {
throw new Error('preferencesSet: no value is specified.');
}
var valueType = typeof value;
var defaultType = typeof DEFAULT_PREFERENCES[name];
if (valueType !== defaultType) {
if (valueType === 'number' && defaultType === 'string') {
value = value.toString();
} else {
throw new Error('Preferences_set: \'' + value + '\' is a \"' +
valueType + '\", expected \"' + defaultType + '\".');
}
} else {
if (valueType === 'number' && (value | 0) !== value) {
throw new Error('Preferences_set: \'' + value +
'\' must be an \"integer\".');
}
}
this.prefs[name] = value;
return this._writeToStorage(this.prefs); // <<!! should return promise
}.bind(this));
}, |
The above is also nice since you don't have to worry about rejecting the promise and can use regular exceptions. |
@brendandahl Good points, thanks for the quick feedback! |
FirefoxCom.requestSync('setPreferences', prefObj); | ||
Preferences._writeToStorage = function (prefObj) { | ||
return new Promise(function (resolve) { | ||
FirefoxCom.requestSync('setPreferences', prefObj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make it with async "request" call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be something wrong with the request
method, I'll check if it's easy to address.
Edit: Ignore the above, I apparently missed that you have to change the methods in PdfStreamConverter.jsm
for this to work properly. Revised patch coming up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks for catching this!
@brendandahl Could you please look at this again, and see if I have managed to address all of your comments. Slightly off-topic: The main reason that prompted me to rewrite this, was actually to make it possible to easily add a pref to enable/disable WebGL (once #4286 lands). |
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 3 Live output at: http://107.21.233.14:8877/31d10bc354d18c5/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/31d10bc354d18c5/output.txt Total script time: 0.41 mins Published
|
* or every time the viewer is loaded. | ||
*/ | ||
var Preferences = { | ||
prefs: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will prefs: Object.create(DEFAULT_PREFERENCES),
be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, what's the advantage of doing that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking you would want to populate prefs with default values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way things currently are set up (this wasn't changed by this PR), is that if/when a pref doesn't exist in prefs
, it's just fetched from DEFAULT_PREFERENCES
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I was just wondering just that, {}
has meaning of the new object -- I would expect null
in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect null in this case.
That would complicate the code more, and after thinking about this I've reached the conclusion that it's probably nicer to do what you suggested initially anyway.
Looks good after the comments above addressed (and removing |
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/86e4ded51fd7f81/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/86e4ded51fd7f81/output.txt Total script time: 0.43 mins Published
|
/botio-windows preview |
From: Bot.io (Windows)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/4da7afe83358619/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/4da7afe83358619/output.txt Total script time: 0.51 mins Published
|
Looks good, thank you |
Rewrite 'Preferences' to make it async
@brendandahl and @yurydelendik Thanks to the both of you for your help with this PR! |
/cc @brendandahl Please look at this, and see if I'm on the right track with the rewrite.
This PR makes a number of changes to
Preferences
:This change is necessary if we want to support preferences for the viewer itself, and not just when opening documents. (The second commit makes use of this to add a pref that enables the hand tool by default.)
Fixes #4459.