let result = await super.getUpdateComplete();
await this.#initPromise;
return result;
}
async init() {
if (this.initialized) {
return;
}
document.addEventListener("LaunchProfile", this);
document.addEventListener("CreateProfile", this);
document.addEventListener("DeleteProfile", this);
this.selectableProfileService = SelectableProfileService;
await this.selectableProfileService.init();
await this.selectableProfileService.maybeSetupDataStore();
this.profiles = await this.selectableProfileService.getAllProfiles();
this.showSelector =
this.selectableProfileService.groupToolkitProfile.showProfileSelector;
if (!this.profiles.length) {
await this.selectableProfileService.setShowProfileSelectorWindow(false);
}
this.initialized = true;
this.#initPromise = null;
if (this.isStartupUI) {
window.addEventListener("unload", () => {
// In case the user closed the window manually.
this.selectableProfileService.uninit();
});
}
}
handleCheckboxToggle() {
this.showSelector = this.checkbox.checked;
let state = this.showSelector ? "enabled" : "disabled";
Glean.profilesSelectorWindow.showAtStartup.record({ value: state });
this.selectableProfileService.setShowProfileSelectorWindow(
this.showSelector
);
}
async launchProfile(profile, url) {
if (this.isStartupUI) {
await this.setLaunchArguments(profile, url ? ["-url", url] : []);
await this.selectableProfileService.uninit();
} else {
this.selectableProfileService.launchInstance(profile, url ? [url] : []);
}
window.close();
}
async handleEvent(event) {
switch (event.type) {
case "LaunchProfile": {
Glean.profilesSelectorWindow.launch.record();
let { profile, url } = event.detail;
await this.launchProfile(profile, url);
break;
}
case "CreateProfile": {
let profile =
await this.selectableProfileService.createNewProfile(false);
await this.launchProfile(profile, "about:newprofile");
break;
}
case "DeleteProfile": {
let profile = event.detail;
await this.launchProfile(profile, "about:deleteprofile");
break;
}
}
}
render() {
if (!this.profiles) {
return null;
}
return html`