1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-10 05:35:29 +02:00
zen-desktop/src/browser/base/content/zen-browser-places.js
2024-04-02 21:09:35 +02:00

141 lines
3.9 KiB
JavaScript

var ZenProfileDialogUI = {
showSubView(parent, event) {
let element = parent.querySelector('.zen-side-bar-profiles-button-panel-correction') || parent;
PanelUI.showSubView('PanelUI-zen-profiles', element, event);
this._updateProfilesList();
this._updateCurentProfileId();
},
_updateProfilesList() {
let parentList = document.getElementById('PanelUI-zen-profiles-list');
this._emptyUserList(parentList);
console.log(ProfileService.profiles)
if (this._getProfilesSize(ProfileService.profiles) <= 1) {
return;
}
parentList.appendChild(document.createElement('toolbarseparator'));
for (let profile of ProfileService.profiles) {
if (profile == ProfileService.currentProfile) {
continue;
}
let item = document.createElement('menu');
item.onclick = () => this._openProfile(profile);
item.className = 'PanelUI-zen-profiles-item';
let avatar = document.createElement('img');
avatar.className = 'PanelUI-zen-profiles-item-avatar';
let name = document.createElement('div');
name.className = 'PanelUI-zen-profiles-item-name';
name.appendChild(document.createTextNode(profile.name));
name.container = true;
avatar.setAttribute('src', profile.zenAvatarPath);
item.appendChild(avatar);
item.appendChild(name);
parentList.appendChild(item);
}
},
_emptyUserList(element) {
element.innerHTML = '';
},
_updateCurentProfileId() {
let currentProfile = ProfileService.currentProfile;
let nameContainer = document.getElementById("PanelUI-zen-profiles-current-name");
nameContainer.textContent = currentProfile.name;
},
_openProfile(profile) {
Services.startup.createInstanceWithProfile(profile);
},
_getProfilesSize(profiles) {
let size = 0;
for (let _ of profiles) {
size += 1;
}
return size;
},
createProfileWizard() {
// This should be rewritten in HTML eventually.
window.browsingContext.topChromeWindow.openDialog(
"chrome://mozapps/content/profile/createProfileWizard.xhtml",
"",
"centerscreen,chrome,modal,titlebar",
ProfileService,
{ CreateProfile: async (profile) => {
try {
ProfileService.defaultProfile = profile;
this._flush();
} catch (e) {
// This can happen on dev-edition.
let [title, msg] = await document.l10n.formatValues([
{ id: "profiles-cannot-set-as-default-title" },
{ id: "profiles-cannot-set-as-default-message" },
]);
Services.prompt.alert(window, title, msg);
}
} }
);
},
async _flush() {
try {
ProfileService.flush();
this._updateProfilesList();
} catch (e) {
let [title, msg, button] = await document.l10n.formatValues([
{ id: "profiles-flush-fail-title" },
{
id:
e.result == Cr.NS_ERROR_DATABASE_CHANGED
? "profiles-flush-conflict"
: "profiles-flush-failed",
},
{ id: "profiles-flush-restart-button" },
]);
const PS = Ci.nsIPromptService;
let result = Services.prompt.confirmEx(
window,
title,
msg,
PS.BUTTON_POS_0 * PS.BUTTON_TITLE_CANCEL +
PS.BUTTON_POS_1 * PS.BUTTON_TITLE_IS_STRING,
null,
button,
null,
null,
{}
);
if (result == 1) {
this._restart(false);
}
}
},
_restart(safeMode) {
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
Ci.nsISupportsPRBool
);
Services.obs.notifyObservers(
cancelQuit,
"quit-application-requested",
"restart"
);
if (cancelQuit.data) {
return;
}
let flags = Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart;
if (safeMode) {
Services.startup.restartInSafeMode(flags);
} else {
Services.startup.quit(flags);
}
}
};