Observers(window, "experimental-pane-loaded"); }, async _onCheckboxChanged(event) { const target = event.target; const slug = target.dataset.nimbusSlug; const branchSlug = target.dataset.nimbusBranchSlug; const enrolling = !(ExperimentAPI.manager.store.get(slug)?.active ?? false); let shouldRestart = false; if (this._firefoxLabs.get(slug).requiresRestart) { const buttonIndex = await confirmRestartPrompt(enrolling, 1, true, false); shouldRestart = buttonIndex === CONFIRM_RESTART_PROMPT_RESTART_NOW; if (!shouldRestart) { // The user declined to restart, so we will not enroll in the opt-in. target.checked = false; return; } } // Disable the checkbox so that the user cannot interact with it during enrollment. target.disabled = true; if (enrolling) { await this._firefoxLabs.enroll(slug, branchSlug); } else { this._firefoxLabs.unenroll(slug); } target.disabled = false; if (shouldRestart) { Services.startup.quit( Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart ); } }, _onNimbusUpdate(_event, { slug, active }) { if (this._firefoxLabs.get(slug)) { document.getElementById(slug).checked = active; } }, _removeObservers() { ExperimentAPI.manager.store.off("update", this._onNimbusUpdate); Services.obs.removeObserver(this, ExperimentAPI.ENROLLMENTS_UPDATED); }, // Reset the features to their default values async _resetAllFeatures() { for (const optIn of this._firefoxLabs.all()) { const enrolled = (await ExperimentAPI.manager.store.get(optIn.slug)?.active) ?? false; if (enrolled) { this._firefoxLabs.unenroll(optIn.slug); } } }, _setCategoryVisibility(shouldHide) { document.getElementById("category-experimental").hidden = shouldHide; // Cache the visibility so we can show it quicker in subsequent loads. Services.prefs.setBoolPref( "browser.preferences.experimental.hidden", shouldHide ); if ( shouldHide && document.getElementById("categories").selectedItem?.id == "category-experimental" ) { // Leave the 'experimental' category if there are no available features gotoPref("general"); } }, observe(_subject, topic, _data) { switch (topic) { case ExperimentAPI.ENROLLMENTS_UPDATED: void this._queueRender(); } }, }; PK