mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 00:59:57 +02:00
Merge branch 'main' into fix/change-tab-workspace-duplicates
This commit is contained in:
commit
4fc5d9df94
9 changed files with 686 additions and 1109 deletions
|
@ -3,349 +3,174 @@ const kZKSActions = {
|
|||
// otherwise "oncommand=" will be added.
|
||||
|
||||
// Split view actions
|
||||
zenSplitViewGrid: [
|
||||
"gZenViewSplitter.toggleShortcut('grid')",
|
||||
"zen-split-view-grid",
|
||||
"split-view-action",
|
||||
],
|
||||
zenSplitViewVertical: [
|
||||
"gZenViewSplitter.toggleShortcut('vsep')",
|
||||
"zen-split-view-vertical",
|
||||
"split-view-action",
|
||||
],
|
||||
zenSplitViewHorizontal: [
|
||||
"gZenViewSplitter.toggleShortcut('hsep')",
|
||||
"zen-split-view-horizontal",
|
||||
"split-view-action",
|
||||
],
|
||||
zenSplitViewClose: [
|
||||
"gZenViewSplitter.toggleShortcut('unsplit')",
|
||||
"zen-split-view-close",
|
||||
"split-view-action",
|
||||
],
|
||||
zenSplitViewGrid: ["gZenViewSplitter.toggleShortcut('grid')", 'zen-split-view-grid', 'split-view-action'],
|
||||
zenSplitViewVertical: ["gZenViewSplitter.toggleShortcut('vsep')", 'zen-split-view-vertical', 'split-view-action'],
|
||||
zenSplitViewHorizontal: ["gZenViewSplitter.toggleShortcut('hsep')", 'zen-split-view-horizontal', 'split-view-action'],
|
||||
zenSplitViewClose: ["gZenViewSplitter.toggleShortcut('unsplit')", 'zen-split-view-close', 'split-view-action'],
|
||||
|
||||
// Workspace actions
|
||||
zenChangeWorkspace: [
|
||||
"ZenWorkspaces.changeWorkspaceShortcut()",
|
||||
"zen-change-workspace",
|
||||
"workspace-action",
|
||||
],
|
||||
zenChangeWorkspace: ['ZenWorkspaces.changeWorkspaceShortcut()', 'zen-change-workspace', 'workspace-action'],
|
||||
|
||||
// manage actions
|
||||
openNewTab: [
|
||||
"command:cmd_newNavigatorTabNoEvent",
|
||||
"open-new-tab",
|
||||
"tab-action",
|
||||
],
|
||||
duplicateTab: [
|
||||
"duplicateTabIn(gBrowser.selectedTab, 'tab')",
|
||||
"duplicate-tab",
|
||||
"tab-action",
|
||||
],
|
||||
closeTab: ["command:cmd_close", "close-tab", "tab-action"],
|
||||
openNewWindow: ["command:cmd_newNavigator", "open-new-window", "tab-action"],
|
||||
openNewPrivateWindow: [
|
||||
"command:Tools:PrivateBrowsing",
|
||||
"open-new-private-window",
|
||||
"tab-action",
|
||||
],
|
||||
closeWindow: ["command:cmd_closeWindow", "close-window", "tab-action"],
|
||||
restoreLastTab: ["undoCloseTab()", "restore-last-session", "tab-action"],
|
||||
restoreLastWindow: [
|
||||
"command:History:UndoCloseWindow",
|
||||
"restore-last-window",
|
||||
"tab-action",
|
||||
],
|
||||
showNextTab: [
|
||||
"gBrowser.tabContainer.advanceSelectedTab(1, true)",
|
||||
"show-next-tab",
|
||||
"tab-action",
|
||||
],
|
||||
showPreviousTab: [
|
||||
"gBrowser.tabContainer.advanceSelectedTab(-1, true)",
|
||||
"show-previous-tab",
|
||||
"tab-action",
|
||||
],
|
||||
showAllTabsPanel: [
|
||||
"gTabsPanel.showAllTabsPanel()",
|
||||
"show-all-tabs-panel",
|
||||
"tab-action",
|
||||
],
|
||||
openNewTab: ['command:cmd_newNavigatorTabNoEvent', 'open-new-tab', 'tab-action'],
|
||||
duplicateTab: ["duplicateTabIn(gBrowser.selectedTab, 'tab')", 'duplicate-tab', 'tab-action'],
|
||||
closeTab: ['command:cmd_close', 'close-tab', 'tab-action'],
|
||||
openNewWindow: ['command:cmd_newNavigator', 'open-new-window', 'tab-action'],
|
||||
openNewPrivateWindow: ['command:Tools:PrivateBrowsing', 'open-new-private-window', 'tab-action'],
|
||||
closeWindow: ['command:cmd_closeWindow', 'close-window', 'tab-action'],
|
||||
restoreLastTab: ['undoCloseTab()', 'restore-last-session', 'tab-action'],
|
||||
restoreLastWindow: ['command:History:UndoCloseWindow', 'restore-last-window', 'tab-action'],
|
||||
showNextTab: ['gBrowser.tabContainer.advanceSelectedTab(1, true)', 'show-next-tab', 'tab-action'],
|
||||
showPreviousTab: ['gBrowser.tabContainer.advanceSelectedTab(-1, true)', 'show-previous-tab', 'tab-action'],
|
||||
showAllTabsPanel: ['gTabsPanel.showAllTabsPanel()', 'show-all-tabs-panel', 'tab-action'],
|
||||
|
||||
// Compact mode actions
|
||||
zenToggleCompactMode: [
|
||||
"gZenCompactModeManager.toggle()",
|
||||
"zen-toggle-compact-mode",
|
||||
"compact-mode-action",
|
||||
],
|
||||
zenToggleCompactMode: ['gZenCompactModeManager.toggle()', 'zen-toggle-compact-mode', 'compact-mode-action'],
|
||||
zenToggleCompactModeSidebar: [
|
||||
"gZenCompactModeManager.toggleSidebar()",
|
||||
"zen-toggle-compact-mode-sidebar",
|
||||
"compact-mode-action",
|
||||
'gZenCompactModeManager.toggleSidebar()',
|
||||
'zen-toggle-compact-mode-sidebar',
|
||||
'compact-mode-action',
|
||||
],
|
||||
zenToggleCompactModeToolbar: [
|
||||
"gZenCompactModeManager.toggleToolbar()",
|
||||
"zen-toggle-compact-mode-toolbar",
|
||||
"compact-mode-action",
|
||||
'gZenCompactModeManager.toggleToolbar()',
|
||||
'zen-toggle-compact-mode-toolbar',
|
||||
'compact-mode-action',
|
||||
],
|
||||
|
||||
// Page actions
|
||||
sendWithMail: ["command:Browser:SendLink", "send-with-mail", "page-action"],
|
||||
savePage: ["command:Browser:SavePage", "save-page", "page-action"],
|
||||
printPage: ["command:cmd_print", "print-page", "page-action"],
|
||||
muteCurrentTab: ["command:cmd_toggleMute", "mute-current-tab", "page-action"],
|
||||
showSourceOfPage: [
|
||||
"command:View:PageSource",
|
||||
"show-source-of-page",
|
||||
"page-action",
|
||||
],
|
||||
showPageInfo: ["command:View:PageInfo", "show-page-info", "page-action"],
|
||||
sendWithMail: ['command:Browser:SendLink', 'send-with-mail', 'page-action'],
|
||||
savePage: ['command:Browser:SavePage', 'save-page', 'page-action'],
|
||||
printPage: ['command:cmd_print', 'print-page', 'page-action'],
|
||||
muteCurrentTab: ['command:cmd_toggleMute', 'mute-current-tab', 'page-action'],
|
||||
showSourceOfPage: ['command:View:PageSource', 'show-source-of-page', 'page-action'],
|
||||
showPageInfo: ['command:View:PageInfo', 'show-page-info', 'page-action'],
|
||||
|
||||
// Visible actions
|
||||
zoomIn: ["command:cmd_fullZoomEnlarge", "zoom-in", "visible-action"],
|
||||
zoomOut: ["command:cmd_fullZoomReduce", "zoom-out", "visible-action"],
|
||||
resetZoom: ["command:cmd_fullZoomReset", "reset-zoom", "visible-action"],
|
||||
zoomIn: ['command:cmd_fullZoomEnlarge', 'zoom-in', 'visible-action'],
|
||||
zoomOut: ['command:cmd_fullZoomReduce', 'zoom-out', 'visible-action'],
|
||||
resetZoom: ['command:cmd_fullZoomReset', 'reset-zoom', 'visible-action'],
|
||||
|
||||
// History actions
|
||||
back: ["command:Browser:Back", "back", "history-action"],
|
||||
forward: ["command:Browser:Forward", "forward", "history-action"],
|
||||
stop: ["command:Browser:Stop", "stop", "history-action"],
|
||||
reload: ["command:Browser:Reload", "reload", "history-action"],
|
||||
forceReload: [
|
||||
"command:Browser:ReloadSkipCache",
|
||||
"force-reload",
|
||||
"history-action",
|
||||
],
|
||||
back: ['command:Browser:Back', 'back', 'history-action'],
|
||||
forward: ['command:Browser:Forward', 'forward', 'history-action'],
|
||||
stop: ['command:Browser:Stop', 'stop', 'history-action'],
|
||||
reload: ['command:Browser:Reload', 'reload', 'history-action'],
|
||||
forceReload: ['command:Browser:ReloadSkipCache', 'force-reload', 'history-action'],
|
||||
|
||||
// search actions
|
||||
searchInThisPage: [
|
||||
"gLazyFindCommand('onFindCommand')",
|
||||
"search-in-this-page",
|
||||
"search-action",
|
||||
],
|
||||
showNextSearchResult: [
|
||||
"gLazyFindCommand('onFindAgainCommand', false)",
|
||||
"show-next-search-result",
|
||||
"search-action",
|
||||
],
|
||||
showPreviousSearchResult: [
|
||||
"gLazyFindCommand('onFindAgainCommand', true)",
|
||||
"show-previous-search-result",
|
||||
"search-action",
|
||||
],
|
||||
searchTheWeb: ["command:Tools:Search", "search-the-web", "search-action"],
|
||||
searchInThisPage: ["gLazyFindCommand('onFindCommand')", 'search-in-this-page', 'search-action'],
|
||||
showNextSearchResult: ["gLazyFindCommand('onFindAgainCommand', false)", 'show-next-search-result', 'search-action'],
|
||||
showPreviousSearchResult: ["gLazyFindCommand('onFindAgainCommand', true)", 'show-previous-search-result', 'search-action'],
|
||||
searchTheWeb: ['command:Tools:Search', 'search-the-web', 'search-action'],
|
||||
|
||||
// Tools actions
|
||||
openMigrationWizard: [
|
||||
"command:cmd_file_importFromAnotherBrowser",
|
||||
"open-migration-wizard",
|
||||
"tools-action",
|
||||
],
|
||||
quitFromApplication: [
|
||||
"command:goQuitApplication",
|
||||
"quit-from-application",
|
||||
"tools-action",
|
||||
],
|
||||
enterIntoCustomizeMode: [
|
||||
"gCustomizeMode.enter()",
|
||||
"enter-into-customize-mode",
|
||||
"tools-action",
|
||||
],
|
||||
enterIntoOfflineMode: [
|
||||
"command:cmd_toggleOfflineStatus",
|
||||
"enter-into-offline-mode",
|
||||
"tools-action",
|
||||
],
|
||||
openScreenCapture: [
|
||||
"command:Browser:Screenshot",
|
||||
"open-screen-capture",
|
||||
"tools-action",
|
||||
],
|
||||
openMigrationWizard: ['command:cmd_file_importFromAnotherBrowser', 'open-migration-wizard', 'tools-action'],
|
||||
quitFromApplication: ['command:goQuitApplication', 'quit-from-application', 'tools-action'],
|
||||
enterIntoCustomizeMode: ['gCustomizeMode.enter()', 'enter-into-customize-mode', 'tools-action'],
|
||||
enterIntoOfflineMode: ['command:cmd_toggleOfflineStatus', 'enter-into-offline-mode', 'tools-action'],
|
||||
openScreenCapture: ['command:Browser:Screenshot', 'open-screen-capture', 'tools-action'],
|
||||
|
||||
// Bookmark actions
|
||||
bookmarkThisPage: [
|
||||
"BrowserPageActions.doCommandForAction(PageActions.actionForID('bookmark'), event, this);",
|
||||
"bookmark-this-page",
|
||||
"bookmark-action",
|
||||
'bookmark-this-page',
|
||||
'bookmark-action',
|
||||
],
|
||||
openBookmarkAddTool: [
|
||||
"PlacesUIUtils.showBookmarkPagesDialog(PlacesCommandHook.uniqueCurrentPages)",
|
||||
"open-bookmark-add-tool",
|
||||
"bookmark-action",
|
||||
],
|
||||
openBookmarksManager: [
|
||||
"SidebarController.toggle('viewBookmarksSidebar');",
|
||||
"open-bookmarks-manager",
|
||||
"bookmark-action",
|
||||
'PlacesUIUtils.showBookmarkPagesDialog(PlacesCommandHook.uniqueCurrentPages)',
|
||||
'open-bookmark-add-tool',
|
||||
'bookmark-action',
|
||||
],
|
||||
openBookmarksManager: ["SidebarController.toggle('viewBookmarksSidebar');", 'open-bookmarks-manager', 'bookmark-action'],
|
||||
toggleBookmarkToolbar: [
|
||||
"BookmarkingUI.toggleBookmarksToolbar('bookmark-tools')",
|
||||
"toggle-bookmark-toolbar",
|
||||
"bookmark-action",
|
||||
'toggle-bookmark-toolbar',
|
||||
'bookmark-action',
|
||||
],
|
||||
|
||||
// Open Page actions
|
||||
openGeneralPreferences: [
|
||||
"openPreferences()",
|
||||
"open-general-preferences",
|
||||
"open-page-action",
|
||||
],
|
||||
openPrivacyPreferences: [
|
||||
"openPreferences('panePrivacy')",
|
||||
"open-privacy-preferences",
|
||||
"open-page-action",
|
||||
],
|
||||
openWorkspacesPreferences: [
|
||||
"openPreferences('paneWorkspaces')",
|
||||
"open-workspaces-preferences",
|
||||
"open-page-action",
|
||||
],
|
||||
openContainersPreferences: [
|
||||
"openPreferences('paneContainers')",
|
||||
"open-containers-preferences",
|
||||
"open-page-action",
|
||||
],
|
||||
openSearchPreferences: [
|
||||
"openPreferences('paneSearch')",
|
||||
"open-search-preferences",
|
||||
"open-page-action",
|
||||
],
|
||||
openSyncPreferences: [
|
||||
"openPreferences('paneSync')",
|
||||
"open-sync-preferences",
|
||||
"open-page-action",
|
||||
],
|
||||
openTaskManager: [
|
||||
"command:View:AboutProcesses",
|
||||
"open-task-manager",
|
||||
"open-page-action",
|
||||
],
|
||||
openAddonsManager: [
|
||||
"command:Tools:Addons",
|
||||
"open-addons-manager",
|
||||
"open-page-action",
|
||||
],
|
||||
openHomePage: ["BrowserHome()", "open-home-page", "open-page-action"],
|
||||
openGeneralPreferences: ['openPreferences()', 'open-general-preferences', 'open-page-action'],
|
||||
openPrivacyPreferences: ["openPreferences('panePrivacy')", 'open-privacy-preferences', 'open-page-action'],
|
||||
openWorkspacesPreferences: ["openPreferences('paneWorkspaces')", 'open-workspaces-preferences', 'open-page-action'],
|
||||
openContainersPreferences: ["openPreferences('paneContainers')", 'open-containers-preferences', 'open-page-action'],
|
||||
openSearchPreferences: ["openPreferences('paneSearch')", 'open-search-preferences', 'open-page-action'],
|
||||
openSyncPreferences: ["openPreferences('paneSync')", 'open-sync-preferences', 'open-page-action'],
|
||||
openTaskManager: ['command:View:AboutProcesses', 'open-task-manager', 'open-page-action'],
|
||||
openAddonsManager: ['command:Tools:Addons', 'open-addons-manager', 'open-page-action'],
|
||||
openHomePage: ['BrowserHome()', 'open-home-page', 'open-page-action'],
|
||||
|
||||
// History actions
|
||||
forgetHistory: ["command:Tools:Sanitize", "forget-history", "history-action"],
|
||||
quickForgetHistory: [
|
||||
"PlacesUtils.history.clear(true)",
|
||||
"quick-forget-history",
|
||||
"history-action",
|
||||
],
|
||||
clearRecentHistory: [
|
||||
"command:cmd_closeWindow",
|
||||
"clear-recent-history",
|
||||
"history-action",
|
||||
],
|
||||
restoreLastSession: [
|
||||
"command:Browser:RestoreLastSession",
|
||||
"restore-last-session",
|
||||
"history-action",
|
||||
],
|
||||
searchHistory: [
|
||||
"command:History:SearchHistory",
|
||||
"search-history",
|
||||
"history-action",
|
||||
],
|
||||
manageHistory: [
|
||||
"PlacesCommandHook.showPlacesOrganizer('History')",
|
||||
"manage-history",
|
||||
"history-action",
|
||||
],
|
||||
forgetHistory: ['command:Tools:Sanitize', 'forget-history', 'history-action'],
|
||||
quickForgetHistory: ['PlacesUtils.history.clear(true)', 'quick-forget-history', 'history-action'],
|
||||
clearRecentHistory: ['command:cmd_closeWindow', 'clear-recent-history', 'history-action'],
|
||||
restoreLastSession: ['command:Browser:RestoreLastSession', 'restore-last-session', 'history-action'],
|
||||
searchHistory: ['command:History:SearchHistory', 'search-history', 'history-action'],
|
||||
manageHistory: ["PlacesCommandHook.showPlacesOrganizer('History')", 'manage-history', 'history-action'],
|
||||
|
||||
// Downloads actions
|
||||
openDownloads: [
|
||||
"DownloadsPanel.showDownloadsHistory()",
|
||||
"open-downloads",
|
||||
"downloads-action",
|
||||
],
|
||||
openDownloads: ['DownloadsPanel.showDownloadsHistory()', 'open-downloads', 'downloads-action'],
|
||||
|
||||
// Sidebar actions
|
||||
showBookmarkSidebar: [
|
||||
"SidebarController.show('viewBookmarksSidebar')",
|
||||
"show-bookmark-sidebar",
|
||||
"sidebar-action",
|
||||
],
|
||||
showHistorySidebar: [
|
||||
"SidebarController.show('viewHistorySidebar')",
|
||||
"show-history-sidebar",
|
||||
"sidebar-action",
|
||||
],
|
||||
showSyncedTabsSidebar: [
|
||||
"SidebarController.show('viewTabsSidebar')",
|
||||
"show-synced-tabs-sidebar",
|
||||
"sidebar-action",
|
||||
],
|
||||
reverseSidebarPosition: [
|
||||
"SidebarController.reversePosition()",
|
||||
"reverse-sidebar",
|
||||
"sidebar-action",
|
||||
],
|
||||
hideSidebar: ["SidebarController.hide()", "hide-sidebar", "sidebar-action"],
|
||||
toggleSidebar: [
|
||||
"SidebarController.toggle()",
|
||||
"toggle-sidebar",
|
||||
"sidebar-action",
|
||||
],
|
||||
zenToggleWebPanels: [
|
||||
"gZenBrowserManagerSidebar.toggle()",
|
||||
"zen-toggle-web-panels",
|
||||
"sidebar-action",
|
||||
],
|
||||
showBookmarkSidebar: ["SidebarController.show('viewBookmarksSidebar')", 'show-bookmark-sidebar', 'sidebar-action'],
|
||||
showHistorySidebar: ["SidebarController.show('viewHistorySidebar')", 'show-history-sidebar', 'sidebar-action'],
|
||||
showSyncedTabsSidebar: ["SidebarController.show('viewTabsSidebar')", 'show-synced-tabs-sidebar', 'sidebar-action'],
|
||||
reverseSidebarPosition: ['SidebarController.reversePosition()', 'reverse-sidebar', 'sidebar-action'],
|
||||
hideSidebar: ['SidebarController.hide()', 'hide-sidebar', 'sidebar-action'],
|
||||
toggleSidebar: ['SidebarController.toggle()', 'toggle-sidebar', 'sidebar-action'],
|
||||
zenToggleWebPanels: ['gZenBrowserManagerSidebar.toggle()', 'zen-toggle-web-panels', 'sidebar-action'],
|
||||
zenExpandSidebar: ['gZenVerticalTabsManager.toggleExpand()', 'zen-expand-sidebar', 'sidebar-action'],
|
||||
};
|
||||
|
||||
const kZenDefaultShortcuts = {
|
||||
// Split view actions
|
||||
zenSplitViewGrid: "Ctrl+Alt+G",
|
||||
zenSplitViewVertical: "Ctrl+Alt+V",
|
||||
zenSplitViewHorizontal: "Ctrl+Alt+H",
|
||||
zenSplitViewClose: "Ctrl+Alt+U",
|
||||
zenSplitViewGrid: 'Ctrl+Alt+G',
|
||||
zenSplitViewVertical: 'Ctrl+Alt+V',
|
||||
zenSplitViewHorizontal: 'Ctrl+Alt+H',
|
||||
zenSplitViewClose: 'Ctrl+Alt+U',
|
||||
|
||||
// Workspace actions
|
||||
zenChangeWorkspace: "Ctrl+Shift+E",
|
||||
zenChangeWorkspace: 'Ctrl+Shift+E',
|
||||
|
||||
// Compact mode actions
|
||||
zenToggleCompactMode: "Ctrl+Alt+C",
|
||||
zenToggleCompactModeSidebar: "Ctrl+Alt+S",
|
||||
zenToggleCompactModeToolbar: "Ctrl+Alt+T",
|
||||
zenToggleCompactMode: 'Ctrl+Alt+C',
|
||||
zenToggleCompactModeSidebar: 'Ctrl+Alt+S',
|
||||
zenToggleCompactModeToolbar: 'Ctrl+Alt+T',
|
||||
|
||||
// manage actions
|
||||
zenToggleWebPanels: "Alt+P",
|
||||
zenToggleWebPanels: 'Alt+P',
|
||||
};
|
||||
|
||||
// Section: ZenKeyboardShortcuts
|
||||
|
||||
const kZKSStorageKey = "zen.keyboard.shortcuts";
|
||||
const kZKSStorageKey = 'zen.keyboard.shortcuts';
|
||||
const kZKSKeyCodeMap = {
|
||||
F1: "VK_F1",
|
||||
F2: "VK_F2",
|
||||
F3: "VK_F3",
|
||||
F4: "VK_F4",
|
||||
F5: "VK_F5",
|
||||
F6: "VK_F6",
|
||||
F7: "VK_F7",
|
||||
F8: "VK_F8",
|
||||
F9: "VK_F9",
|
||||
F10: "VK_F10",
|
||||
F11: "VK_F11",
|
||||
F12: "VK_F12",
|
||||
TAB: "VK_TAB",
|
||||
ENTER: "VK_RETURN",
|
||||
ESCAPE: "VK_ESCAPE",
|
||||
SPACE: "VK_SPACE",
|
||||
ARROWLEFT: "VK_LEFT",
|
||||
ARROWRIGHT: "VK_RIGHT",
|
||||
ARROWUP: "VK_UP",
|
||||
ARROWDOWN: "VK_DOWN",
|
||||
DELETE: "VK_DELETE",
|
||||
BACKSPACE: "VK_BACK",
|
||||
F1: 'VK_F1',
|
||||
F2: 'VK_F2',
|
||||
F3: 'VK_F3',
|
||||
F4: 'VK_F4',
|
||||
F5: 'VK_F5',
|
||||
F6: 'VK_F6',
|
||||
F7: 'VK_F7',
|
||||
F8: 'VK_F8',
|
||||
F9: 'VK_F9',
|
||||
F10: 'VK_F10',
|
||||
F11: 'VK_F11',
|
||||
F12: 'VK_F12',
|
||||
TAB: 'VK_TAB',
|
||||
ENTER: 'VK_RETURN',
|
||||
ESCAPE: 'VK_ESCAPE',
|
||||
SPACE: 'VK_SPACE',
|
||||
ARROWLEFT: 'VK_LEFT',
|
||||
ARROWRIGHT: 'VK_RIGHT',
|
||||
ARROWUP: 'VK_UP',
|
||||
ARROWDOWN: 'VK_DOWN',
|
||||
DELETE: 'VK_DELETE',
|
||||
BACKSPACE: 'VK_BACK',
|
||||
};
|
||||
|
||||
var gZenKeyboardShortcuts = {
|
||||
init() {
|
||||
if (!Services.prefs.getBoolPref("zen.keyboard.shortcuts.enabled")) {
|
||||
if (!Services.prefs.getBoolPref('zen.keyboard.shortcuts.enabled')) {
|
||||
return;
|
||||
}
|
||||
this._initShortcuts();
|
||||
|
@ -361,7 +186,7 @@ var gZenKeyboardShortcuts = {
|
|||
}
|
||||
this.__savedShortcuts = JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.error("Zen CKS: Error parsing saved shortcuts", e);
|
||||
console.error('Zen CKS: Error parsing saved shortcuts', e);
|
||||
this.__savedShortcuts = {};
|
||||
}
|
||||
}
|
||||
|
@ -382,34 +207,16 @@ var gZenKeyboardShortcuts = {
|
|||
},
|
||||
|
||||
_parseDefaultShortcut(shortcut) {
|
||||
let ctrl = shortcut.includes("Ctrl+");
|
||||
let alt = shortcut.includes("Alt+");
|
||||
let shift = shortcut.includes("Shift+");
|
||||
let meta = shortcut.includes("Meta+");
|
||||
let key = shortcut.replace(/Ctrl\+|Alt\+|Shift\+|Meta\+/g, "");
|
||||
if (
|
||||
[
|
||||
"Tab",
|
||||
"Enter",
|
||||
"Escape",
|
||||
"Space",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
].includes(key)
|
||||
) {
|
||||
let ctrl = shortcut.includes('Ctrl+');
|
||||
let alt = shortcut.includes('Alt+');
|
||||
let shift = shortcut.includes('Shift+');
|
||||
let meta = shortcut.includes('Meta+');
|
||||
let key = shortcut.replace(/Ctrl\+|Alt\+|Shift\+|Meta\+/g, '');
|
||||
if (['Tab', 'Enter', 'Escape', 'Space', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(key)) {
|
||||
return { ctrl, alt, shift, meta, key: undefined, keycode: key };
|
||||
}
|
||||
let isKeyCode = key.length > 1;
|
||||
return {
|
||||
ctrl,
|
||||
alt,
|
||||
shift,
|
||||
meta,
|
||||
key: isKeyCode ? undefined : key,
|
||||
keycode: isKeyCode ? key : undefined,
|
||||
};
|
||||
return { ctrl, alt, shift, meta, key: isKeyCode ? undefined : key, keycode: isKeyCode ? key : undefined };
|
||||
},
|
||||
|
||||
_addDefaultShortcuts() {
|
||||
|
@ -432,50 +239,42 @@ var gZenKeyboardShortcuts = {
|
|||
},
|
||||
|
||||
_initShortcuts() {
|
||||
if (window.location.href == "chrome://browser/content/browser.xhtml") {
|
||||
console.info("Zen CKS: Initializing shortcuts");
|
||||
Services.prefs.addObserver(
|
||||
kZKSStorageKey,
|
||||
this._onShortcutChange.bind(this),
|
||||
);
|
||||
Services.prefs.addObserver(
|
||||
"zen.keyboard.shortcuts.disable-firefox",
|
||||
this._disableFirefoxShortcuts.bind(this),
|
||||
);
|
||||
if (window.location.href == 'chrome://browser/content/browser.xhtml') {
|
||||
console.info('Zen CKS: Initializing shortcuts');
|
||||
Services.prefs.addObserver(kZKSStorageKey, this._onShortcutChange.bind(this));
|
||||
Services.prefs.addObserver('zen.keyboard.shortcuts.disable-firefox', this._disableFirefoxShortcuts.bind(this));
|
||||
this._initSavedShortcuts();
|
||||
this._disableFirefoxShortcuts();
|
||||
}
|
||||
},
|
||||
|
||||
_disableFirefoxShortcuts() {
|
||||
let disable = Services.prefs.getBoolPref(
|
||||
"zen.keyboard.shortcuts.disable-firefox",
|
||||
);
|
||||
let disable = Services.prefs.getBoolPref('zen.keyboard.shortcuts.disable-firefox');
|
||||
if (!disable) {
|
||||
return;
|
||||
}
|
||||
window.SessionStore.promiseInitialized.then(() => {
|
||||
let keySet = document.getElementById("mainKeyset");
|
||||
let keySet = document.getElementById('mainKeyset');
|
||||
if (!keySet) {
|
||||
throw new Error("Zen CKS: No main keyset found");
|
||||
throw new Error('Zen CKS: No main keyset found');
|
||||
}
|
||||
for (let child of keySet.children) {
|
||||
if (!child.id.startsWith("zen-key_")) {
|
||||
child.setAttribute("disabled", true);
|
||||
if (!child.id.startsWith('zen-key_')) {
|
||||
child.setAttribute('disabled', true);
|
||||
}
|
||||
}
|
||||
console.info("Remove already exist shortcut keys");
|
||||
console.info('Remove already exist shortcut keys');
|
||||
});
|
||||
},
|
||||
|
||||
_onShortcutChange() {
|
||||
console.info("Zen CKS: Shortcut changed");
|
||||
console.info('Zen CKS: Shortcut changed');
|
||||
this.__savedShortcuts = null;
|
||||
this._initSavedShortcuts(true);
|
||||
},
|
||||
|
||||
_getCommandAttribute(action) {
|
||||
if (action.startsWith("command:")) {
|
||||
if (action.startsWith('command:')) {
|
||||
return `command="${action.substring(8)}"`;
|
||||
}
|
||||
return `oncommand="${action}"`;
|
||||
|
@ -499,7 +298,7 @@ var gZenKeyboardShortcuts = {
|
|||
|
||||
modifiers = Object.keys(modifiers)
|
||||
.filter((mod) => modifiers[mod])
|
||||
.join(",");
|
||||
.join(',');
|
||||
|
||||
if (keycode) {
|
||||
const key = kZKSKeyCodeMap[keycode] || keycode;
|
||||
|
@ -524,9 +323,9 @@ var gZenKeyboardShortcuts = {
|
|||
},
|
||||
|
||||
_initSavedShortcuts(fromUpdate = false) {
|
||||
let keySet = document.getElementById("mainKeyset");
|
||||
let keySet = document.getElementById('mainKeyset');
|
||||
if (!keySet) {
|
||||
throw new Error("Zen CKS: No main keyset found");
|
||||
throw new Error('Zen CKS: No main keyset found');
|
||||
}
|
||||
|
||||
for (let action in kZKSActions) {
|
||||
|
@ -545,9 +344,9 @@ var gZenKeyboardShortcuts = {
|
|||
},
|
||||
|
||||
_fixMeinKeyset() {
|
||||
let keySet = document.getElementById("mainKeyset");
|
||||
let keySet = document.getElementById('mainKeyset');
|
||||
if (!keySet) {
|
||||
throw new Error("Zen CKS: No main keyset found");
|
||||
throw new Error('Zen CKS: No main keyset found');
|
||||
}
|
||||
const parent = keySet.parentElement;
|
||||
// We need to re-append the main keyset to the document to make the shortcuts work
|
||||
|
@ -564,15 +363,15 @@ var gZenKeyboardShortcuts = {
|
|||
},
|
||||
|
||||
shortCutToString(shortcut) {
|
||||
let str = "";
|
||||
let str = '';
|
||||
if (shortcut.ctrl) {
|
||||
str += "Ctrl+";
|
||||
}
|
||||
if (shortcut.alt) {
|
||||
str += "Alt+";
|
||||
str += 'Alt+';
|
||||
}
|
||||
if (shortcut.shift) {
|
||||
str += "Shift+";
|
||||
str += 'Shift+';
|
||||
}
|
||||
if (shortcut.meta) {
|
||||
str += AppConstants.platform == "macosx" ? "Cmd+" : "Meta+";
|
||||
|
|
|
@ -44,7 +44,7 @@ var ZenProfileDialogUI = {
|
|||
_updateCurentProfileId() {
|
||||
let currentProfile = ProfileService.currentProfile;
|
||||
if (!currentProfile) return;
|
||||
let nameContainer = document.getElementById("PanelUI-zen-profiles-current-name");
|
||||
let nameContainer = document.getElementById('PanelUI-zen-profiles-current-name');
|
||||
nameContainer.textContent = currentProfile.name;
|
||||
},
|
||||
|
||||
|
@ -64,25 +64,27 @@ var ZenProfileDialogUI = {
|
|||
// This should be rewritten in HTML eventually.
|
||||
// TODO: it could be `window.browsingContext.topChromeWindow.gDialogBox.open` but it does not work with the callback?
|
||||
window.browsingContext.topChromeWindow.openDialog(
|
||||
"chrome://mozapps/content/profile/createProfileWizard.xhtml",
|
||||
"",
|
||||
"centerscreen,chrome,modal,titlebar",
|
||||
'chrome://mozapps/content/profile/createProfileWizard.xhtml',
|
||||
'',
|
||||
'centerscreen,chrome,modal,titlebar',
|
||||
ProfileService,
|
||||
{ CreateProfile: async (profile) => {
|
||||
try {
|
||||
ProfileService.defaultProfile = profile;
|
||||
this._flush();
|
||||
this._openProfile(profile);
|
||||
} 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);
|
||||
}
|
||||
} }
|
||||
{
|
||||
CreateProfile: async (profile) => {
|
||||
try {
|
||||
ProfileService.defaultProfile = profile;
|
||||
this._flush();
|
||||
this._openProfile(profile);
|
||||
} 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);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -92,23 +94,19 @@ var ZenProfileDialogUI = {
|
|||
this._updateProfilesList();
|
||||
} catch (e) {
|
||||
let [title, msg, button] = await document.l10n.formatValues([
|
||||
{ id: "profiles-flush-fail-title" },
|
||||
{ id: 'profiles-flush-fail-title' },
|
||||
{
|
||||
id:
|
||||
e.result == Cr.NS_ERROR_DATABASE_CHANGED
|
||||
? "profiles-flush-conflict"
|
||||
: "profiles-flush-failed",
|
||||
id: e.result == Cr.NS_ERROR_DATABASE_CHANGED ? 'profiles-flush-conflict' : 'profiles-flush-failed',
|
||||
},
|
||||
{ id: "profiles-flush-restart-button" },
|
||||
{ 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,
|
||||
PS.BUTTON_POS_0 * PS.BUTTON_TITLE_CANCEL + PS.BUTTON_POS_1 * PS.BUTTON_TITLE_IS_STRING,
|
||||
null,
|
||||
button,
|
||||
null,
|
||||
|
@ -122,25 +120,19 @@ var ZenProfileDialogUI = {
|
|||
},
|
||||
|
||||
_restart(safeMode) {
|
||||
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
|
||||
Ci.nsISupportsPRBool
|
||||
);
|
||||
Services.obs.notifyObservers(
|
||||
cancelQuit,
|
||||
"quit-application-requested",
|
||||
"restart"
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -9,8 +9,7 @@ var gZenBrowserManagerSidebar = {
|
|||
_isDragging: false,
|
||||
contextTab: null,
|
||||
|
||||
DEFAULT_MOBILE_USER_AGENT:
|
||||
"Mozilla/5.0 (Android 12; Mobile; rv:129.0) Gecko/20100101 Firefox/129.0",
|
||||
DEFAULT_MOBILE_USER_AGENT: 'Mozilla/5.0 (Android 12; Mobile; rv:129.0) Gecko/20100101 Firefox/130.0',
|
||||
MAX_SIDEBAR_PANELS: 8, // +1 for the add panel button
|
||||
MAX_RUNS: 3,
|
||||
|
||||
|
@ -22,35 +21,28 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
get sidebarData() {
|
||||
let services = Services.prefs.getStringPref("zen.sidebar.data");
|
||||
if (services === "") {
|
||||
let services = Services.prefs.getStringPref('zen.sidebar.data');
|
||||
if (services === '') {
|
||||
return {};
|
||||
}
|
||||
return JSON.parse(services);
|
||||
},
|
||||
|
||||
get shouldCloseOnBlur() {
|
||||
return Services.prefs.getBoolPref("zen.sidebar.close-on-blur");
|
||||
return Services.prefs.getBoolPref('zen.sidebar.close-on-blur');
|
||||
},
|
||||
|
||||
listenForPrefChanges() {
|
||||
Services.prefs.addObserver("zen.sidebar.data", this.handleEvent.bind(this));
|
||||
Services.prefs.addObserver(
|
||||
"zen.sidebar.enabled",
|
||||
this.handleEvent.bind(this)
|
||||
);
|
||||
Services.prefs.addObserver('zen.sidebar.data', this.handleEvent.bind(this));
|
||||
Services.prefs.addObserver('zen.sidebar.enabled', this.handleEvent.bind(this));
|
||||
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
this.splitterElement.addEventListener(
|
||||
"mousedown",
|
||||
'mousedown',
|
||||
function (event) {
|
||||
let computedStyle = window.getComputedStyle(sidebar);
|
||||
let maxWidth = parseInt(
|
||||
computedStyle.getPropertyValue("max-width").replace("px", "")
|
||||
);
|
||||
let minWidth = parseInt(
|
||||
computedStyle.getPropertyValue("min-width").replace("px", "")
|
||||
);
|
||||
let maxWidth = parseInt(computedStyle.getPropertyValue('max-width').replace('px', ''));
|
||||
let minWidth = parseInt(computedStyle.getPropertyValue('min-width').replace('px', ''));
|
||||
|
||||
if (!this._isDragging) {
|
||||
// Prevent multiple resizes
|
||||
|
@ -70,30 +62,25 @@ var gZenBrowserManagerSidebar = {
|
|||
let mouseUp = function () {
|
||||
this.handleEvent();
|
||||
this._isDragging = false;
|
||||
document.removeEventListener("mousemove", mouseMove);
|
||||
document.removeEventListener("mouseup", mouseUp);
|
||||
document.removeEventListener('mousemove', mouseMove);
|
||||
document.removeEventListener('mouseup', mouseUp);
|
||||
}.bind(this);
|
||||
document.addEventListener("mousemove", mouseMove);
|
||||
document.addEventListener("mouseup", mouseUp);
|
||||
document.addEventListener('mousemove', mouseMove);
|
||||
document.addEventListener('mouseup', mouseUp);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.hSplitterElement.addEventListener(
|
||||
"mousedown",
|
||||
'mousedown',
|
||||
function (event) {
|
||||
let computedStyle = window.getComputedStyle(sidebar);
|
||||
const parent = sidebar.parentElement;
|
||||
// relative to avoid the top margin
|
||||
// 20px is the padding
|
||||
let parentRelativeHeight =
|
||||
parent.getBoundingClientRect().height -
|
||||
parent.getBoundingClientRect().top +
|
||||
sidebar.getBoundingClientRect().top -
|
||||
20;
|
||||
let minHeight = parseInt(
|
||||
computedStyle.getPropertyValue("min-height").replace("px", "")
|
||||
);
|
||||
parent.getBoundingClientRect().height - parent.getBoundingClientRect().top + sidebar.getBoundingClientRect().top - 20;
|
||||
let minHeight = parseInt(computedStyle.getPropertyValue('min-height').replace('px', ''));
|
||||
if (!this._isDragging) {
|
||||
// Prevent multiple resizes
|
||||
this._isDragging = true;
|
||||
|
@ -113,11 +100,11 @@ var gZenBrowserManagerSidebar = {
|
|||
let mouseUp = function () {
|
||||
this.handleEvent();
|
||||
this._isDragging = false;
|
||||
document.removeEventListener("mousemove", mouseMove);
|
||||
document.removeEventListener("mouseup", mouseUp);
|
||||
document.removeEventListener('mousemove', mouseMove);
|
||||
document.removeEventListener('mouseup', mouseUp);
|
||||
}.bind(this);
|
||||
document.addEventListener("mousemove", mouseMove);
|
||||
document.addEventListener("mouseup", mouseUp);
|
||||
document.addEventListener('mousemove', mouseMove);
|
||||
document.addEventListener('mouseup', mouseUp);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
@ -126,9 +113,7 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
get isFloating() {
|
||||
return document
|
||||
.getElementById("zen-sidebar-web-panel")
|
||||
.hasAttribute("pinned");
|
||||
return document.getElementById('zen-sidebar-web-panel').hasAttribute('pinned');
|
||||
},
|
||||
|
||||
handleEvent() {
|
||||
|
@ -140,40 +125,36 @@ var gZenBrowserManagerSidebar = {
|
|||
var clickOutsideHandler = this._handleClickOutside.bind(this);
|
||||
let isFloating = this.isFloating;
|
||||
if (isFloating && !this._hasRegisteredPinnedClickOutside) {
|
||||
document.addEventListener("mouseup", clickOutsideHandler);
|
||||
document.addEventListener('mouseup', clickOutsideHandler);
|
||||
this._hasRegisteredPinnedClickOutside = true;
|
||||
} else if (!isFloating && this._hasRegisteredPinnedClickOutside) {
|
||||
document.removeEventListener("mouseup", clickOutsideHandler);
|
||||
document.removeEventListener('mouseup', clickOutsideHandler);
|
||||
this._hasRegisteredPinnedClickOutside = false;
|
||||
}
|
||||
|
||||
const button = document.getElementById("zen-sidepanel-button");
|
||||
if (Services.prefs.getBoolPref("zen.sidebar.enabled")) {
|
||||
button.removeAttribute("hidden");
|
||||
const button = document.getElementById('zen-sidepanel-button');
|
||||
if (Services.prefs.getBoolPref('zen.sidebar.enabled')) {
|
||||
button.removeAttribute('hidden');
|
||||
} else {
|
||||
button.setAttribute("hidden", "true");
|
||||
button.setAttribute('hidden', 'true');
|
||||
this._closeSidebarPanel();
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
_handleClickOutside(event) {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
if (
|
||||
!sidebar.hasAttribute("pinned") ||
|
||||
this._isDragging ||
|
||||
!this.shouldCloseOnBlur
|
||||
) {
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
if (!sidebar.hasAttribute('pinned') || this._isDragging || !this.shouldCloseOnBlur) {
|
||||
return;
|
||||
}
|
||||
let target = event.target;
|
||||
const closestSelector = [
|
||||
"#zen-sidebar-web-panel",
|
||||
"#zen-sidebar-panels-wrapper",
|
||||
"#zenWebPanelContextMenu",
|
||||
"#zen-sidebar-web-panel-splitter",
|
||||
"#contentAreaContextMenu",
|
||||
].join(", ");
|
||||
'#zen-sidebar-web-panel',
|
||||
'#zen-sidebar-panels-wrapper',
|
||||
'#zenWebPanelContextMenu',
|
||||
'#zen-sidebar-web-panel-splitter',
|
||||
'#contentAreaContextMenu',
|
||||
].join(', ');
|
||||
if (target.closest(closestSelector)) {
|
||||
return;
|
||||
}
|
||||
|
@ -184,9 +165,7 @@ var gZenBrowserManagerSidebar = {
|
|||
if (!this._currentPanel) {
|
||||
this._currentPanel = this._lastOpenedPanel;
|
||||
}
|
||||
if (
|
||||
document.getElementById("zen-sidebar-web-panel").hasAttribute("hidden")
|
||||
) {
|
||||
if (document.getElementById('zen-sidebar-web-panel').hasAttribute('hidden')) {
|
||||
this.open();
|
||||
return;
|
||||
}
|
||||
|
@ -194,8 +173,8 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
open() {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
sidebar.removeAttribute("hidden");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
sidebar.removeAttribute('hidden');
|
||||
this.update();
|
||||
},
|
||||
|
||||
|
@ -207,21 +186,19 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
_updateSidebarButton() {
|
||||
let button = document.getElementById("zen-sidepanel-button");
|
||||
if (
|
||||
!document.getElementById("zen-sidebar-web-panel").hasAttribute("hidden")
|
||||
) {
|
||||
button.setAttribute("open", "true");
|
||||
let button = document.getElementById('zen-sidepanel-button');
|
||||
if (!document.getElementById('zen-sidebar-web-panel').hasAttribute('hidden')) {
|
||||
button.setAttribute('open', 'true');
|
||||
} else {
|
||||
button.removeAttribute("open");
|
||||
button.removeAttribute('open');
|
||||
}
|
||||
},
|
||||
|
||||
_updateWebPanels() {
|
||||
if (Services.prefs.getBoolPref("zen.sidebar.enabled")) {
|
||||
this.sidebarElement.removeAttribute("hidden");
|
||||
if (Services.prefs.getBoolPref('zen.sidebar.enabled')) {
|
||||
this.sidebarElement.removeAttribute('hidden');
|
||||
} else {
|
||||
this.sidebarElement.setAttribute("hidden", "true");
|
||||
this.sidebarElement.setAttribute('hidden', 'true');
|
||||
this._closeSidebarPanel();
|
||||
return;
|
||||
}
|
||||
|
@ -230,75 +207,67 @@ var gZenBrowserManagerSidebar = {
|
|||
if (!data.data || !data.index) {
|
||||
return;
|
||||
}
|
||||
this.sidebarElement.innerHTML = "";
|
||||
this.sidebarElement.innerHTML = '';
|
||||
for (let site of data.index) {
|
||||
let panel = data.data[site];
|
||||
if (!panel || !panel.url) {
|
||||
continue;
|
||||
}
|
||||
let button = document.createXULElement("toolbarbutton");
|
||||
button.classList.add(
|
||||
"zen-sidebar-panel-button",
|
||||
"toolbarbutton-1",
|
||||
"chromeclass-toolbar-additional"
|
||||
);
|
||||
button.setAttribute("flex", "1");
|
||||
button.setAttribute("zen-sidebar-id", site);
|
||||
button.setAttribute("context", "zenWebPanelContextMenu");
|
||||
let button = document.createXULElement('toolbarbutton');
|
||||
button.classList.add('zen-sidebar-panel-button', 'toolbarbutton-1', 'chromeclass-toolbar-additional');
|
||||
button.setAttribute('flex', '1');
|
||||
button.setAttribute('zen-sidebar-id', site);
|
||||
button.setAttribute('context', 'zenWebPanelContextMenu');
|
||||
this._getWebPanelIcon(panel.url, button);
|
||||
button.addEventListener("click", this._handleClick.bind(this));
|
||||
button.addEventListener('click', this._handleClick.bind(this));
|
||||
button.addEventListener('dragstart', this._handleDragStart.bind(this));
|
||||
button.addEventListener('dragover', this._handleDragOver.bind(this));
|
||||
button.addEventListener('dragenter', this._handleDragEnter.bind(this));
|
||||
button.addEventListener('dragend', this._handleDragEnd.bind(this));
|
||||
this.sidebarElement.appendChild(button);
|
||||
}
|
||||
const addButton = document.getElementById("zen-sidebar-add-panel-button");
|
||||
const addButton = document.getElementById('zen-sidebar-add-panel-button');
|
||||
if (data.index.length < this.MAX_SIDEBAR_PANELS) {
|
||||
addButton.removeAttribute("hidden");
|
||||
addButton.removeAttribute('hidden');
|
||||
} else {
|
||||
addButton.setAttribute("hidden", "true");
|
||||
addButton.setAttribute('hidden', 'true');
|
||||
}
|
||||
},
|
||||
|
||||
async _openAddPanelDialog() {
|
||||
let dialogURL = "chrome://browser/content/places/zenNewWebPanel.xhtml";
|
||||
let features = "centerscreen,chrome,modal,resizable=no";
|
||||
let aParentWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let dialogURL = 'chrome://browser/content/places/zenNewWebPanel.xhtml';
|
||||
let features = 'centerscreen,chrome,modal,resizable=no';
|
||||
let aParentWindow = Services.wm.getMostRecentWindow('navigator:browser');
|
||||
|
||||
if (aParentWindow?.gDialogBox) {
|
||||
await aParentWindow.gDialogBox.open(dialogURL, {});
|
||||
} else {
|
||||
aParentWindow.openDialog(dialogURL, "", features, {});
|
||||
aParentWindow.openDialog(dialogURL, '', features, {});
|
||||
}
|
||||
},
|
||||
|
||||
_setPinnedToElements() {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
sidebar.setAttribute("pinned", "true");
|
||||
document
|
||||
.getElementById("zen-sidebar-web-panel-pinned")
|
||||
.setAttribute("pinned", "true");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
sidebar.setAttribute('pinned', 'true');
|
||||
document.getElementById('zen-sidebar-web-panel-pinned').setAttribute('pinned', 'true');
|
||||
},
|
||||
|
||||
_removePinnedFromElements() {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
sidebar.removeAttribute("pinned");
|
||||
document
|
||||
.getElementById("zen-sidebar-web-panel-pinned")
|
||||
.removeAttribute("pinned");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
sidebar.removeAttribute('pinned');
|
||||
document.getElementById('zen-sidebar-web-panel-pinned').removeAttribute('pinned');
|
||||
},
|
||||
|
||||
_closeSidebarPanel() {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
sidebar.setAttribute("hidden", "true");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
sidebar.setAttribute('hidden', 'true');
|
||||
this._lastOpenedPanel = this._currentPanel;
|
||||
this._currentPanel = null;
|
||||
},
|
||||
|
||||
_handleClick(event) {
|
||||
let target = event.target;
|
||||
let panelId = target.getAttribute("zen-sidebar-id");
|
||||
let panelId = target.getAttribute('zen-sidebar-id');
|
||||
if (this._currentPanel === panelId) {
|
||||
return;
|
||||
}
|
||||
|
@ -316,8 +285,7 @@ var gZenBrowserManagerSidebar = {
|
|||
event.dataTransfer.setData('text/plain', event.target.id);
|
||||
},
|
||||
|
||||
_handleDragOver(event) {
|
||||
},
|
||||
_handleDragOver(event) {},
|
||||
|
||||
_handleDragEnter(event) {
|
||||
const target = event.target;
|
||||
|
@ -336,52 +304,50 @@ var gZenBrowserManagerSidebar = {
|
|||
let data = this.sidebarData;
|
||||
let newPos = [];
|
||||
for (let element of this.__dragingElement.parentNode.children) {
|
||||
console.log(element)
|
||||
let panelId = element.getAttribute("zen-sidebar-id");
|
||||
console.log(element);
|
||||
let panelId = element.getAttribute('zen-sidebar-id');
|
||||
newPos.push(panelId);
|
||||
}
|
||||
data.index = newPos;
|
||||
Services.prefs.setStringPref("zen.sidebar.data", JSON.stringify(data));
|
||||
this._currentPanel = this.__dragingElement.getAttribute("zen-sidebar-id");
|
||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||
this._currentPanel = this.__dragingElement.getAttribute('zen-sidebar-id');
|
||||
this.open();
|
||||
this.__dragingElement = undefined;
|
||||
},
|
||||
|
||||
|
||||
_createNewPanel(url) {
|
||||
let data = this.sidebarData;
|
||||
let newName = "p" + new Date().getTime();
|
||||
let newName = 'p' + new Date().getTime();
|
||||
data.index.push(newName);
|
||||
data.data[newName] = {
|
||||
url: url,
|
||||
ua: false,
|
||||
};
|
||||
Services.prefs.setStringPref("zen.sidebar.data", JSON.stringify(data));
|
||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||
this._currentPanel = newName;
|
||||
this.open();
|
||||
},
|
||||
|
||||
_updateButtons() {
|
||||
for (let button of this.sidebarElement.querySelectorAll(
|
||||
".zen-sidebar-panel-button"
|
||||
)) {
|
||||
if (button.getAttribute("zen-sidebar-id") === this._currentPanel) {
|
||||
button.setAttribute("selected", "true");
|
||||
for (let button of this.sidebarElement.querySelectorAll('.zen-sidebar-panel-button')) {
|
||||
if (button.getAttribute('zen-sidebar-id') === this._currentPanel) {
|
||||
button.setAttribute('selected', 'true');
|
||||
} else {
|
||||
button.removeAttribute("selected");
|
||||
button.removeAttribute('selected');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_hideAllWebPanels() {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
for (let browser of sidebar.querySelectorAll("browser[zen-sidebar-id]")) {
|
||||
browser.setAttribute("hidden", "true");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
for (let browser of sidebar.querySelectorAll('browser[zen-sidebar-id]')) {
|
||||
browser.setAttribute('hidden', 'true');
|
||||
browser.docShellIsActive = false;
|
||||
}
|
||||
},
|
||||
|
||||
get introductionPanel() {
|
||||
return document.getElementById("zen-sidebar-introduction-panel");
|
||||
return document.getElementById('zen-sidebar-introduction-panel');
|
||||
},
|
||||
|
||||
_updateWebPanel() {
|
||||
|
@ -389,23 +355,20 @@ var gZenBrowserManagerSidebar = {
|
|||
// let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
this._hideAllWebPanels();
|
||||
if (!this._currentPanel) {
|
||||
this.introductionPanel.removeAttribute("hidden");
|
||||
this.introductionPanel.removeAttribute('hidden');
|
||||
return;
|
||||
}
|
||||
this.introductionPanel.setAttribute("hidden", "true");
|
||||
this.introductionPanel.setAttribute('hidden', 'true');
|
||||
let existantWebview = this._getCurrentBrowser();
|
||||
if (existantWebview) {
|
||||
existantWebview.docShellIsActive = true;
|
||||
existantWebview.removeAttribute("hidden");
|
||||
document.getElementById("zen-sidebar-web-panel-title").textContent =
|
||||
existantWebview.contentTitle;
|
||||
existantWebview.removeAttribute('hidden');
|
||||
document.getElementById('zen-sidebar-web-panel-title').textContent = existantWebview.contentTitle;
|
||||
return;
|
||||
}
|
||||
let data = this._getWebPanelData(this._currentPanel);
|
||||
let browser = this._createWebPanelBrowser(data);
|
||||
let browserContainers = document.getElementById(
|
||||
"zen-sidebar-web-panel-browser-containers"
|
||||
);
|
||||
let browserContainers = document.getElementById('zen-sidebar-web-panel-browser-containers');
|
||||
browserContainers.appendChild(browser);
|
||||
if (data.ua) {
|
||||
browser.browsingContext.customUserAgent = this.DEFAULT_MOBILE_USER_AGENT;
|
||||
|
@ -426,26 +389,24 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
_createWebPanelBrowser(data) {
|
||||
const titleContainer = document.getElementById(
|
||||
"zen-sidebar-web-panel-title"
|
||||
);
|
||||
titleContainer.textContent = "Loading...";
|
||||
const titleContainer = document.getElementById('zen-sidebar-web-panel-title');
|
||||
titleContainer.textContent = 'Loading...';
|
||||
let browser = gBrowser.createBrowser({});
|
||||
browser.setAttribute("disablefullscreen", "true");
|
||||
browser.setAttribute("src", data.url);
|
||||
browser.setAttribute("zen-sidebar-id", data.id);
|
||||
browser.setAttribute("autoscroll", "false");
|
||||
browser.setAttribute("autocompletepopup", "PopupAutoComplete");
|
||||
browser.setAttribute("contextmenu", "contentAreaContextMenu");
|
||||
browser.setAttribute('disablefullscreen', 'true');
|
||||
browser.setAttribute('src', data.url);
|
||||
browser.setAttribute('zen-sidebar-id', data.id);
|
||||
browser.setAttribute('autoscroll', 'false');
|
||||
browser.setAttribute('autocompletepopup', 'PopupAutoComplete');
|
||||
browser.setAttribute('contextmenu', 'contentAreaContextMenu');
|
||||
browser.addEventListener(
|
||||
"pagetitlechanged",
|
||||
'pagetitlechanged',
|
||||
function (event) {
|
||||
let browser = event.target;
|
||||
let title = browser.contentTitle;
|
||||
if (!title) {
|
||||
return;
|
||||
}
|
||||
let id = browser.getAttribute("zen-sidebar-id");
|
||||
let id = browser.getAttribute('zen-sidebar-id');
|
||||
if (id === this._currentPanel) {
|
||||
titleContainer.textContent = title;
|
||||
}
|
||||
|
@ -456,15 +417,13 @@ var gZenBrowserManagerSidebar = {
|
|||
|
||||
_getWebPanelIcon(url, element) {
|
||||
let { preferredURI } = Services.uriFixup.getFixupURIInfo(url);
|
||||
element.setAttribute("image", `page-icon:${preferredURI.spec}`);
|
||||
fetch(
|
||||
`https://s2.googleusercontent.com/s2/favicons?domain_url=${preferredURI.spec}`
|
||||
).then(async (response) => {
|
||||
element.setAttribute('image', `page-icon:${preferredURI.spec}`);
|
||||
fetch(`https://s2.googleusercontent.com/s2/favicons?domain_url=${preferredURI.spec}`).then(async (response) => {
|
||||
if (response.ok) {
|
||||
let blob = await response.blob();
|
||||
let reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
element.setAttribute("image", reader.result);
|
||||
element.setAttribute('image', reader.result);
|
||||
};
|
||||
reader.readAsDataURL(blob);
|
||||
}
|
||||
|
@ -472,7 +431,7 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
_getBrowserById(id) {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
return sidebar.querySelector(`browser[zen-sidebar-id="${id}"]`);
|
||||
},
|
||||
|
||||
|
@ -515,8 +474,8 @@ var gZenBrowserManagerSidebar = {
|
|||
},
|
||||
|
||||
togglePinned(elem) {
|
||||
let sidebar = document.getElementById("zen-sidebar-web-panel");
|
||||
if (sidebar.hasAttribute("pinned")) {
|
||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
if (sidebar.hasAttribute('pinned')) {
|
||||
this._removePinnedFromElements();
|
||||
} else {
|
||||
this._setPinnedToElements();
|
||||
|
@ -526,27 +485,21 @@ var gZenBrowserManagerSidebar = {
|
|||
|
||||
get sidebarElement() {
|
||||
if (!this._sidebarElement) {
|
||||
this._sidebarElement = document.getElementById(
|
||||
"zen-sidebar-panels-sites"
|
||||
);
|
||||
this._sidebarElement = document.getElementById('zen-sidebar-panels-sites');
|
||||
}
|
||||
return this._sidebarElement;
|
||||
},
|
||||
|
||||
get splitterElement() {
|
||||
if (!this._splitterElement) {
|
||||
this._splitterElement = document.getElementById(
|
||||
"zen-sidebar-web-panel-splitter"
|
||||
);
|
||||
this._splitterElement = document.getElementById('zen-sidebar-web-panel-splitter');
|
||||
}
|
||||
return this._splitterElement;
|
||||
},
|
||||
|
||||
get hSplitterElement() {
|
||||
if (!this._hSplitterElement) {
|
||||
this._hSplitterElement = document.getElementById(
|
||||
"zen-sidebar-web-panel-hsplitter"
|
||||
);
|
||||
this._hSplitterElement = document.getElementById('zen-sidebar-web-panel-hsplitter');
|
||||
}
|
||||
return this._hSplitterElement;
|
||||
},
|
||||
|
@ -555,45 +508,33 @@ var gZenBrowserManagerSidebar = {
|
|||
|
||||
updateContextMenu(aPopupMenu) {
|
||||
let panel =
|
||||
aPopupMenu.triggerNode &&
|
||||
(aPopupMenu.triggerNode ||
|
||||
aPopupMenu.triggerNode.closest("toolbarbutton[zen-sidebar-id]"));
|
||||
aPopupMenu.triggerNode && (aPopupMenu.triggerNode || aPopupMenu.triggerNode.closest('toolbarbutton[zen-sidebar-id]'));
|
||||
if (!panel) {
|
||||
return;
|
||||
}
|
||||
let id = panel.getAttribute("zen-sidebar-id");
|
||||
let id = panel.getAttribute('zen-sidebar-id');
|
||||
this.contextTab = id;
|
||||
let data = this._getWebPanelData(id);
|
||||
let browser = this._getBrowserById(id);
|
||||
let isMuted = browser && browser.audioMuted;
|
||||
let mutedContextItem = document.getElementById(
|
||||
"context_zenToggleMuteWebPanel"
|
||||
);
|
||||
let mutedContextItem = document.getElementById('context_zenToggleMuteWebPanel');
|
||||
document.l10n.setAttributes(
|
||||
mutedContextItem,
|
||||
!isMuted
|
||||
? "zen-web-side-panel-context-mute-panel"
|
||||
: "zen-web-side-panel-context-unmute-panel"
|
||||
!isMuted ? 'zen-web-side-panel-context-mute-panel' : 'zen-web-side-panel-context-unmute-panel'
|
||||
);
|
||||
if (!isMuted) {
|
||||
mutedContextItem.setAttribute("muted", "true");
|
||||
mutedContextItem.setAttribute('muted', 'true');
|
||||
} else {
|
||||
mutedContextItem.removeAttribute("muted");
|
||||
mutedContextItem.removeAttribute('muted');
|
||||
}
|
||||
document.l10n.setAttributes(
|
||||
document.getElementById("context_zenToogleUAWebPanel"),
|
||||
data.ua
|
||||
? "zen-web-side-panel-context-disable-ua"
|
||||
: "zen-web-side-panel-context-enable-ua"
|
||||
document.getElementById('context_zenToogleUAWebPanel'),
|
||||
data.ua ? 'zen-web-side-panel-context-disable-ua' : 'zen-web-side-panel-context-enable-ua'
|
||||
);
|
||||
if (!browser) {
|
||||
document
|
||||
.getElementById("context_zenUnloadWebPanel")
|
||||
.setAttribute("disabled", "true");
|
||||
document.getElementById('context_zenUnloadWebPanel').setAttribute('disabled', 'true');
|
||||
} else {
|
||||
document
|
||||
.getElementById("context_zenUnloadWebPanel")
|
||||
.removeAttribute("disabled");
|
||||
document.getElementById('context_zenUnloadWebPanel').removeAttribute('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -617,13 +558,10 @@ var gZenBrowserManagerSidebar = {
|
|||
|
||||
contextToggleUserAgent() {
|
||||
let browser = this._getBrowserById(this.contextTab);
|
||||
browser.browsingContext.customUserAgent = browser.browsingContext
|
||||
.customUserAgent
|
||||
? null
|
||||
: this.DEFAULT_MOBILE_USER_AGENT;
|
||||
browser.browsingContext.customUserAgent = browser.browsingContext.customUserAgent ? null : this.DEFAULT_MOBILE_USER_AGENT;
|
||||
let data = this.sidebarData;
|
||||
data.data[this.contextTab].ua = !data.data[this.contextTab].ua;
|
||||
Services.prefs.setStringPref("zen.sidebar.data", JSON.stringify(data));
|
||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||
browser.reload();
|
||||
},
|
||||
|
||||
|
@ -634,42 +572,35 @@ var gZenBrowserManagerSidebar = {
|
|||
let browser = this._getBrowserById(this.contextTab);
|
||||
if (browser) {
|
||||
browser.remove();
|
||||
document.getElementById("zen-sidebar-web-panel-title").textContent = "";
|
||||
document.getElementById('zen-sidebar-web-panel-title').textContent = '';
|
||||
}
|
||||
this._currentPanel = null;
|
||||
this._lastOpenedPanel = null;
|
||||
this.update();
|
||||
Services.prefs.setStringPref("zen.sidebar.data", JSON.stringify(data));
|
||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||
},
|
||||
|
||||
contextUnload() {
|
||||
let browser = this._getBrowserById(this.contextTab);
|
||||
browser.remove();
|
||||
document.getElementById("zen-sidebar-web-panel-title").textContent = "";
|
||||
document.getElementById('zen-sidebar-web-panel-title').textContent = '';
|
||||
this._closeSidebarPanel();
|
||||
this.close();
|
||||
this._lastOpenedPanel = null;
|
||||
},
|
||||
|
||||
insertIntoContextMenu() {
|
||||
const sibling = document.getElementById("context-stripOnShareLink");
|
||||
const menuitem = document.createXULElement("menuitem");
|
||||
menuitem.setAttribute("id", "context-zenAddToWebPanel");
|
||||
menuitem.setAttribute("hidden", "true");
|
||||
menuitem.setAttribute(
|
||||
"oncommand",
|
||||
"gZenBrowserManagerSidebar.addPanelFromContextMenu();"
|
||||
);
|
||||
menuitem.setAttribute(
|
||||
"data-l10n-id",
|
||||
"zen-web-side-panel-context-add-to-panel"
|
||||
);
|
||||
sibling.insertAdjacentElement("afterend", menuitem);
|
||||
const sibling = document.getElementById('context-stripOnShareLink');
|
||||
const menuitem = document.createXULElement('menuitem');
|
||||
menuitem.setAttribute('id', 'context-zenAddToWebPanel');
|
||||
menuitem.setAttribute('hidden', 'true');
|
||||
menuitem.setAttribute('oncommand', 'gZenBrowserManagerSidebar.addPanelFromContextMenu();');
|
||||
menuitem.setAttribute('data-l10n-id', 'zen-web-side-panel-context-add-to-panel');
|
||||
sibling.insertAdjacentElement('afterend', menuitem);
|
||||
},
|
||||
|
||||
addPanelFromContextMenu() {
|
||||
const url =
|
||||
gContextMenu.linkURL || gContextMenu.target.ownerDocument.location.href;
|
||||
const url = gContextMenu.linkURL || gContextMenu.target.ownerDocument.location.href;
|
||||
this._createNewPanel(url);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
const kZenAccentColorConfigKey = "zen.theme.accent-color";
|
||||
const kZenAccentColorConfigKey = 'zen.theme.accent-color';
|
||||
|
||||
var gZenThemeBuilder = {
|
||||
init() {
|
||||
|
@ -14,7 +13,7 @@ var gZenThemeBuilder = {
|
|||
if (this.__builderWrapper) {
|
||||
return this.__builderWrapper;
|
||||
}
|
||||
this.__builderWrapper = document.getElementById("zen-theme-builder-wrapper");
|
||||
this.__builderWrapper = document.getElementById('zen-theme-builder-wrapper');
|
||||
return this.__builderWrapper;
|
||||
},
|
||||
|
||||
|
@ -24,7 +23,7 @@ var gZenThemeBuilder = {
|
|||
return;
|
||||
}
|
||||
|
||||
console.info("gZenThemeBuilder: init builder UI");
|
||||
console.info('gZenThemeBuilder: init builder UI');
|
||||
|
||||
const kTemplate = `
|
||||
<html:div id="zen-theme-builder">
|
||||
|
@ -44,20 +43,22 @@ var gZenThemeBuilder = {
|
|||
var w = ctx.canvas.width,
|
||||
h = ctx.canvas.height,
|
||||
data = ctx.getImageData(0, 0, w, h), /// get image data
|
||||
buffer = data.data, /// and its pixel buffer
|
||||
len = buffer.length, /// cache length
|
||||
x, y = 0, p, px; /// for iterating
|
||||
buffer = data.data, /// and its pixel buffer
|
||||
len = buffer.length, /// cache length
|
||||
x,
|
||||
y = 0,
|
||||
p,
|
||||
px; /// for iterating
|
||||
/// iterating x/y instead of forward to get position the easy way
|
||||
for(;y < h; y++) {
|
||||
for (; y < h; y++) {
|
||||
/// common value for all x
|
||||
p = y * 4 * w;
|
||||
for(x = 0; x < w; x++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
/// next pixel (skipping 4 bytes as each pixel is RGBA bytes)
|
||||
px = p + x * 4;
|
||||
/// if red component match check the others
|
||||
if (buffer[px] === color[0]) {
|
||||
if (buffer[px + 1] === color[1] &&
|
||||
buffer[px + 2] === color[2]) {
|
||||
if (buffer[px + 1] === color[1] && buffer[px + 2] === color[2]) {
|
||||
return [x, y];
|
||||
}
|
||||
}
|
||||
|
@ -68,30 +69,26 @@ var gZenThemeBuilder = {
|
|||
|
||||
_hexToRgb(hex) {
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return [
|
||||
parseInt(result[1], 16),
|
||||
parseInt(result[2], 16),
|
||||
parseInt(result[3], 16)
|
||||
]
|
||||
return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)];
|
||||
},
|
||||
|
||||
_componentToHex(c) {
|
||||
var hex = c.toString(16);
|
||||
return hex.length == 1 ? "0" + hex : hex;
|
||||
},
|
||||
return hex.length == 1 ? '0' + hex : hex;
|
||||
},
|
||||
|
||||
_rgbToHex(r, g, b) {
|
||||
return "#" + this._componentToHex(r) + this._componentToHex(g) + this._componentToHex(b);
|
||||
return '#' + this._componentToHex(r) + this._componentToHex(g) + this._componentToHex(b);
|
||||
},
|
||||
|
||||
_initColorPicker() {
|
||||
const canvas = document.getElementById("zen-theme-builder-color-picker-canvas");
|
||||
const thumb = document.getElementById("zen-theme-builder-color-picker-thumb");
|
||||
const canvas = document.getElementById('zen-theme-builder-color-picker-canvas');
|
||||
const thumb = document.getElementById('zen-theme-builder-color-picker-thumb');
|
||||
|
||||
// A all the main colors are all blended together towards the center.
|
||||
// But we also add some random gradients to make it look more interesting.
|
||||
// Instead of using a simple gradient, we use a radial gradient.
|
||||
const ctx = canvas.getContext("2d");
|
||||
const ctx = canvas.getContext('2d');
|
||||
const size = 180;
|
||||
canvas.width = size;
|
||||
canvas.height = size;
|
||||
|
@ -115,15 +112,15 @@ var gZenThemeBuilder = {
|
|||
const radialGradient = ctx.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2);
|
||||
radialGradient.addColorStop(0, 'rgba(255,255,255,1)');
|
||||
radialGradient.addColorStop(1, 'rgba(255,255,255,0)');
|
||||
|
||||
|
||||
ctx.fillStyle = gradient;
|
||||
ctx.fillRect(0, 0, size, size);
|
||||
|
||||
|
||||
//ctx.fillStyle = radialGradient;
|
||||
//ctx.fillRect(0, 0, size, size);
|
||||
|
||||
// Add the thumb.
|
||||
const accentColor = Services.prefs.getStringPref(kZenAccentColorConfigKey, "#aac7ff");
|
||||
const accentColor = Services.prefs.getStringPref(kZenAccentColorConfigKey, '#aac7ff');
|
||||
const pos = this._getPositionFromColor(ctx, this._hexToRgb(accentColor));
|
||||
|
||||
let x = pos ? pos[0] : center;
|
||||
|
@ -132,23 +129,23 @@ var gZenThemeBuilder = {
|
|||
thumb.style.left = `${x}px`;
|
||||
thumb.style.top = `${y}px`;
|
||||
|
||||
thumb.addEventListener("mousedown", this._handleThumbMouseDown.bind(this));
|
||||
document.addEventListener("mouseup", this._handleThumbMouseUp.bind(this));
|
||||
thumb.addEventListener('mousedown', this._handleThumbMouseDown.bind(this));
|
||||
document.addEventListener('mouseup', this._handleThumbMouseUp.bind(this));
|
||||
},
|
||||
|
||||
_handleThumbMouseDown(e) {
|
||||
document.addEventListener("mousemove", this._mouseMoveListener);
|
||||
document.addEventListener('mousemove', this._mouseMoveListener);
|
||||
},
|
||||
|
||||
_handleThumbMouseUp(e) {
|
||||
document.removeEventListener("mousemove", this._mouseMoveListener);
|
||||
document.removeEventListener('mousemove', this._mouseMoveListener);
|
||||
},
|
||||
|
||||
_handleThumbMouseMove(e) {
|
||||
const kThumbOffset = 15;
|
||||
const deck = document.getElementById("zen-theme-builder-color-picker-deck");
|
||||
const deck = document.getElementById('zen-theme-builder-color-picker-deck');
|
||||
|
||||
const thumb = document.getElementById("zen-theme-builder-color-picker-thumb");
|
||||
const thumb = document.getElementById('zen-theme-builder-color-picker-thumb');
|
||||
const rect = deck.getBoundingClientRect();
|
||||
let x = e.clientX - rect.left;
|
||||
let y = e.clientY - rect.top;
|
||||
|
@ -169,8 +166,8 @@ var gZenThemeBuilder = {
|
|||
thumb.style.left = `${x}px`;
|
||||
thumb.style.top = `${y}px`;
|
||||
|
||||
const canvas = document.getElementById("zen-theme-builder-color-picker-canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
const canvas = document.getElementById('zen-theme-builder-color-picker-canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const imageData = ctx.getImageData(x, y, 1, 1);
|
||||
|
||||
// Update the accent color.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
const kZenStylesheetThemeHeader = `
|
||||
/* Zen Themes - Generated by ZenThemeImporter.
|
||||
* DO NOT EDIT THIS FILE DIRECTLY!
|
||||
|
@ -21,7 +20,7 @@ var gZenStylesheetManager = {
|
|||
},
|
||||
|
||||
getThemeCSS(theme) {
|
||||
let css = "\n";
|
||||
let css = '\n';
|
||||
if (theme._readmeURL) {
|
||||
css += `/* Name: ${theme.name} */\n`;
|
||||
css += `/* Description: ${theme.description} */\n`;
|
||||
|
@ -30,51 +29,40 @@ var gZenStylesheetManager = {
|
|||
}
|
||||
css += `@import url("${theme._chromeURL}");\n`;
|
||||
return css;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var gZenThemeImporter = new class {
|
||||
var gZenThemeImporter = new (class {
|
||||
constructor() {
|
||||
console.info("ZenThemeImporter: Initiating Zen theme importer");
|
||||
console.info('ZenThemeImporter: Initiating Zen theme importer');
|
||||
try {
|
||||
window.SessionStore.promiseInitialized.then(() => {
|
||||
this.insertStylesheet();
|
||||
});
|
||||
console.info("ZenThemeImporter: Zen theme imported");
|
||||
console.info('ZenThemeImporter: Zen theme imported');
|
||||
} catch (e) {
|
||||
console.error("ZenThemeImporter: Error importing Zen theme: ", e);
|
||||
console.error('ZenThemeImporter: Error importing Zen theme: ', e);
|
||||
}
|
||||
Services.prefs.addObserver("zen.themes.updated-value-observer", this.rebuildThemeStylesheet.bind(this), false);
|
||||
Services.prefs.addObserver('zen.themes.updated-value-observer', this.rebuildThemeStylesheet.bind(this), false);
|
||||
}
|
||||
|
||||
get sss() {
|
||||
if (!this._sss) {
|
||||
this._sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
||||
this._sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
|
||||
}
|
||||
return this._sss;
|
||||
}
|
||||
|
||||
get styleSheetPath() {
|
||||
return PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"chrome",
|
||||
"zen-themes.css"
|
||||
);
|
||||
return PathUtils.join(PathUtils.profileDir, 'chrome', 'zen-themes.css');
|
||||
}
|
||||
|
||||
get themesRootPath() {
|
||||
return PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"chrome",
|
||||
"zen-themes"
|
||||
);
|
||||
return PathUtils.join(PathUtils.profileDir, 'chrome', 'zen-themes');
|
||||
}
|
||||
|
||||
get themesDataFile() {
|
||||
return PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"zen-themes.json"
|
||||
);
|
||||
return PathUtils.join(PathUtils.profileDir, 'zen-themes.json');
|
||||
}
|
||||
|
||||
getThemeFolder(theme) {
|
||||
|
@ -104,7 +92,7 @@ var gZenThemeImporter = new class {
|
|||
}
|
||||
|
||||
getStylesheetURIForTheme(theme) {
|
||||
return Services.io.newFileURI(new FileUtils.File(PathUtils.join(this.getThemeFolder(theme), "chrome.css")));
|
||||
return Services.io.newFileURI(new FileUtils.File(PathUtils.join(this.getThemeFolder(theme), 'chrome.css')));
|
||||
}
|
||||
|
||||
insertStylesheet() {
|
||||
|
@ -124,7 +112,7 @@ var gZenThemeImporter = new class {
|
|||
}
|
||||
|
||||
async writeStylesheet() {
|
||||
const themes = []
|
||||
const themes = [];
|
||||
this._themes = null;
|
||||
for (let theme of Object.values(await this.getThemes())) {
|
||||
theme._chromeURL = this.getStylesheetURIForTheme(theme).spec;
|
||||
|
@ -132,4 +120,4 @@ var gZenThemeImporter = new class {
|
|||
}
|
||||
await gZenStylesheetManager.writeStylesheet(this.styleSheetPath, themes);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
var gZenViewSplitter = new class {
|
||||
var gZenViewSplitter = new (class {
|
||||
constructor() {
|
||||
this._data = [];
|
||||
this.currentView = -1;
|
||||
|
@ -7,22 +6,22 @@ var gZenViewSplitter = new class {
|
|||
this.__modifierElement = null;
|
||||
this.__hasSetMenuListener = false;
|
||||
|
||||
window.addEventListener("TabClose", this.handleTabClose.bind(this));
|
||||
window.addEventListener('TabClose', this.handleTabClose.bind(this));
|
||||
this.initializeContextMenu();
|
||||
this.insertPageActionButton();
|
||||
this.insertIntoContextMenu();
|
||||
}
|
||||
|
||||
insertIntoContextMenu() {
|
||||
const sibling = document.getElementById("context-stripOnShareLink");
|
||||
const menuitem = document.createXULElement("menuitem");
|
||||
menuitem.setAttribute("id", "context-zenSplitLink");
|
||||
menuitem.setAttribute("hidden", "true");
|
||||
menuitem.setAttribute("oncommand", "gZenViewSplitter.splitLinkInNewTab();");
|
||||
menuitem.setAttribute("data-l10n-id", "zen-split-link");
|
||||
sibling.insertAdjacentElement("afterend", document.createXULElement("menuseparator"));
|
||||
sibling.insertAdjacentElement("afterend", menuitem);
|
||||
sibling.insertAdjacentElement("afterend", document.createXULElement("menuseparator"));
|
||||
const sibling = document.getElementById('context-stripOnShareLink');
|
||||
const menuitem = document.createXULElement('menuitem');
|
||||
menuitem.setAttribute('id', 'context-zenSplitLink');
|
||||
menuitem.setAttribute('hidden', 'true');
|
||||
menuitem.setAttribute('oncommand', 'gZenViewSplitter.splitLinkInNewTab();');
|
||||
menuitem.setAttribute('data-l10n-id', 'zen-split-link');
|
||||
sibling.insertAdjacentElement('afterend', document.createXULElement('menuseparator'));
|
||||
sibling.insertAdjacentElement('afterend', menuitem);
|
||||
sibling.insertAdjacentElement('afterend', document.createXULElement('menuseparator'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +30,7 @@ var gZenViewSplitter = new class {
|
|||
*/
|
||||
handleTabClose(event) {
|
||||
const tab = event.target;
|
||||
const groupIndex = this._data.findIndex(group => group.tabs.includes(tab));
|
||||
const groupIndex = this._data.findIndex((group) => group.tabs.includes(tab));
|
||||
if (groupIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -68,14 +67,14 @@ var gZenViewSplitter = new class {
|
|||
resetTabState(tab, forUnsplit) {
|
||||
tab.splitView = false;
|
||||
tab.linkedBrowser.zenModeActive = false;
|
||||
const container = tab.linkedBrowser.closest(".browserSidebarContainer");
|
||||
container.removeAttribute("zen-split");
|
||||
container.removeAttribute("style");
|
||||
const container = tab.linkedBrowser.closest('.browserSidebarContainer');
|
||||
container.removeAttribute('zen-split');
|
||||
container.removeAttribute('style');
|
||||
|
||||
if (!forUnsplit) {
|
||||
tab.linkedBrowser.docShellIsActive = false;
|
||||
} else {
|
||||
container.style.gridArea = "1 / 1";
|
||||
container.style.gridArea = '1 / 1';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,24 +99,21 @@ var gZenViewSplitter = new class {
|
|||
}
|
||||
|
||||
this.currentView = -1;
|
||||
this.tabBrowserPanel.removeAttribute("zen-split-view");
|
||||
this.tabBrowserPanel.style.gridTemplateAreas = "";
|
||||
this.tabBrowserPanel.removeAttribute('zen-split-view');
|
||||
this.tabBrowserPanel.style.gridTemplateAreas = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* context menu item display update
|
||||
*/
|
||||
insetUpdateContextMenuItems() {
|
||||
const contentAreaContextMenu = document.getElementById("tabContextMenu");
|
||||
contentAreaContextMenu.addEventListener("popupshowing", () => {
|
||||
const contentAreaContextMenu = document.getElementById('tabContextMenu');
|
||||
contentAreaContextMenu.addEventListener('popupshowing', () => {
|
||||
const tabCountInfo = JSON.stringify({
|
||||
tabCount: window.gBrowser.selectedTabs.length,
|
||||
});
|
||||
document
|
||||
.getElementById("context_zenSplitTabs")
|
||||
.setAttribute("data-l10n-args", tabCountInfo);
|
||||
document.getElementById("context_zenSplitTabs").disabled =
|
||||
!this.contextCanSplitTabs();
|
||||
document.getElementById('context_zenSplitTabs').setAttribute('data-l10n-args', tabCountInfo);
|
||||
document.getElementById('context_zenSplitTabs').disabled = !this.contextCanSplitTabs();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -132,7 +128,7 @@ var gZenViewSplitter = new class {
|
|||
oncommand="gZenViewSplitter.contextSplitTabs();"/>
|
||||
<menuseparator/>
|
||||
`);
|
||||
document.getElementById("context_closeDuplicateTabs").after(element);
|
||||
document.getElementById('context_closeDuplicateTabs').after(element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,7 +153,7 @@ var gZenViewSplitter = new class {
|
|||
class="urlbar-icon"/>
|
||||
</hbox>
|
||||
`);
|
||||
document.getElementById("star-button-box").after(element);
|
||||
document.getElementById('star-button-box').after(element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,7 +163,7 @@ var gZenViewSplitter = new class {
|
|||
*/
|
||||
get tabBrowserPanel() {
|
||||
if (!this._tabBrowserPanel) {
|
||||
this._tabBrowserPanel = document.getElementById("tabbrowser-tabpanels");
|
||||
this._tabBrowserPanel = document.getElementById('tabbrowser-tabpanels');
|
||||
}
|
||||
return this._tabBrowserPanel;
|
||||
}
|
||||
|
@ -176,9 +172,7 @@ var gZenViewSplitter = new class {
|
|||
* Splits a link in a new tab.
|
||||
*/
|
||||
splitLinkInNewTab() {
|
||||
const url =
|
||||
window.gContextMenu.linkURL ||
|
||||
window.gContextMenu.target.ownerDocument.location.href;
|
||||
const url = window.gContextMenu.linkURL || window.gContextMenu.target.ownerDocument.location.href;
|
||||
const currentTab = window.gBrowser.selectedTab;
|
||||
const newTab = this.openAndSwitchToTab(url);
|
||||
this.splitTabs([currentTab, newTab]);
|
||||
|
@ -229,16 +223,14 @@ var gZenViewSplitter = new class {
|
|||
* @param {Tab[]} tabs - The tabs to split.
|
||||
* @param {string} gridType - The type of grid layout.
|
||||
*/
|
||||
splitTabs(tabs, gridType = "grid") {
|
||||
splitTabs(tabs, gridType = 'grid') {
|
||||
if (tabs.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingSplitTab = tabs.find(tab => tab.splitView);
|
||||
const existingSplitTab = tabs.find((tab) => tab.splitView);
|
||||
if (existingSplitTab) {
|
||||
const groupIndex = this._data.findIndex(group =>
|
||||
group.tabs.includes(existingSplitTab)
|
||||
);
|
||||
const groupIndex = this._data.findIndex((group) => group.tabs.includes(existingSplitTab));
|
||||
if (groupIndex >= 0) {
|
||||
// Add any tabs that are not already in the group
|
||||
for (const tab of tabs) {
|
||||
|
@ -266,12 +258,8 @@ var gZenViewSplitter = new class {
|
|||
* @param {Tab} tab - The tab to update the split view for.
|
||||
*/
|
||||
updateSplitView(tab) {
|
||||
const splitData = this._data.find(group => group.tabs.includes(tab));
|
||||
if (
|
||||
!splitData ||
|
||||
(this.currentView >= 0 &&
|
||||
!this._data[this.currentView].tabs.includes(tab))
|
||||
) {
|
||||
const splitData = this._data.find((group) => group.tabs.includes(tab));
|
||||
if (!splitData || (this.currentView >= 0 && !this._data[this.currentView].tabs.includes(tab))) {
|
||||
this.updateSplitViewButton(true);
|
||||
if (this.currentView >= 0) {
|
||||
this.deactivateSplitView();
|
||||
|
@ -289,12 +277,12 @@ var gZenViewSplitter = new class {
|
|||
*/
|
||||
deactivateSplitView() {
|
||||
for (const tab of this._data[this.currentView].tabs) {
|
||||
const container = tab.linkedBrowser.closest(".browserSidebarContainer");
|
||||
const container = tab.linkedBrowser.closest('.browserSidebarContainer');
|
||||
this.resetContainerStyle(container);
|
||||
container.removeEventListener("click", this.handleTabClick);
|
||||
container.removeEventListener('click', this.handleTabClick);
|
||||
}
|
||||
this.tabBrowserPanel.removeAttribute("zen-split-view");
|
||||
this.tabBrowserPanel.style.gridTemplateAreas = "";
|
||||
this.tabBrowserPanel.removeAttribute('zen-split-view');
|
||||
this.tabBrowserPanel.style.gridTemplateAreas = '';
|
||||
this.setTabsDocShellState(this._data[this.currentView].tabs, false);
|
||||
this.currentView = -1;
|
||||
}
|
||||
|
@ -306,10 +294,10 @@ var gZenViewSplitter = new class {
|
|||
* @param {Tab} activeTab - The active tab.
|
||||
*/
|
||||
activateSplitView(splitData, activeTab) {
|
||||
this.tabBrowserPanel.setAttribute("zen-split-view", "true");
|
||||
this.tabBrowserPanel.setAttribute('zen-split-view', 'true');
|
||||
this.currentView = this._data.indexOf(splitData);
|
||||
|
||||
const gridType = splitData.gridType || "grid";
|
||||
const gridType = splitData.gridType || 'grid';
|
||||
this.applyGridLayout(splitData.tabs, gridType, activeTab);
|
||||
|
||||
this.setTabsDocShellState(splitData.tabs, true);
|
||||
|
@ -329,7 +317,7 @@ var gZenViewSplitter = new class {
|
|||
|
||||
tabs.forEach((tab, index) => {
|
||||
tab.splitView = true;
|
||||
const container = tab.linkedBrowser.closest(".browserSidebarContainer");
|
||||
const container = tab.linkedBrowser.closest('.browserSidebarContainer');
|
||||
this.styleContainer(container, tab === activeTab, index, gridType);
|
||||
});
|
||||
}
|
||||
|
@ -342,16 +330,16 @@ var gZenViewSplitter = new class {
|
|||
* @returns {string} The calculated grid areas.
|
||||
*/
|
||||
calculateGridAreas(tabs, gridType) {
|
||||
if (gridType === "grid") {
|
||||
if (gridType === 'grid') {
|
||||
return this.calculateGridAreasForGrid(tabs);
|
||||
}
|
||||
if (gridType === "vsep") {
|
||||
return `'${tabs.map((_, j) => `tab${j + 1}`).join(" ")}'`;
|
||||
if (gridType === 'vsep') {
|
||||
return `'${tabs.map((_, j) => `tab${j + 1}`).join(' ')}'`;
|
||||
}
|
||||
if (gridType === "hsep") {
|
||||
return tabs.map((_, j) => `'tab${j + 1}'`).join(" ");
|
||||
if (gridType === 'hsep') {
|
||||
return tabs.map((_, j) => `'tab${j + 1}'`).join(' ');
|
||||
}
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -361,7 +349,7 @@ var gZenViewSplitter = new class {
|
|||
* @returns {string} The calculated grid areas.
|
||||
*/
|
||||
calculateGridAreasForGrid(tabs) {
|
||||
const rows = ["", ""];
|
||||
const rows = ['', ''];
|
||||
tabs.forEach((_, i) => {
|
||||
if (i % 2 === 0) {
|
||||
rows[0] += ` tab${i + 1}`;
|
||||
|
@ -390,12 +378,12 @@ var gZenViewSplitter = new class {
|
|||
* @param {string} gridType - The type of grid layout.
|
||||
*/
|
||||
styleContainer(container, isActive, index, gridType) {
|
||||
container.removeAttribute("zen-split-active");
|
||||
container.removeAttribute('zen-split-active');
|
||||
if (isActive) {
|
||||
container.setAttribute("zen-split-active", "true");
|
||||
container.setAttribute('zen-split-active', 'true');
|
||||
}
|
||||
container.setAttribute("zen-split-anim", "true");
|
||||
container.addEventListener("click", this.handleTabClick);
|
||||
container.setAttribute('zen-split-anim', 'true');
|
||||
container.addEventListener('click', this.handleTabClick);
|
||||
|
||||
container.style.gridArea = `tab${index + 1}`;
|
||||
}
|
||||
|
@ -405,11 +393,9 @@ var gZenViewSplitter = new class {
|
|||
*
|
||||
* @param {Event} event - The click event.
|
||||
*/
|
||||
handleTabClick = event => {
|
||||
handleTabClick = (event) => {
|
||||
const container = event.currentTarget;
|
||||
const tab = window.gBrowser.tabs.find(
|
||||
t => t.linkedBrowser.closest(".browserSidebarContainer") === container
|
||||
);
|
||||
const tab = window.gBrowser.tabs.find((t) => t.linkedBrowser.closest('.browserSidebarContainer') === container);
|
||||
if (tab) {
|
||||
window.gBrowser.selectedTab = tab;
|
||||
}
|
||||
|
@ -431,12 +417,12 @@ var gZenViewSplitter = new class {
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
const browser = tab.linkedBrowser.closest(".browserSidebarContainer");
|
||||
const browser = tab.linkedBrowser.closest('.browserSidebarContainer');
|
||||
if (active) {
|
||||
browser.setAttribute("zen-split", "true");
|
||||
browser.setAttribute('zen-split', 'true');
|
||||
} else {
|
||||
browser.removeAttribute("zen-split");
|
||||
browser.removeAttribute("style");
|
||||
browser.removeAttribute('zen-split');
|
||||
browser.removeAttribute('style');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -447,9 +433,9 @@ var gZenViewSplitter = new class {
|
|||
* @param {Element} container - The container element.
|
||||
*/
|
||||
resetContainerStyle(container) {
|
||||
container.removeAttribute("zen-split-active");
|
||||
container.classList.remove("deck-selected");
|
||||
container.style.gridArea = "";
|
||||
container.removeAttribute('zen-split-active');
|
||||
container.classList.remove('deck-selected');
|
||||
container.style.gridArea = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -458,11 +444,11 @@ var gZenViewSplitter = new class {
|
|||
* @param {boolean} hidden - Indicates if the button should be hidden.
|
||||
*/
|
||||
updateSplitViewButton(hidden) {
|
||||
const button = document.getElementById("zen-split-views-box");
|
||||
const button = document.getElementById('zen-split-views-box');
|
||||
if (hidden) {
|
||||
button?.setAttribute("hidden", "true");
|
||||
button?.setAttribute('hidden', 'true');
|
||||
} else {
|
||||
button?.removeAttribute("hidden");
|
||||
button?.removeAttribute('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,7 +459,7 @@ var gZenViewSplitter = new class {
|
|||
*/
|
||||
get modifierElement() {
|
||||
if (!this.__modifierElement) {
|
||||
const wrapper = document.getElementById("template-zen-split-view-modifier");
|
||||
const wrapper = document.getElementById('template-zen-split-view-modifier');
|
||||
const panel = wrapper.content.firstElementChild;
|
||||
wrapper.replaceWith(wrapper.content);
|
||||
this.__modifierElement = panel;
|
||||
|
@ -497,7 +483,7 @@ var gZenViewSplitter = new class {
|
|||
}
|
||||
|
||||
window.PanelMultiView.openPopup(panel, target, {
|
||||
position: "bottomright topright",
|
||||
position: 'bottomright topright',
|
||||
triggerEvent: event,
|
||||
}).catch(console.error);
|
||||
}
|
||||
|
@ -508,16 +494,11 @@ var gZenViewSplitter = new class {
|
|||
* @param {Element} panel - The panel element.
|
||||
*/
|
||||
updatePanelUI(panel) {
|
||||
for (const gridType of ["hsep", "vsep", "grid", "unsplit"]) {
|
||||
const selector = panel.querySelector(
|
||||
`.zen-split-view-modifier-preview.${gridType}`
|
||||
);
|
||||
selector.classList.remove("active");
|
||||
if (
|
||||
this.currentView >= 0 &&
|
||||
this._data[this.currentView].gridType === gridType
|
||||
) {
|
||||
selector.classList.add("active");
|
||||
for (const gridType of ['hsep', 'vsep', 'grid', 'unsplit']) {
|
||||
const selector = panel.querySelector(`.zen-split-view-modifier-preview.${gridType}`);
|
||||
selector.classList.remove('active');
|
||||
if (this.currentView >= 0 && this._data[this.currentView].gridType === gridType) {
|
||||
selector.classList.add('active');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -527,13 +508,9 @@ var gZenViewSplitter = new class {
|
|||
* @param {Element} panel - The panel element
|
||||
*/
|
||||
setupPanelListeners(panel) {
|
||||
for (const gridType of ["hsep", "vsep", "grid", "unsplit"]) {
|
||||
const selector = panel.querySelector(
|
||||
`.zen-split-view-modifier-preview.${gridType}`
|
||||
);
|
||||
selector.addEventListener("click", () =>
|
||||
this.handlePanelSelection(gridType, panel)
|
||||
);
|
||||
for (const gridType of ['hsep', 'vsep', 'grid', 'unsplit']) {
|
||||
const selector = panel.querySelector(`.zen-split-view-modifier-preview.${gridType}`);
|
||||
selector.addEventListener('click', () => this.handlePanelSelection(gridType, panel));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -543,7 +520,7 @@ var gZenViewSplitter = new class {
|
|||
* @param {Element} panel - The panel element
|
||||
*/
|
||||
handlePanelSelection(gridType, panel) {
|
||||
if (gridType === "unsplit") {
|
||||
if (gridType === 'unsplit') {
|
||||
this.unsplitCurrentView();
|
||||
} else {
|
||||
this._data[this.currentView].gridType = gridType;
|
||||
|
@ -581,7 +558,7 @@ var gZenViewSplitter = new class {
|
|||
}
|
||||
|
||||
toggleShortcut(gridType) {
|
||||
if (gridType === "unsplit") {
|
||||
if (gridType === 'unsplit') {
|
||||
this.unsplitCurrentView();
|
||||
return;
|
||||
}
|
||||
|
@ -591,12 +568,18 @@ var gZenViewSplitter = new class {
|
|||
}
|
||||
let nextTabIndex = tabs.indexOf(gBrowser.selectedTab) + 1;
|
||||
if (nextTabIndex >= tabs.length) {
|
||||
nextTabIndex = 0;
|
||||
// Find the first non-hidden tab
|
||||
nextTabIndex = tabs.findIndex((tab) => !tab.hidden);
|
||||
} else if (nextTabIndex < 0) {
|
||||
nextTabIndex = tabs.length - 1;
|
||||
// reverse find the first non-hidden tab
|
||||
nextTabIndex = tabs
|
||||
.slice()
|
||||
.reverse()
|
||||
.findIndex((tab) => !tab.hidden);
|
||||
}
|
||||
const selected_tabs = gBrowser.selectedTab.multiselected
|
||||
? gBrowser.selectedTabs : [gBrowser.selectedTab, tabs[nextTabIndex]];
|
||||
const selected_tabs = gBrowser.selectedTab.multiselected
|
||||
? gBrowser.selectedTabs
|
||||
: [gBrowser.selectedTab, tabs[nextTabIndex]];
|
||||
this.splitTabs(selected_tabs, gridType);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -2,33 +2,27 @@ var ZenWorkspaces = {
|
|||
async init() {
|
||||
let docElement = document.documentElement;
|
||||
if (
|
||||
docElement.getAttribute("chromehidden").includes("toolbar") ||
|
||||
docElement.getAttribute("chromehidden").includes("menubar") ||
|
||||
docElement.hasAttribute("privatebrowsingmode")
|
||||
docElement.getAttribute('chromehidden').includes('toolbar') ||
|
||||
docElement.getAttribute('chromehidden').includes('menubar') ||
|
||||
docElement.hasAttribute('privatebrowsingmode')
|
||||
) {
|
||||
console.warn(
|
||||
"ZenWorkspaces: !!! ZenWorkspaces is disabled in hidden windows !!!",
|
||||
);
|
||||
console.warn('ZenWorkspaces: !!! ZenWorkspaces is disabled in hidden windows !!!');
|
||||
return; // We are in a hidden window, don't initialize ZenWorkspaces
|
||||
}
|
||||
console.info("ZenWorkspaces: Initializing ZenWorkspaces...");
|
||||
console.info('ZenWorkspaces: Initializing ZenWorkspaces...');
|
||||
window.SessionStore.promiseInitialized.then(async () => {
|
||||
await this.initializeWorkspaces();
|
||||
console.info("ZenWorkspaces: ZenWorkspaces initialized");
|
||||
console.info('ZenWorkspaces: ZenWorkspaces initialized');
|
||||
});
|
||||
},
|
||||
|
||||
get workspaceEnabled() {
|
||||
return Services.prefs.getBoolPref("zen.workspaces.enabled", false);
|
||||
return Services.prefs.getBoolPref('zen.workspaces.enabled', false);
|
||||
},
|
||||
|
||||
// Wrorkspaces saving/loading
|
||||
get _storeFile() {
|
||||
return PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"zen-workspaces",
|
||||
"Workspaces.json",
|
||||
);
|
||||
return PathUtils.join(PathUtils.profileDir, 'zen-workspaces', 'Workspaces.json');
|
||||
},
|
||||
|
||||
async _workspaces() {
|
||||
|
@ -46,7 +40,7 @@ var ZenWorkspaces = {
|
|||
throw Error("Shoud've had reloaded the window");
|
||||
} else {
|
||||
this._workspaceCache = null;
|
||||
document.getElementById("zen-workspaces-button")?.remove();
|
||||
document.getElementById('zen-workspaces-button')?.remove();
|
||||
for (let tab of gBrowser.tabs) {
|
||||
gBrowser.showTab(tab);
|
||||
}
|
||||
|
@ -54,28 +48,21 @@ var ZenWorkspaces = {
|
|||
},
|
||||
|
||||
async initializeWorkspaces() {
|
||||
Services.prefs.addObserver(
|
||||
"zen.workspaces.enabled",
|
||||
this.onWorkspacesEnabledChanged.bind(this),
|
||||
);
|
||||
Services.prefs.addObserver('zen.workspaces.enabled', this.onWorkspacesEnabledChanged.bind(this));
|
||||
this.initializeWorkspacesButton();
|
||||
let file = new FileUtils.File(this._storeFile);
|
||||
if (!file.exists()) {
|
||||
await IOUtils.writeJSON(this._storeFile, {});
|
||||
}
|
||||
if (this.workspaceEnabled) {
|
||||
window.addEventListener("TabClose", this.handleTabClose.bind(this));
|
||||
window.addEventListener('TabClose', this.handleTabClose.bind(this));
|
||||
let workspaces = await this._workspaces();
|
||||
if (workspaces.workspaces.length === 0) {
|
||||
await this.createAndSaveWorkspace("Default Workspace", true);
|
||||
await this.createAndSaveWorkspace('Default Workspace', true);
|
||||
} else {
|
||||
let activeWorkspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.used,
|
||||
);
|
||||
let activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used);
|
||||
if (!activeWorkspace) {
|
||||
activeWorkspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.default,
|
||||
);
|
||||
activeWorkspace = workspaces.workspaces.find((workspace) => workspace.default);
|
||||
activeWorkspace.used = true;
|
||||
await this.saveWorkspaces();
|
||||
}
|
||||
|
@ -97,12 +84,10 @@ var ZenWorkspaces = {
|
|||
return; // Bug when closing tabs from the context menu
|
||||
}
|
||||
let tab = event.target;
|
||||
let workspaceID = tab.getAttribute("zen-workspace-id");
|
||||
let workspaceID = tab.getAttribute('zen-workspace-id');
|
||||
// If the tab is the last one in the workspace, create a new tab
|
||||
if (workspaceID) {
|
||||
let tabs = gBrowser.tabs.filter(
|
||||
(tab) => tab.getAttribute("zen-workspace-id") === workspaceID,
|
||||
);
|
||||
let tabs = gBrowser.tabs.filter((tab) => tab.getAttribute('zen-workspace-id') === workspaceID);
|
||||
if (tabs.length === 1) {
|
||||
this._createNewTabForWorkspace({ uuid: workspaceID });
|
||||
// We still need to close other tabs in the workspace
|
||||
|
@ -111,23 +96,21 @@ var ZenWorkspaces = {
|
|||
}
|
||||
},
|
||||
|
||||
_kIcons: ["🏠", "📄", "💹", "💼", "📧", "✅", "👥"],
|
||||
_kIcons: ['🏠', '📄', '💹', '💼', '📧', '✅', '👥'],
|
||||
|
||||
_initializeWorkspaceCreationIcons() {
|
||||
let container = document.getElementById(
|
||||
"PanelUI-zen-workspaces-create-icons-container",
|
||||
);
|
||||
let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container');
|
||||
for (let icon of this._kIcons) {
|
||||
let button = document.createXULElement("toolbarbutton");
|
||||
button.className = "toolbarbutton-1";
|
||||
button.setAttribute("label", icon);
|
||||
let button = document.createXULElement('toolbarbutton');
|
||||
button.className = 'toolbarbutton-1';
|
||||
button.setAttribute('label', icon);
|
||||
button.onclick = ((event) => {
|
||||
let wasSelected = button.hasAttribute("selected");
|
||||
let wasSelected = button.hasAttribute('selected');
|
||||
for (let button of container.children) {
|
||||
button.removeAttribute("selected");
|
||||
button.removeAttribute('selected');
|
||||
}
|
||||
if (!wasSelected) {
|
||||
button.setAttribute("selected", "true");
|
||||
button.setAttribute('selected', 'true');
|
||||
}
|
||||
}).bind(this, button);
|
||||
container.appendChild(button);
|
||||
|
@ -137,16 +120,16 @@ var ZenWorkspaces = {
|
|||
_initializeWorkspaceEditIcons() {
|
||||
let container = this._workspaceEditIconsContainer;
|
||||
for (let icon of this._kIcons) {
|
||||
let button = document.createXULElement("toolbarbutton");
|
||||
button.className = "toolbarbutton-1";
|
||||
button.setAttribute("label", icon);
|
||||
let button = document.createXULElement('toolbarbutton');
|
||||
button.className = 'toolbarbutton-1';
|
||||
button.setAttribute('label', icon);
|
||||
button.onclick = ((event) => {
|
||||
let wasSelected = button.hasAttribute("selected");
|
||||
let wasSelected = button.hasAttribute('selected');
|
||||
for (let button of container.children) {
|
||||
button.removeAttribute("selected");
|
||||
button.removeAttribute('selected');
|
||||
}
|
||||
if (!wasSelected) {
|
||||
button.setAttribute("selected", "true");
|
||||
button.setAttribute('selected', 'true');
|
||||
}
|
||||
this.onWorkspaceEditChange();
|
||||
}).bind(this, button);
|
||||
|
@ -156,18 +139,16 @@ var ZenWorkspaces = {
|
|||
|
||||
async saveWorkspace(workspaceData) {
|
||||
let json = await IOUtils.readJSON(this._storeFile);
|
||||
if (typeof json.workspaces === "undefined") {
|
||||
if (typeof json.workspaces === 'undefined') {
|
||||
json.workspaces = [];
|
||||
}
|
||||
let existing = json.workspaces.findIndex(
|
||||
(workspace) => workspace.uuid === workspaceData.uuid,
|
||||
);
|
||||
let existing = json.workspaces.findIndex((workspace) => workspace.uuid === workspaceData.uuid);
|
||||
if (existing >= 0) {
|
||||
json.workspaces[existing] = workspaceData;
|
||||
} else {
|
||||
json.workspaces.push(workspaceData);
|
||||
}
|
||||
console.info("ZenWorkspaces: Saving workspace", workspaceData);
|
||||
console.info('ZenWorkspaces: Saving workspace', workspaceData);
|
||||
await IOUtils.writeJSON(this._storeFile, json);
|
||||
this._workspaceCache = null;
|
||||
|
||||
|
@ -176,14 +157,10 @@ var ZenWorkspaces = {
|
|||
|
||||
async removeWorkspace(windowID) {
|
||||
let json = await this._workspaces();
|
||||
console.info("ZenWorkspaces: Removing workspace", windowID);
|
||||
await this.changeWorkspace(
|
||||
json.workspaces.find((workspace) => workspace.uuid !== windowID),
|
||||
);
|
||||
console.info('ZenWorkspaces: Removing workspace', windowID);
|
||||
await this.changeWorkspace(json.workspaces.find((workspace) => workspace.uuid !== windowID));
|
||||
this._deleteAllTabsInWorkspace(windowID);
|
||||
json.workspaces = json.workspaces.filter(
|
||||
(workspace) => workspace.uuid !== windowID,
|
||||
);
|
||||
json.workspaces = json.workspaces.filter((workspace) => workspace.uuid !== windowID);
|
||||
await this.unsafeSaveWorkspaces(json);
|
||||
await this._propagateWorkspaceData();
|
||||
await this._updateWorkspacesChangeContextMenu();
|
||||
|
@ -202,60 +179,37 @@ var ZenWorkspaces = {
|
|||
// Workspaces dialog UI management
|
||||
|
||||
openSaveDialog() {
|
||||
let parentPanel = document.getElementById(
|
||||
"PanelUI-zen-workspaces-multiview",
|
||||
);
|
||||
PanelUI.showSubView("PanelUI-zen-workspaces-create", parentPanel);
|
||||
let parentPanel = document.getElementById('PanelUI-zen-workspaces-multiview');
|
||||
PanelUI.showSubView('PanelUI-zen-workspaces-create', parentPanel);
|
||||
},
|
||||
|
||||
async openEditDialog(workspaceUuid) {
|
||||
this._workspaceEditDialog.setAttribute(
|
||||
"data-workspace-uuid",
|
||||
workspaceUuid,
|
||||
);
|
||||
document
|
||||
.getElementById("PanelUI-zen-workspaces-edit-save")
|
||||
.setAttribute("disabled", "true");
|
||||
this._workspaceEditDialog.setAttribute('data-workspace-uuid', workspaceUuid);
|
||||
document.getElementById('PanelUI-zen-workspaces-edit-save').setAttribute('disabled', 'true');
|
||||
let workspaces = (await this._workspaces()).workspaces;
|
||||
let workspaceData = workspaces.find(
|
||||
(workspace) => workspace.uuid === workspaceUuid,
|
||||
);
|
||||
let workspaceData = workspaces.find((workspace) => workspace.uuid === workspaceUuid);
|
||||
this._workspaceEditInput.textContent = workspaceData.name;
|
||||
this._workspaceEditInput.value = workspaceData.name;
|
||||
this._workspaceEditInput.setAttribute(
|
||||
"data-initial-value",
|
||||
workspaceData.name,
|
||||
);
|
||||
this._workspaceEditIconsContainer.setAttribute(
|
||||
"data-initial-value",
|
||||
workspaceData.icon,
|
||||
);
|
||||
document
|
||||
.querySelectorAll(
|
||||
"#PanelUI-zen-workspaces-edit-icons-container toolbarbutton",
|
||||
)
|
||||
.forEach((button) => {
|
||||
if (button.label === workspaceData.icon) {
|
||||
button.setAttribute("selected", "true");
|
||||
} else {
|
||||
button.removeAttribute("selected");
|
||||
}
|
||||
});
|
||||
let parentPanel = document.getElementById(
|
||||
"PanelUI-zen-workspaces-multiview",
|
||||
);
|
||||
PanelUI.showSubView("PanelUI-zen-workspaces-edit", parentPanel);
|
||||
this._workspaceEditInput.setAttribute('data-initial-value', workspaceData.name);
|
||||
this._workspaceEditIconsContainer.setAttribute('data-initial-value', workspaceData.icon);
|
||||
document.querySelectorAll('#PanelUI-zen-workspaces-edit-icons-container toolbarbutton').forEach((button) => {
|
||||
if (button.label === workspaceData.icon) {
|
||||
button.setAttribute('selected', 'true');
|
||||
} else {
|
||||
button.removeAttribute('selected');
|
||||
}
|
||||
});
|
||||
let parentPanel = document.getElementById('PanelUI-zen-workspaces-multiview');
|
||||
PanelUI.showSubView('PanelUI-zen-workspaces-edit', parentPanel);
|
||||
},
|
||||
|
||||
closeWorkspacesSubView() {
|
||||
let parentPanel = document.getElementById(
|
||||
"PanelUI-zen-workspaces-multiview",
|
||||
);
|
||||
let parentPanel = document.getElementById('PanelUI-zen-workspaces-multiview');
|
||||
parentPanel.goBack();
|
||||
},
|
||||
|
||||
workspaceHasIcon(workspace) {
|
||||
return typeof workspace.icon !== "undefined" && workspace.icon !== "";
|
||||
return typeof workspace.icon !== 'undefined' && workspace.icon !== '';
|
||||
},
|
||||
|
||||
getWorkspaceIcon(workspace) {
|
||||
|
@ -266,15 +220,13 @@ var ZenWorkspaces = {
|
|||
},
|
||||
|
||||
async _propagateWorkspaceData() {
|
||||
let currentContainer = document.getElementById(
|
||||
"PanelUI-zen-workspaces-current-info",
|
||||
);
|
||||
let workspaceList = document.getElementById("PanelUI-zen-workspaces-list");
|
||||
let currentContainer = document.getElementById('PanelUI-zen-workspaces-current-info');
|
||||
let workspaceList = document.getElementById('PanelUI-zen-workspaces-list');
|
||||
const createWorkspaceElement = (workspace) => {
|
||||
let element = document.createXULElement("toolbarbutton");
|
||||
element.className = "subviewbutton";
|
||||
element.setAttribute("tooltiptext", workspace.name);
|
||||
element.setAttribute("zen-workspace-id", workspace.uuid);
|
||||
let element = document.createXULElement('toolbarbutton');
|
||||
element.className = 'subviewbutton';
|
||||
element.setAttribute('tooltiptext', workspace.name);
|
||||
element.setAttribute('zen-workspace-id', workspace.uuid);
|
||||
//element.setAttribute("context", "zenWorkspaceActionsMenu");
|
||||
let childs = window.MozXULElement.parseXULToFragment(`
|
||||
<div class="zen-workspace-icon">
|
||||
|
@ -287,48 +239,37 @@ var ZenWorkspaces = {
|
|||
`);
|
||||
|
||||
// use text content instead of innerHTML to avoid XSS
|
||||
childs.querySelector(".zen-workspace-icon").textContent =
|
||||
this.getWorkspaceIcon(workspace);
|
||||
childs.querySelector(".zen-workspace-name").textContent = workspace.name;
|
||||
childs.querySelector('.zen-workspace-icon').textContent = this.getWorkspaceIcon(workspace);
|
||||
childs.querySelector('.zen-workspace-name').textContent = workspace.name;
|
||||
|
||||
childs
|
||||
.querySelector(".zen-workspace-actions")
|
||||
.addEventListener("command", (event) => {
|
||||
let button = event.target;
|
||||
this._contextMenuId = button
|
||||
.closest("toolbarbutton[zen-workspace-id]")
|
||||
.getAttribute("zen-workspace-id");
|
||||
const popup = button.ownerDocument.getElementById(
|
||||
"zenWorkspaceActionsMenu",
|
||||
);
|
||||
popup.openPopup(button, "after_end");
|
||||
});
|
||||
childs.querySelector('.zen-workspace-actions').addEventListener('command', (event) => {
|
||||
let button = event.target;
|
||||
this._contextMenuId = button.closest('toolbarbutton[zen-workspace-id]').getAttribute('zen-workspace-id');
|
||||
const popup = button.ownerDocument.getElementById('zenWorkspaceActionsMenu');
|
||||
popup.openPopup(button, 'after_end');
|
||||
});
|
||||
element.appendChild(childs);
|
||||
element.onclick = (async () => {
|
||||
if (event.target.closest(".zen-workspace-actions")) {
|
||||
if (event.target.closest('.zen-workspace-actions')) {
|
||||
return; // Ignore clicks on the actions button
|
||||
}
|
||||
await this.changeWorkspace(workspace);
|
||||
let panel = document.getElementById("PanelUI-zen-workspaces");
|
||||
let panel = document.getElementById('PanelUI-zen-workspaces');
|
||||
PanelMultiView.hidePopup(panel);
|
||||
document
|
||||
.getElementById("zen-workspaces-button")
|
||||
.removeAttribute("open");
|
||||
document.getElementById('zen-workspaces-button').removeAttribute('open');
|
||||
}).bind(this, workspace);
|
||||
return element;
|
||||
};
|
||||
let workspaces = await this._workspaces();
|
||||
let activeWorkspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.used,
|
||||
);
|
||||
currentContainer.innerHTML = "";
|
||||
workspaceList.innerHTML = "";
|
||||
workspaceList.parentNode.style.display = "flex";
|
||||
let activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used);
|
||||
currentContainer.innerHTML = '';
|
||||
workspaceList.innerHTML = '';
|
||||
workspaceList.parentNode.style.display = 'flex';
|
||||
if (workspaces.workspaces.length - 1 <= 0) {
|
||||
workspaceList.innerHTML = "No workspaces available";
|
||||
workspaceList.setAttribute("empty", "true");
|
||||
workspaceList.innerHTML = 'No workspaces available';
|
||||
workspaceList.setAttribute('empty', 'true');
|
||||
} else {
|
||||
workspaceList.removeAttribute("empty");
|
||||
workspaceList.removeAttribute('empty');
|
||||
}
|
||||
if (activeWorkspace) {
|
||||
let currentWorkspace = createWorkspaceElement(activeWorkspace);
|
||||
|
@ -348,10 +289,10 @@ var ZenWorkspaces = {
|
|||
return;
|
||||
}
|
||||
let target = event.target;
|
||||
let panel = document.getElementById("PanelUI-zen-workspaces");
|
||||
let panel = document.getElementById('PanelUI-zen-workspaces');
|
||||
await this._propagateWorkspaceData();
|
||||
PanelMultiView.openPopup(panel, target, {
|
||||
position: "bottomright topright",
|
||||
position: 'bottomright topright',
|
||||
triggerEvent: event,
|
||||
}).catch(console.error);
|
||||
},
|
||||
|
@ -359,29 +300,27 @@ var ZenWorkspaces = {
|
|||
initializeWorkspacesButton() {
|
||||
if (!this.workspaceEnabled) {
|
||||
return;
|
||||
} else if (document.getElementById("zen-workspaces-button")) {
|
||||
let button = document.getElementById("zen-workspaces-button");
|
||||
button.removeAttribute("hidden");
|
||||
} else if (document.getElementById('zen-workspaces-button')) {
|
||||
let button = document.getElementById('zen-workspaces-button');
|
||||
button.removeAttribute('hidden');
|
||||
return;
|
||||
}
|
||||
let browserTabs = document.getElementById("tabbrowser-tabs");
|
||||
let button = document.createElement("toolbarbutton");
|
||||
button.id = "zen-workspaces-button";
|
||||
button.className = "toolbarbutton-1 chromeclass-toolbar-additional";
|
||||
button.setAttribute("label", "Workspaces");
|
||||
button.setAttribute("tooltiptext", "Workspaces");
|
||||
let browserTabs = document.getElementById('tabbrowser-tabs');
|
||||
let button = document.createElement('toolbarbutton');
|
||||
button.id = 'zen-workspaces-button';
|
||||
button.className = 'toolbarbutton-1 chromeclass-toolbar-additional';
|
||||
button.setAttribute('label', 'Workspaces');
|
||||
button.setAttribute('tooltiptext', 'Workspaces');
|
||||
button.onclick = this.openWorkspacesDialog.bind(this);
|
||||
browserTabs.insertAdjacentElement("beforebegin", button);
|
||||
browserTabs.insertAdjacentElement('beforebegin', button);
|
||||
},
|
||||
|
||||
async _updateWorkspacesButton() {
|
||||
let button = document.getElementById("zen-workspaces-button");
|
||||
let button = document.getElementById('zen-workspaces-button');
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
let activeWorkspace = (await this._workspaces()).workspaces.find(
|
||||
(workspace) => workspace.used,
|
||||
);
|
||||
let activeWorkspace = (await this._workspaces()).workspaces.find((workspace) => workspace.used);
|
||||
if (activeWorkspace) {
|
||||
button.innerHTML = `
|
||||
<div class="zen-workspace-sidebar-icon">
|
||||
|
@ -391,15 +330,11 @@ var ZenWorkspaces = {
|
|||
`;
|
||||
|
||||
// use text content instead of innerHTML to avoid XSS
|
||||
button.querySelector(".zen-workspace-sidebar-name").textContent =
|
||||
activeWorkspace.name;
|
||||
button.querySelector(".zen-workspace-sidebar-icon").textContent =
|
||||
this.getWorkspaceIcon(activeWorkspace);
|
||||
button.querySelector('.zen-workspace-sidebar-name').textContent = activeWorkspace.name;
|
||||
button.querySelector('.zen-workspace-sidebar-icon').textContent = this.getWorkspaceIcon(activeWorkspace);
|
||||
|
||||
if (!this.workspaceHasIcon(activeWorkspace)) {
|
||||
button
|
||||
.querySelector(".zen-workspace-sidebar-icon")
|
||||
.setAttribute("no-icon", "true");
|
||||
button.querySelector('.zen-workspace-sidebar-icon').setAttribute('no-icon', 'true');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -407,26 +342,24 @@ var ZenWorkspaces = {
|
|||
// Workspaces management
|
||||
|
||||
get _workspaceCreateInput() {
|
||||
return document.getElementById("PanelUI-zen-workspaces-create-input");
|
||||
return document.getElementById('PanelUI-zen-workspaces-create-input');
|
||||
},
|
||||
|
||||
get _workspaceEditDialog() {
|
||||
return document.getElementById("PanelUI-zen-workspaces-edit");
|
||||
return document.getElementById('PanelUI-zen-workspaces-edit');
|
||||
},
|
||||
|
||||
get _workspaceEditInput() {
|
||||
return document.getElementById("PanelUI-zen-workspaces-edit-input");
|
||||
return document.getElementById('PanelUI-zen-workspaces-edit-input');
|
||||
},
|
||||
|
||||
get _workspaceEditIconsContainer() {
|
||||
return document.getElementById(
|
||||
"PanelUI-zen-workspaces-edit-icons-container",
|
||||
);
|
||||
return document.getElementById('PanelUI-zen-workspaces-edit-icons-container');
|
||||
},
|
||||
|
||||
_deleteAllTabsInWorkspace(workspaceID) {
|
||||
for (let tab of gBrowser.tabs) {
|
||||
if (tab.getAttribute("zen-workspace-id") === workspaceID) {
|
||||
if (tab.getAttribute('zen-workspace-id') === workspaceID) {
|
||||
gBrowser.removeTab(tab, {
|
||||
animate: true,
|
||||
skipSessionStore: true,
|
||||
|
@ -437,11 +370,11 @@ var ZenWorkspaces = {
|
|||
},
|
||||
|
||||
_prepareNewWorkspace(window) {
|
||||
document.documentElement.setAttribute("zen-workspace-id", window.uuid);
|
||||
document.documentElement.setAttribute('zen-workspace-id', window.uuid);
|
||||
let tabCount = 0;
|
||||
for (let tab of gBrowser.tabs) {
|
||||
if (!tab.hasAttribute("zen-workspace-id")) {
|
||||
tab.setAttribute("zen-workspace-id", window.uuid);
|
||||
if (!tab.hasAttribute('zen-workspace-id')) {
|
||||
tab.setAttribute('zen-workspace-id', window.uuid);
|
||||
tabCount++;
|
||||
}
|
||||
}
|
||||
|
@ -451,10 +384,8 @@ var ZenWorkspaces = {
|
|||
},
|
||||
|
||||
_createNewTabForWorkspace(window) {
|
||||
let tab = gZenUIManager.openAndChangeToTab(
|
||||
Services.prefs.getStringPref("browser.startup.homepage"),
|
||||
);
|
||||
tab.setAttribute("zen-workspace-id", window.uuid);
|
||||
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
|
||||
tab.setAttribute('zen-workspace-id', window.uuid);
|
||||
},
|
||||
|
||||
async saveWorkspaceFromCreate() {
|
||||
|
@ -462,32 +393,24 @@ var ZenWorkspaces = {
|
|||
if (!workspaceName) {
|
||||
return;
|
||||
}
|
||||
this._workspaceCreateInput.value = "";
|
||||
let icon = document.querySelector(
|
||||
"#PanelUI-zen-workspaces-create-icons-container [selected]",
|
||||
);
|
||||
icon?.removeAttribute("selected");
|
||||
this._workspaceCreateInput.value = '';
|
||||
let icon = document.querySelector('#PanelUI-zen-workspaces-create-icons-container [selected]');
|
||||
icon?.removeAttribute('selected');
|
||||
await this.createAndSaveWorkspace(workspaceName, false, icon?.label);
|
||||
document.getElementById("PanelUI-zen-workspaces").hidePopup(true);
|
||||
document.getElementById('PanelUI-zen-workspaces').hidePopup(true);
|
||||
},
|
||||
|
||||
async saveWorkspaceFromEdit() {
|
||||
let workspaceUuid = this._workspaceEditDialog.getAttribute(
|
||||
"data-workspace-uuid",
|
||||
);
|
||||
let workspaceUuid = this._workspaceEditDialog.getAttribute('data-workspace-uuid');
|
||||
let workspaceName = this._workspaceEditInput.value;
|
||||
if (!workspaceName) {
|
||||
return;
|
||||
}
|
||||
this._workspaceEditInput.value = "";
|
||||
let icon = document.querySelector(
|
||||
"#PanelUI-zen-workspaces-edit-icons-container [selected]",
|
||||
);
|
||||
icon?.removeAttribute("selected");
|
||||
this._workspaceEditInput.value = '';
|
||||
let icon = document.querySelector('#PanelUI-zen-workspaces-edit-icons-container [selected]');
|
||||
icon?.removeAttribute('selected');
|
||||
let workspaces = (await this._workspaces()).workspaces;
|
||||
let workspaceData = workspaces.find(
|
||||
(workspace) => workspace.uuid === workspaceUuid,
|
||||
);
|
||||
let workspaceData = workspaces.find((workspace) => workspace.uuid === workspaceUuid);
|
||||
workspaceData.name = workspaceName;
|
||||
workspaceData.icon = icon?.label;
|
||||
await this.saveWorkspace(workspaceData);
|
||||
|
@ -497,29 +420,26 @@ var ZenWorkspaces = {
|
|||
},
|
||||
|
||||
onWorkspaceCreationNameChange(event) {
|
||||
let button = document.getElementById("PanelUI-zen-workspaces-create-save");
|
||||
if (this._workspaceCreateInput.value === "") {
|
||||
button.setAttribute("disabled", "true");
|
||||
let button = document.getElementById('PanelUI-zen-workspaces-create-save');
|
||||
if (this._workspaceCreateInput.value === '') {
|
||||
button.setAttribute('disabled', 'true');
|
||||
return;
|
||||
}
|
||||
button.removeAttribute("disabled");
|
||||
button.removeAttribute('disabled');
|
||||
},
|
||||
|
||||
onWorkspaceEditChange() {
|
||||
let button = document.getElementById("PanelUI-zen-workspaces-edit-save");
|
||||
let button = document.getElementById('PanelUI-zen-workspaces-edit-save');
|
||||
let name = this._workspaceEditInput.value;
|
||||
let icon = document.querySelector(
|
||||
"#PanelUI-zen-workspaces-edit-icons-container [selected]",
|
||||
)?.label;
|
||||
let icon = document.querySelector('#PanelUI-zen-workspaces-edit-icons-container [selected]')?.label;
|
||||
if (
|
||||
name === this._workspaceEditInput.getAttribute("data-initial-value") &&
|
||||
icon ===
|
||||
this._workspaceEditIconsContainer.getAttribute("data-initial-value")
|
||||
name === this._workspaceEditInput.getAttribute('data-initial-value') &&
|
||||
icon === this._workspaceEditIconsContainer.getAttribute('data-initial-value')
|
||||
) {
|
||||
button.setAttribute("disabled", "true");
|
||||
button.setAttribute('disabled', 'true');
|
||||
return;
|
||||
}
|
||||
button.removeAttribute("disabled");
|
||||
button.removeAttribute('disabled');
|
||||
},
|
||||
|
||||
async changeWorkspace(window, onInit = false) {
|
||||
|
@ -532,33 +452,35 @@ var ZenWorkspaces = {
|
|||
workspace.used = workspace.uuid === window.uuid;
|
||||
}
|
||||
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) {
|
||||
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) || !tab.hasAttribute('zen-workspace-id')) {
|
||||
if (!firstTab) {
|
||||
firstTab = tab;
|
||||
gBrowser.selectedTab = firstTab;
|
||||
} else if (gBrowser.selectedTab === tab) {
|
||||
// If the selected tab is already in the workspace, we don't want to change it
|
||||
firstTab = undefined;
|
||||
}
|
||||
gBrowser.showTab(tab);
|
||||
if (!tab.hasAttribute("zen-workspace-id")) {
|
||||
if (!tab.hasAttribute('zen-workspace-id')) {
|
||||
// We add the id to those tabs that got inserted before we initialize the workspaces
|
||||
// example use case: opening a link from an external app
|
||||
tab.setAttribute("zen-workspace-id", window.uuid);
|
||||
tab.setAttribute('zen-workspace-id', window.uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof firstTab === "undefined" && !onInit) {
|
||||
if (firstTab) {
|
||||
gBrowser.selectedTab = firstTab;
|
||||
}
|
||||
if (typeof firstTab === 'undefined' && !onInit) {
|
||||
this._createNewTabForWorkspace(window);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
document.documentElement.setAttribute("zen-workspace-id", window.uuid);
|
||||
document.documentElement.setAttribute('zen-workspace-id', window.uuid);
|
||||
await this.saveWorkspaces();
|
||||
await this._updateWorkspacesButton();
|
||||
await this._propagateWorkspaceData();
|
||||
|
@ -568,23 +490,19 @@ var ZenWorkspaces = {
|
|||
async _updateWorkspacesChangeContextMenu() {
|
||||
const workspaces = await this._workspaces();
|
||||
|
||||
const menuPopup = document.getElementById(
|
||||
"context-zen-change-workspace-tab-menu-popup",
|
||||
);
|
||||
const menuPopup = document.getElementById('context-zen-change-workspace-tab-menu-popup');
|
||||
|
||||
menuPopup.innerHTML = "";
|
||||
menuPopup.innerHTML = '';
|
||||
|
||||
const activeWorkspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.used,
|
||||
);
|
||||
const activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used);
|
||||
|
||||
for (let workspace of workspaces.workspaces) {
|
||||
const menuItem = document.createXULElement("menuitem");
|
||||
menuItem.setAttribute("label", workspace.name);
|
||||
menuItem.setAttribute("zen-workspace-id", workspace.uuid);
|
||||
const menuItem = document.createXULElement('menuitem');
|
||||
menuItem.setAttribute('label', workspace.name);
|
||||
menuItem.setAttribute('zen-workspace-id', workspace.uuid);
|
||||
|
||||
if (workspace.uuid === activeWorkspace.uuid) {
|
||||
menuItem.setAttribute("disabled", "true");
|
||||
menuItem.setAttribute('disabled', 'true');
|
||||
}
|
||||
|
||||
menuPopup.appendChild(menuItem);
|
||||
|
@ -603,11 +521,7 @@ var ZenWorkspaces = {
|
|||
return window;
|
||||
},
|
||||
|
||||
async createAndSaveWorkspace(
|
||||
name = "New Workspace",
|
||||
isDefault = false,
|
||||
icon = undefined,
|
||||
) {
|
||||
async createAndSaveWorkspace(name = 'New Workspace', isDefault = false, icon = undefined) {
|
||||
if (!this.workspaceEnabled) {
|
||||
return;
|
||||
}
|
||||
|
@ -618,16 +532,14 @@ var ZenWorkspaces = {
|
|||
|
||||
async onLocationChange(browser) {
|
||||
let tab = gBrowser.getTabForBrowser(browser);
|
||||
let workspaceID = tab.getAttribute("zen-workspace-id");
|
||||
let workspaceID = tab.getAttribute('zen-workspace-id');
|
||||
if (!workspaceID) {
|
||||
let workspaces = await this._workspaces();
|
||||
let activeWorkspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.used,
|
||||
);
|
||||
if (!activeWorkspace || tab.hasAttribute("hidden")) {
|
||||
let activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used);
|
||||
if (!activeWorkspace || tab.hasAttribute('hidden')) {
|
||||
return;
|
||||
}
|
||||
tab.setAttribute("zen-workspace-id", activeWorkspace.uuid);
|
||||
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -635,54 +547,40 @@ var ZenWorkspaces = {
|
|||
|
||||
_contextMenuId: null,
|
||||
async updateContextMenu(_) {
|
||||
console.assert(this._contextMenuId, "No context menu ID set");
|
||||
console.assert(this._contextMenuId, 'No context menu ID set');
|
||||
document
|
||||
.querySelector(
|
||||
`#PanelUI-zen-workspaces [zen-workspace-id="${this._contextMenuId}"] .zen-workspace-actions`,
|
||||
)
|
||||
.setAttribute("active", "true");
|
||||
.querySelector(`#PanelUI-zen-workspaces [zen-workspace-id="${this._contextMenuId}"] .zen-workspace-actions`)
|
||||
.setAttribute('active', 'true');
|
||||
const workspaces = await this._workspaces();
|
||||
let deleteMenuItem = document.getElementById("context_zenDeleteWorkspace");
|
||||
let deleteMenuItem = document.getElementById('context_zenDeleteWorkspace');
|
||||
if (
|
||||
workspaces.workspaces.length <= 1 ||
|
||||
workspaces.workspaces.find(
|
||||
(workspace) => workspace.uuid === this._contextMenuId,
|
||||
).default
|
||||
workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId).default
|
||||
) {
|
||||
deleteMenuItem.setAttribute("disabled", "true");
|
||||
deleteMenuItem.setAttribute('disabled', 'true');
|
||||
} else {
|
||||
deleteMenuItem.removeAttribute("disabled");
|
||||
deleteMenuItem.removeAttribute('disabled');
|
||||
}
|
||||
let defaultMenuItem = document.getElementById(
|
||||
"context_zenSetAsDefaultWorkspace",
|
||||
);
|
||||
if (
|
||||
workspaces.workspaces.find(
|
||||
(workspace) => workspace.uuid === this._contextMenuId,
|
||||
).default
|
||||
) {
|
||||
defaultMenuItem.setAttribute("disabled", "true");
|
||||
let defaultMenuItem = document.getElementById('context_zenSetAsDefaultWorkspace');
|
||||
if (workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId).default) {
|
||||
defaultMenuItem.setAttribute('disabled', 'true');
|
||||
} else {
|
||||
defaultMenuItem.removeAttribute("disabled");
|
||||
defaultMenuItem.removeAttribute('disabled');
|
||||
}
|
||||
let openMenuItem = document.getElementById("context_zenOpenWorkspace");
|
||||
if (
|
||||
workspaces.workspaces.find(
|
||||
(workspace) => workspace.uuid === this._contextMenuId,
|
||||
).used
|
||||
) {
|
||||
openMenuItem.setAttribute("disabled", "true");
|
||||
let openMenuItem = document.getElementById('context_zenOpenWorkspace');
|
||||
if (workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId).used) {
|
||||
openMenuItem.setAttribute('disabled', 'true');
|
||||
} else {
|
||||
openMenuItem.removeAttribute("disabled");
|
||||
openMenuItem.removeAttribute('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
onContextMenuClose() {
|
||||
let target = document.querySelector(
|
||||
`#PanelUI-zen-workspaces [zen-workspace-id="${this._contextMenuId}"] .zen-workspace-actions`,
|
||||
`#PanelUI-zen-workspaces [zen-workspace-id="${this._contextMenuId}"] .zen-workspace-actions`
|
||||
);
|
||||
if (target) {
|
||||
target.removeAttribute("active");
|
||||
target.removeAttribute('active');
|
||||
}
|
||||
this._contextMenuId = null;
|
||||
},
|
||||
|
@ -698,9 +596,7 @@ var ZenWorkspaces = {
|
|||
|
||||
async openWorkspace() {
|
||||
let workspaces = await this._workspaces();
|
||||
let workspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.uuid === this._contextMenuId,
|
||||
);
|
||||
let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId);
|
||||
await this.changeWorkspace(workspace);
|
||||
},
|
||||
|
||||
|
@ -719,43 +615,33 @@ var ZenWorkspaces = {
|
|||
async changeWorkspaceShortcut() {
|
||||
// Cycle through workspaces
|
||||
let workspaces = await this._workspaces();
|
||||
let activeWorkspace = workspaces.workspaces.find(
|
||||
(workspace) => workspace.used,
|
||||
);
|
||||
let activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used);
|
||||
let workspaceIndex = workspaces.workspaces.indexOf(activeWorkspace);
|
||||
let nextWorkspace =
|
||||
workspaces.workspaces[workspaceIndex + 1] || workspaces.workspaces[0];
|
||||
let nextWorkspace = workspaces.workspaces[workspaceIndex + 1] || workspaces.workspaces[0];
|
||||
this.changeWorkspace(nextWorkspace);
|
||||
},
|
||||
|
||||
_initializeWorkspaceTabContextMenus() {
|
||||
const menu = document.createXULElement("menu");
|
||||
menu.setAttribute("id", "context-zen-change-workspace-tab");
|
||||
menu.setAttribute("data-l10n-id", "context-zen-change-workspace-tab");
|
||||
const menu = document.createXULElement('menu');
|
||||
menu.setAttribute('id', 'context-zen-change-workspace-tab');
|
||||
menu.setAttribute('data-l10n-id', 'context-zen-change-workspace-tab');
|
||||
|
||||
const menuPopup = document.createXULElement("menupopup");
|
||||
menuPopup.setAttribute("id", "context-zen-change-workspace-tab-menu-popup");
|
||||
menuPopup.setAttribute(
|
||||
"oncommand",
|
||||
"ZenWorkspaces.changeTabWorkspace(event.target.getAttribute('zen-workspace-id'))",
|
||||
);
|
||||
const menuPopup = document.createXULElement('menupopup');
|
||||
menuPopup.setAttribute('id', 'context-zen-change-workspace-tab-menu-popup');
|
||||
menuPopup.setAttribute('oncommand', "ZenWorkspaces.changeTabWorkspace(event.target.getAttribute('zen-workspace-id'))");
|
||||
|
||||
menu.appendChild(menuPopup);
|
||||
|
||||
document.getElementById("context_closeDuplicateTabs").after(menu);
|
||||
document.getElementById('context_closeDuplicateTabs').after(menu);
|
||||
},
|
||||
|
||||
async changeTabWorkspace(workspaceID) {
|
||||
const tabs = TabContextMenu.contextTab.multiselected
|
||||
? gBrowser.selectedTabs
|
||||
: [TabContextMenu.contextTab];
|
||||
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||
for (let tab of tabs) {
|
||||
tab.setAttribute("zen-workspace-id", workspaceID);
|
||||
tab.setAttribute('zen-workspace-id', workspaceID);
|
||||
}
|
||||
const workspaces = await this._workspaces();
|
||||
await this.changeWorkspace(
|
||||
workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID),
|
||||
);
|
||||
await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -6,9 +5,9 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
|
||||
handleEvent(event) {
|
||||
switch (event.type) {
|
||||
case "DOMContentLoaded":
|
||||
case 'DOMContentLoaded':
|
||||
this.initiateThemeMarketplace();
|
||||
this.contentWindow.document.addEventListener("ZenCheckForThemeUpdates", this.checkForThemeUpdates.bind(this));
|
||||
this.contentWindow.document.addEventListener('ZenCheckForThemeUpdates', this.checkForThemeUpdates.bind(this));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
@ -17,7 +16,7 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
// This function will be caleld from about:preferences
|
||||
checkForThemeUpdates(event) {
|
||||
event.preventDefault();
|
||||
this.sendAsyncMessage("ZenThemeMarketplace:CheckForUpdates");
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdates');
|
||||
}
|
||||
|
||||
initiateThemeMarketplace() {
|
||||
|
@ -27,16 +26,16 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
}
|
||||
|
||||
get actionButton() {
|
||||
return this.contentWindow.document.getElementById("install-theme");
|
||||
return this.contentWindow.document.getElementById('install-theme');
|
||||
}
|
||||
|
||||
get actionButtonUnnstall() {
|
||||
return this.contentWindow.document.getElementById("install-theme-uninstall");
|
||||
return this.contentWindow.document.getElementById('install-theme-uninstall');
|
||||
}
|
||||
|
||||
async receiveMessage(message) {
|
||||
switch (message.name) {
|
||||
case "ZenThemeMarketplace:ThemeChanged": {
|
||||
case 'ZenThemeMarketplace:ThemeChanged': {
|
||||
const themeId = message.data.themeId;
|
||||
const actionButton = this.actionButton;
|
||||
const actionButtonInstalled = this.actionButtonUnnstall;
|
||||
|
@ -44,21 +43,23 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
actionButton.disabled = false;
|
||||
actionButtonInstalled.disabled = false;
|
||||
if (await this.isThemeInstalled(themeId)) {
|
||||
actionButton.classList.add("hidden");
|
||||
actionButtonInstalled.classList.remove("hidden");
|
||||
actionButton.classList.add('hidden');
|
||||
actionButtonInstalled.classList.remove('hidden');
|
||||
} else {
|
||||
actionButton.classList.remove("hidden");
|
||||
actionButtonInstalled.classList.add("hidden");
|
||||
actionButton.classList.remove('hidden');
|
||||
actionButtonInstalled.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "ZenThemeMarketplace:CheckForUpdatesFinished": {
|
||||
case 'ZenThemeMarketplace:CheckForUpdatesFinished': {
|
||||
const updates = message.data.updates;
|
||||
this.contentWindow.document.dispatchEvent(new CustomEvent("ZenThemeMarketplace:CheckForUpdatesFinished", { detail: { updates } }));
|
||||
this.contentWindow.document.dispatchEvent(
|
||||
new CustomEvent('ZenThemeMarketplace:CheckForUpdatesFinished', { detail: { updates } })
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "ZenThemeMarketplace:GetThemeInfo": {
|
||||
case 'ZenThemeMarketplace:GetThemeInfo': {
|
||||
const themeId = message.data.themeId;
|
||||
const theme = await this.getThemeInfo(themeId);
|
||||
return theme;
|
||||
|
@ -69,30 +70,30 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
async addIntallButtons() {
|
||||
const actionButton = this.actionButton;
|
||||
const actionButtonUnnstall = this.actionButtonUnnstall;
|
||||
const errorMessage = this.contentWindow.document.getElementById("install-theme-error");
|
||||
const errorMessage = this.contentWindow.document.getElementById('install-theme-error');
|
||||
if (!actionButton || !actionButtonUnnstall) {
|
||||
return;
|
||||
}
|
||||
|
||||
errorMessage.classList.add("hidden");
|
||||
|
||||
const themeId = actionButton.getAttribute("zen-theme-id");
|
||||
errorMessage.classList.add('hidden');
|
||||
|
||||
const themeId = actionButton.getAttribute('zen-theme-id');
|
||||
if (await this.isThemeInstalled(themeId)) {
|
||||
actionButtonUnnstall.classList.remove("hidden");
|
||||
actionButtonUnnstall.classList.remove('hidden');
|
||||
} else {
|
||||
actionButton.classList.remove("hidden");
|
||||
actionButton.classList.remove('hidden');
|
||||
}
|
||||
|
||||
actionButton.addEventListener("click", this.installTheme.bind(this));
|
||||
actionButtonUnnstall.addEventListener("click", this.uninstallTheme.bind(this));
|
||||
actionButton.addEventListener('click', this.installTheme.bind(this));
|
||||
actionButtonUnnstall.addEventListener('click', this.uninstallTheme.bind(this));
|
||||
}
|
||||
|
||||
async isThemeInstalled(themeId) {
|
||||
return await this.sendQuery("ZenThemeMarketplace:IsThemeInstalled", { themeId });
|
||||
return await this.sendQuery('ZenThemeMarketplace:IsThemeInstalled', { themeId });
|
||||
}
|
||||
|
||||
addTheme(theme) {
|
||||
this.sendAsyncMessage("ZenThemeMarketplace:InstallTheme", { theme });
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:InstallTheme', { theme });
|
||||
}
|
||||
|
||||
getThemeAPIUrl(themeId) {
|
||||
|
@ -101,9 +102,9 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
|
||||
async getThemeInfo(themeId) {
|
||||
const url = this.getThemeAPIUrl(themeId);
|
||||
console.info("ZTM: Fetching theme info from: ", url);
|
||||
console.info('ZTM: Fetching theme info from: ', url);
|
||||
const data = await fetch(url, {
|
||||
mode: "no-cors",
|
||||
mode: 'no-cors',
|
||||
});
|
||||
|
||||
if (data.ok) {
|
||||
|
@ -111,31 +112,31 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
|||
const obj = await data.json();
|
||||
return obj;
|
||||
} catch (e) {
|
||||
console.error("ZTM: Error parsing theme info: ", e);
|
||||
console.error('ZTM: Error parsing theme info: ', e);
|
||||
}
|
||||
} else console.log(data.status);
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
async uninstallTheme(event) {
|
||||
const button = event.target;
|
||||
button.disabled = true;
|
||||
const themeId = button.getAttribute("zen-theme-id");
|
||||
console.info("ZTM: Uninstalling theme with id: ", themeId);
|
||||
this.sendAsyncMessage("ZenThemeMarketplace:UninstallTheme", { themeId });
|
||||
const themeId = button.getAttribute('zen-theme-id');
|
||||
console.info('ZTM: Uninstalling theme with id: ', themeId);
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:UninstallTheme', { themeId });
|
||||
}
|
||||
|
||||
async installTheme(event) {
|
||||
const button = event.target;
|
||||
button.disabled = true;
|
||||
const themeId = button.getAttribute("zen-theme-id");
|
||||
console.info("ZTM: Installing theme with id: ", themeId);
|
||||
const themeId = button.getAttribute('zen-theme-id');
|
||||
console.info('ZTM: Installing theme with id: ', themeId);
|
||||
|
||||
const theme = await this.getThemeInfo(themeId);
|
||||
if (!theme) {
|
||||
console.error("ZTM: Error fetching theme info");
|
||||
console.error('ZTM: Error fetching theme info');
|
||||
return;
|
||||
}
|
||||
this.addTheme(theme);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -6,8 +5,8 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
|||
|
||||
async receiveMessage(message) {
|
||||
switch (message.name) {
|
||||
case "ZenThemeMarketplace:InstallTheme": {
|
||||
console.info("ZenThemeMarketplaceParent: Updating themes");
|
||||
case 'ZenThemeMarketplace:InstallTheme': {
|
||||
console.info('ZenThemeMarketplaceParent: Updating themes');
|
||||
const theme = message.data.theme;
|
||||
const themes = await this.getThemes();
|
||||
themes[theme.id] = theme;
|
||||
|
@ -15,8 +14,8 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
|||
this.updateChildProcesses(theme.id);
|
||||
break;
|
||||
}
|
||||
case "ZenThemeMarketplace:UninstallTheme": {
|
||||
console.info("ZenThemeMarketplaceParent: Uninstalling theme");
|
||||
case 'ZenThemeMarketplace:UninstallTheme': {
|
||||
console.info('ZenThemeMarketplaceParent: Uninstalling theme');
|
||||
const themeId = message.data.themeId;
|
||||
const themes = await this.getThemes();
|
||||
delete themes[themeId];
|
||||
|
@ -25,58 +24,66 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
|||
this.updateChildProcesses(themeId);
|
||||
break;
|
||||
}
|
||||
case "ZenThemeMarketplace:IsThemeInstalled": {
|
||||
case 'ZenThemeMarketplace:IsThemeInstalled': {
|
||||
const themeId = message.data.themeId;
|
||||
const themes = await this.getThemes();
|
||||
return themes[themeId] ? true : false;
|
||||
}
|
||||
case "ZenThemeMarketplace:CheckForUpdates": {
|
||||
case 'ZenThemeMarketplace:CheckForUpdates': {
|
||||
this.checkForThemeUpdates();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compareversion(version1,version2){
|
||||
var result=false;
|
||||
if(typeof version1!=='object'){ version1=version1.toString().split('.'); }
|
||||
if(typeof version2!=='object'){ version2=version2.toString().split('.'); }
|
||||
for(var i=0;i<(Math.max(version1.length,version2.length));i++){
|
||||
if(version1[i]==undefined){ version1[i]=0; }
|
||||
if(version2[i]==undefined){ version2[i]=0; }
|
||||
if(Number(version1[i])<Number(version2[i])){
|
||||
result=true;
|
||||
compareversion(version1, version2) {
|
||||
var result = false;
|
||||
if (typeof version1 !== 'object') {
|
||||
version1 = version1.toString().split('.');
|
||||
}
|
||||
if (typeof version2 !== 'object') {
|
||||
version2 = version2.toString().split('.');
|
||||
}
|
||||
for (var i = 0; i < Math.max(version1.length, version2.length); i++) {
|
||||
if (version1[i] == undefined) {
|
||||
version1[i] = 0;
|
||||
}
|
||||
if (version2[i] == undefined) {
|
||||
version2[i] = 0;
|
||||
}
|
||||
if (Number(version1[i]) < Number(version2[i])) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
if(version1[i]!=version2[i]){
|
||||
if (version1[i] != version2[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
async checkForThemeUpdates() {
|
||||
console.info("ZenThemeMarketplaceParent: Checking for theme updates");
|
||||
console.info('ZenThemeMarketplaceParent: Checking for theme updates');
|
||||
let updates = [];
|
||||
this._themes = null;
|
||||
for (const theme of Object.values(await this.getThemes())) {
|
||||
const themeInfo = await this.sendQuery("ZenThemeMarketplace:GetThemeInfo", { themeId: theme.id });
|
||||
const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', { themeId: theme.id });
|
||||
if (!themeInfo) {
|
||||
continue;
|
||||
}
|
||||
if (!this.compareversion(themeInfo.version, theme.version || "0.0.0") && themeInfo.version != theme.version) {
|
||||
console.info("ZenThemeMarketplaceParent: Theme update found", theme.id, theme.version, themeInfo.version);
|
||||
if (!this.compareversion(themeInfo.version, theme.version || '0.0.0') && themeInfo.version != theme.version) {
|
||||
console.info('ZenThemeMarketplaceParent: Theme update found', theme.id, theme.version, themeInfo.version);
|
||||
updates.push(themeInfo);
|
||||
await this.removeTheme(theme.id, false);
|
||||
this._themes[themeInfo.id] = themeInfo;
|
||||
}
|
||||
}
|
||||
await this.updateThemes(this._themes);
|
||||
this.sendAsyncMessage("ZenThemeMarketplace:CheckForUpdatesFinished", { updates });
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates });
|
||||
}
|
||||
|
||||
async updateChildProcesses(themeId) {
|
||||
this.sendAsyncMessage("ZenThemeMarketplace:ThemeChanged", { themeId });
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:ThemeChanged', { themeId });
|
||||
}
|
||||
|
||||
async getThemes() {
|
||||
|
@ -112,37 +119,30 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
|||
let buffer = new TextEncoder().encode(content);
|
||||
await IOUtils.write(path, buffer);
|
||||
} catch (e) {
|
||||
console.error("ZenThemeMarketplaceParent: Error downloading file", url, e);
|
||||
console.error('ZenThemeMarketplaceParent: Error downloading file', url, e);
|
||||
}
|
||||
}
|
||||
|
||||
async downloadThemeFileContents(theme) {
|
||||
const themePath = PathUtils.join(this.themesRootPath, theme.id);
|
||||
await IOUtils.makeDirectory(themePath, { ignoreExisting: true });
|
||||
await this.downloadUrlToFile(theme.style, PathUtils.join(themePath, "chrome.css"), true);
|
||||
await this.downloadUrlToFile(theme.readme, PathUtils.join(themePath, "readme.md"));
|
||||
await this.downloadUrlToFile(theme.style, PathUtils.join(themePath, 'chrome.css'), true);
|
||||
await this.downloadUrlToFile(theme.readme, PathUtils.join(themePath, 'readme.md'));
|
||||
if (theme.preferences) {
|
||||
await this.downloadUrlToFile(theme.preferences, PathUtils.join(themePath, "preferences.json"));
|
||||
await this.downloadUrlToFile(theme.preferences, PathUtils.join(themePath, 'preferences.json'));
|
||||
}
|
||||
}
|
||||
|
||||
get themesRootPath() {
|
||||
return PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"chrome",
|
||||
"zen-themes"
|
||||
);
|
||||
return PathUtils.join(PathUtils.profileDir, 'chrome', 'zen-themes');
|
||||
}
|
||||
|
||||
get themesDataFile() {
|
||||
return PathUtils.join(
|
||||
PathUtils.profileDir,
|
||||
"zen-themes.json"
|
||||
);
|
||||
return PathUtils.join(PathUtils.profileDir, 'zen-themes.json');
|
||||
}
|
||||
|
||||
triggerThemeUpdate() {
|
||||
const pref = "zen.themes.updated-value-observer";
|
||||
const pref = 'zen.themes.updated-value-observer';
|
||||
Services.prefs.setBoolPref(pref, !Services.prefs.getBoolPref(pref));
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,10 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
|||
|
||||
async removeTheme(themeId, triggerUpdate = true) {
|
||||
const themePath = PathUtils.join(this.themesRootPath, themeId);
|
||||
console.info("ZenThemeMarketplaceParent: Removing theme ", themePath);
|
||||
console.info('ZenThemeMarketplaceParent: Removing theme ', themePath);
|
||||
await IOUtils.remove(themePath, { recursive: true, ignoreAbsent: true });
|
||||
if (triggerUpdate) {
|
||||
this.triggerThemeUpdate();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue