Observe prefs and control webextension startup and shutdown via a pref #2397
Conversation
addon/bootstrap.js
Outdated
browser.runtime.onMessage.addListener(handleMessage); | ||
}); | ||
} else if ((! start) && webExtensionStarted) { | ||
// pass |
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.
Of course, this is where shutdown should occur
addon/bootstrap.js
Outdated
// aSubject is the nsIPrefBranch we're observing (after appropriate QI) | ||
// aData is the name of the pref that's been changed (relative to aSubject) | ||
if (aData == "userdisabled" || aData == "systemdisabled") { | ||
handleStartup(); |
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 thought about observing the Telemetry pref here, but it's not that easy – there's no way to initiate a message from bootstrap.js to the webextension. So I think the current logic for the telemetry pref is good as it is.
66d553f
to
c020dcc
Compare
addon/bootstrap.js
Outdated
Components.utils.import("resource://gre/modules/Services.jsm"); | ||
const { EmbeddedExtensionManager } = Components.utils.import("resource://gre/modules/LegacyExtensionsUtils.jsm"); | ||
|
||
const prefs = Services.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.
/home/travis/build/mozilla-services/pageshot/addon/bootstrap.js
15:15 error 'Services' is not defined no-undef
78:19 error 'Services' is not defined no-undef
Not sure if we need to tweak the ESLint envs, or just manually add another globals
to appease the ESLint gods.
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've been generous adding /* globals */
to my code
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.
@ianb: "I've been generous adding
/* globals */
to my code"
I've noticed. We can also add them to the root .eslintrc.yml file, or even add nested .eslintrc.yml files, so you don't have to shotgun a small manifesto of global vars at the top of each file.
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.
They are like pretend import statements!
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.
Ah yeah, thanks @pdehaan. Updated globals.
@ianb Would you mind giving this branch a try? It seems to be totally working for me. Cases to try out:
Then, same three cases for If this seems to be working for you as well, feel free to review now, and I'll plan to squash before merging. |
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 tested this, and systemdisabled didn't work, because of bad boolean logic per my comment. Otherwise things seemed to work well.
addon/bootstrap.js
Outdated
const ADDON_ID = "pageshot@mozilla.org"; | ||
const TELEMETRY_PREF = "toolkit.telemetry.enabled"; | ||
const USER_ENABLE_PREF = "extensions.pageshot.userdisabled"; | ||
const SYSTEM_ENABLE_PREF = "extensions.pageshot.systemdisabled"; |
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.
Well, this is my fault, but these variables have a really bad name – ENABLE when in fact they are DISABLE
addon/bootstrap.js
Outdated
prefs.getPrefType(SYSTEM_ENABLE_PREF) && | ||
prefs.getBoolPref(SYSTEM_ENABLE_PREF) | ||
); | ||
} |
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.
This is probably my fault too, but the expression here is incorrect. I think it's (! USER_ENABLE_PREF) || SYSTEM_ENABLE_PREF
– as a result setting extensions.pageshot.systemdisabled
to true forces Page Shot on rather than off.
thanks for looking! I'll fixup the logic |
4c4319f
to
a40bf2d
Compare
a7ca371
to
b28d687
Compare
@ianb Mind taking another look? Fixed up the disable check logic, did a general cleanup pass, and squashed everything into one commit. Hopefully bootstrap.js will get through Firefox review without too many problems :-P Note that I renamed the user pref to just |
For handoff to @6a68