2018-03-29 21:21:54 +03:00
|
|
|
const {actionTypes: at} = ChromeUtils.import("resource://activity-stream/common/Actions.jsm", {});
|
2018-04-26 19:00:00 +03:00
|
|
|
const {ASRouter} = ChromeUtils.import("resource://activity-stream/lib/ASRouter.jsm", {});
|
2018-09-20 02:42:00 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
const ONBOARDING_FINISHED_PREF = "browser.onboarding.notification.finished";
|
2018-03-29 21:21:54 +03:00
|
|
|
|
|
|
|
/**
|
2018-04-26 19:00:00 +03:00
|
|
|
* @class ASRouterFeed - Connects ASRouter singleton (see above) to Activity Stream's
|
2018-03-29 21:21:54 +03:00
|
|
|
* store so that it can use the RemotePageManager.
|
|
|
|
*/
|
2018-04-26 19:00:00 +03:00
|
|
|
class ASRouterFeed {
|
2018-03-29 21:21:54 +03:00
|
|
|
constructor(options = {}) {
|
2018-04-26 19:00:00 +03:00
|
|
|
this.router = options.router || ASRouter;
|
2018-03-29 21:21:54 +03:00
|
|
|
}
|
|
|
|
|
2018-04-26 19:00:00 +03:00
|
|
|
async enable() {
|
2018-09-20 02:42:00 +03:00
|
|
|
await this.router.init(
|
|
|
|
this.store._messageChannel.channel,
|
|
|
|
this.store.dbStorage.getDbTable("snippets"),
|
|
|
|
this.store.dispatch
|
|
|
|
);
|
|
|
|
// Disable onboarding
|
|
|
|
Services.prefs.setBoolPref(ONBOARDING_FINISHED_PREF, true);
|
2018-03-29 21:21:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
|
|
|
if (this.router.initialized) {
|
|
|
|
this.router.uninit();
|
2018-09-20 02:42:00 +03:00
|
|
|
// Re-enable onboarding
|
|
|
|
Services.prefs.setBoolPref(ONBOARDING_FINISHED_PREF, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enableOrDisableBasedOnPref - Check the experiment pref
|
|
|
|
* (asrouterExperimentEnabled) and enable or disable ASRouter based on
|
|
|
|
* its value.
|
|
|
|
*/
|
|
|
|
enableOrDisableBasedOnPref() {
|
|
|
|
const prefs = this.store.getState().Prefs.values;
|
|
|
|
const isExperimentEnabled = prefs.asrouterExperimentEnabled;
|
|
|
|
if (!this.router.initialized && isExperimentEnabled) {
|
|
|
|
this.enable();
|
|
|
|
} else if (!isExperimentEnabled && this.router.initialized) {
|
|
|
|
this.disable();
|
2018-03-29 21:21:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onAction(action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case at.INIT:
|
2018-09-20 02:42:00 +03:00
|
|
|
this.enableOrDisableBasedOnPref();
|
|
|
|
break;
|
|
|
|
case at.PREF_CHANGED:
|
|
|
|
if (action.data.name === "asrouterExperimentEnabled") {
|
|
|
|
this.enableOrDisableBasedOnPref();
|
|
|
|
}
|
2018-07-12 19:24:24 +03:00
|
|
|
break;
|
2018-03-29 21:21:54 +03:00
|
|
|
case at.UNINIT:
|
|
|
|
this.disable();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-26 19:00:00 +03:00
|
|
|
this.ASRouterFeed = ASRouterFeed;
|
2018-03-29 21:21:54 +03:00
|
|
|
|
2018-04-26 19:00:00 +03:00
|
|
|
const EXPORTED_SYMBOLS = ["ASRouterFeed"];
|