mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 13:59:59 +02:00
Merge branch 'main' into cycle-to-last-selected-workspace-tab
This commit is contained in:
commit
7bfeaefb27
2 changed files with 86 additions and 7 deletions
|
@ -36,8 +36,9 @@ var gZenThemeImporter = new (class {
|
||||||
constructor() {
|
constructor() {
|
||||||
console.info('ZenThemeImporter: Initiating Zen theme importer');
|
console.info('ZenThemeImporter: Initiating Zen theme importer');
|
||||||
try {
|
try {
|
||||||
window.SessionStore.promiseInitialized.then(() => {
|
window.SessionStore.promiseInitialized.then(async () => {
|
||||||
this.insertStylesheet();
|
this.insertStylesheet();
|
||||||
|
await this.writeToDom();
|
||||||
});
|
});
|
||||||
console.info('ZenThemeImporter: Zen theme imported');
|
console.info('ZenThemeImporter: Zen theme imported');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -108,9 +109,68 @@ var gZenThemeImporter = new (class {
|
||||||
async updateStylesheet() {
|
async updateStylesheet() {
|
||||||
this.removeStylesheet();
|
this.removeStylesheet();
|
||||||
await this.writeStylesheet();
|
await this.writeStylesheet();
|
||||||
|
await this.writeToDom();
|
||||||
this.insertStylesheet();
|
this.insertStylesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getBrowser() {
|
||||||
|
if (!this.__browser) {
|
||||||
|
this.__browser = Services.wm.getMostRecentWindow("navigator:browser")
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.__browser
|
||||||
|
}
|
||||||
|
|
||||||
|
async _getThemePreferences(theme) {
|
||||||
|
const themePath = PathUtils.join(this.getThemeFolder(theme), 'preferences.json');
|
||||||
|
|
||||||
|
if (!(await IOUtils.exists(themePath)) || !theme.preferences) {
|
||||||
|
return { preferences: [], isLegacyMode: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
let preferences = await IOUtils.readJSON(themePath);
|
||||||
|
|
||||||
|
// skip transformation, we won't be writing old preferences to dom, all of them can only be checkboxes
|
||||||
|
if (typeof preferences === "object" && !Array.isArray(preferences)) {
|
||||||
|
return { preferences: [], areOldPreferences: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { preferences, areOldPreferences: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeToDom() {
|
||||||
|
const browser = this._getBrowser()
|
||||||
|
|
||||||
|
for (const theme of Object.values(await this.getThemes())) {
|
||||||
|
const { preferences, areOldPreferences } = await this._getThemePreferences(theme);
|
||||||
|
|
||||||
|
if (areOldPreferences) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const themePreferences = preferences.filter(({ type }) => type === "dropdown")
|
||||||
|
|
||||||
|
for (const { property } of themePreferences) {
|
||||||
|
const value = Services.prefs.getStringPref(property, "")
|
||||||
|
|
||||||
|
if (value !== "") {
|
||||||
|
let element = browser.document.getElementById(theme.name)
|
||||||
|
|
||||||
|
if (!element) {
|
||||||
|
element = browser.document.createElement("div")
|
||||||
|
|
||||||
|
element.style.display = "none"
|
||||||
|
element.setAttribute("id", theme.name)
|
||||||
|
|
||||||
|
browser.document.body.appendChild(element)
|
||||||
|
}
|
||||||
|
|
||||||
|
element.setAttribute(property, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async writeStylesheet() {
|
async writeStylesheet() {
|
||||||
const themes = [];
|
const themes = [];
|
||||||
this._themes = null;
|
this._themes = null;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
var ZenWorkspaces = {
|
var ZenWorkspaces = {
|
||||||
/**
|
/**
|
||||||
* Stores workspace IDs and their last selected tabs.
|
* Stores workspace IDs and their last selected tabs.
|
||||||
|
@ -100,14 +101,12 @@ var ZenWorkspaces = {
|
||||||
if (tabs.length === 1) {
|
if (tabs.length === 1) {
|
||||||
this._createNewTabForWorkspace({ uuid: workspaceID });
|
this._createNewTabForWorkspace({ uuid: workspaceID });
|
||||||
// We still need to close other tabs in the workspace
|
// We still need to close other tabs in the workspace
|
||||||
this.changeWorkspace({ uuid: workspaceID });
|
this.changeWorkspace({ uuid: workspaceID }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Convert all the icons to just the first character, just in case someone
|
_kIcons: JSON.parse(Services.prefs.getStringPref("zen.workspaces.icons")).map((icon) => icon),
|
||||||
// decides to use a string with more than one character
|
|
||||||
_kIcons: JSON.parse(Services.prefs.getStringPref('zen.workspaces.icons')).map((icon) => icon[0]),
|
|
||||||
|
|
||||||
_initializeWorkspaceCreationIcons() {
|
_initializeWorkspaceCreationIcons() {
|
||||||
let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container');
|
let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container');
|
||||||
|
@ -475,10 +474,15 @@ var ZenWorkspaces = {
|
||||||
button.removeAttribute('disabled');
|
button.removeAttribute('disabled');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get _shouldAllowPinTab() {
|
||||||
|
return Services.prefs.getBoolPref('zen.workspaces.individual-pinned-tabs');
|
||||||
|
},
|
||||||
|
|
||||||
async changeWorkspace(window, onInit = false) {
|
async changeWorkspace(window, onInit = false) {
|
||||||
if (!this.workspaceEnabled) {
|
if (!this.workspaceEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const shouldAllowPinnedTabs = this._shouldAllowPinTab;
|
||||||
let firstTab = undefined;
|
let firstTab = undefined;
|
||||||
let workspaces = await this._workspaces();
|
let workspaces = await this._workspaces();
|
||||||
for (let workspace of workspaces.workspaces) {
|
for (let workspace of workspaces.workspaces) {
|
||||||
|
@ -487,7 +491,7 @@ var ZenWorkspaces = {
|
||||||
this.unsafeSaveWorkspaces(workspaces);
|
this.unsafeSaveWorkspaces(workspaces);
|
||||||
console.info('ZenWorkspaces: Changing workspace to', window.uuid);
|
console.info('ZenWorkspaces: Changing workspace to', window.uuid);
|
||||||
for (let tab of gBrowser.tabs) {
|
for (let tab of gBrowser.tabs) {
|
||||||
if ((tab.getAttribute('zen-workspace-id') === window.uuid && !tab.pinned) || !tab.hasAttribute('zen-workspace-id')) {
|
if ((tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) || !tab.hasAttribute('zen-workspace-id')) {
|
||||||
if (!firstTab) {
|
if (!firstTab) {
|
||||||
firstTab = tab;
|
firstTab = tab;
|
||||||
} else if (gBrowser.selectedTab === tab) {
|
} else if (gBrowser.selectedTab === tab) {
|
||||||
|
@ -510,7 +514,9 @@ var ZenWorkspaces = {
|
||||||
}
|
}
|
||||||
for (let tab of gBrowser.tabs) {
|
for (let tab of gBrowser.tabs) {
|
||||||
if (tab.getAttribute('zen-workspace-id') !== window.uuid) {
|
if (tab.getAttribute('zen-workspace-id') !== window.uuid) {
|
||||||
gBrowser.hideTab(tab);
|
// FOR UNLOADING TABS:
|
||||||
|
// gBrowser.discardBrowser(tab, true);
|
||||||
|
gBrowser.hideTab(tab, undefined, shouldAllowPinnedTabs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.documentElement.setAttribute('zen-workspace-id', window.uuid);
|
document.documentElement.setAttribute('zen-workspace-id', window.uuid);
|
||||||
|
@ -518,6 +524,8 @@ var ZenWorkspaces = {
|
||||||
await this._updateWorkspacesButton();
|
await this._updateWorkspacesButton();
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
await this._updateWorkspacesChangeContextMenu();
|
await this._updateWorkspacesChangeContextMenu();
|
||||||
|
|
||||||
|
document.getElementById('tabbrowser-tabs')._positionPinnedTabs();
|
||||||
},
|
},
|
||||||
|
|
||||||
async _updateWorkspacesChangeContextMenu() {
|
async _updateWorkspacesChangeContextMenu() {
|
||||||
|
@ -695,6 +703,17 @@ var ZenWorkspaces = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Tab browser utilities
|
// Tab browser utilities
|
||||||
|
createContainerTabMenu(event) {
|
||||||
|
let window = event.target.ownerGlobal;
|
||||||
|
const workspace = this._workspaceCache.workspaces.find((workspace) => this._contextMenuId === workspace.uuid);
|
||||||
|
let containerTabId = workspace.containerTabId;
|
||||||
|
return window.createUserContextMenu(event, {
|
||||||
|
isContextMenu: true,
|
||||||
|
excludeUserContextId: containerTabId,
|
||||||
|
showDefaultTab: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getContextIdIfNeeded(userContextId) {
|
getContextIdIfNeeded(userContextId) {
|
||||||
if (typeof userContextId !== 'undefined' || !this.workspaceEnabled) {
|
if (typeof userContextId !== 'undefined' || !this.workspaceEnabled) {
|
||||||
return [userContextId, false];
|
return [userContextId, false];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue