mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 17:40:00 +02:00
Yet another attempt into fixing macos shortcuts
This commit is contained in:
parent
ccfbac35f3
commit
bfb5e8fc94
1 changed files with 51 additions and 20 deletions
|
@ -96,6 +96,9 @@ const fixedL10nIds = {
|
||||||
'History:RestoreLastClosedTabOrWindowOrSession': 'zen-restore-last-closed-tab-shortcut',
|
'History:RestoreLastClosedTabOrWindowOrSession': 'zen-restore-last-closed-tab-shortcut',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ZEN_MAIN_KEYSET_ID = 'mainKeyset';
|
||||||
|
const ZEN_KEYSET_ID = 'zenKeyset';
|
||||||
|
|
||||||
const ZEN_COMPACT_MODE_SHORTCUTS_GROUP = 'zen-compact-mode';
|
const ZEN_COMPACT_MODE_SHORTCUTS_GROUP = 'zen-compact-mode';
|
||||||
const ZEN_WORKSPACE_SHORTCUTS_GROUP = 'zen-workspace';
|
const ZEN_WORKSPACE_SHORTCUTS_GROUP = 'zen-workspace';
|
||||||
const ZEN_OTHER_SHORTCUTS_GROUP = 'zen-other';
|
const ZEN_OTHER_SHORTCUTS_GROUP = 'zen-other';
|
||||||
|
@ -537,7 +540,7 @@ function zenGetDefaultShortcuts() {
|
||||||
// and increment the version number.
|
// and increment the version number.
|
||||||
|
|
||||||
console.info('Zen CKS: Loading default shortcuts...');
|
console.info('Zen CKS: Loading default shortcuts...');
|
||||||
let keySet = document.getElementById('mainKeyset');
|
let keySet = document.getElementById(ZEN_MAIN_KEYSET_ID);
|
||||||
let newShortcutList = [];
|
let newShortcutList = [];
|
||||||
|
|
||||||
// Firefox's standard keyset. Reverse order to keep the order of the keys
|
// Firefox's standard keyset. Reverse order to keep the order of the keys
|
||||||
|
@ -755,10 +758,18 @@ class ZenKeyboardShortcutsVersioner {
|
||||||
|
|
||||||
var gZenKeyboardShortcutsManager = {
|
var gZenKeyboardShortcutsManager = {
|
||||||
loader: new ZenKeyboardShortcutsLoader(),
|
loader: new ZenKeyboardShortcutsLoader(),
|
||||||
async init() {
|
beforeInit() {
|
||||||
if (window.location.href == 'chrome://browser/content/browser.xhtml') {
|
if (!this.inBrowserView) {
|
||||||
console.info('Zen CKS: Initializing shortcuts');
|
return;
|
||||||
|
}
|
||||||
|
// Create the main keyset before calling the async init function,
|
||||||
|
// This is because other browser-sets needs this element and the JS event
|
||||||
|
// handled wont wait for the async function to finish.
|
||||||
|
void(this.zenKeyset);
|
||||||
|
},
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
if (this.inBrowserView) {
|
||||||
const loadedShortcuts = await this._loadSaved();
|
const loadedShortcuts = await this._loadSaved();
|
||||||
|
|
||||||
this._currentShortcutList = this.versioner.migrateIfNeeded(loadedShortcuts);
|
this._currentShortcutList = this.versioner.migrateIfNeeded(loadedShortcuts);
|
||||||
|
@ -770,6 +781,10 @@ var gZenKeyboardShortcutsManager = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get inBrowserView() {
|
||||||
|
return window.location.href == 'chrome://browser/content/browser.xhtml';
|
||||||
|
},
|
||||||
|
|
||||||
async _loadSaved() {
|
async _loadSaved() {
|
||||||
var innerLoad = async () => {
|
var innerLoad = async () => {
|
||||||
let data = await this.loader.load();
|
let data = await this.loader.load();
|
||||||
|
@ -790,25 +805,39 @@ var gZenKeyboardShortcutsManager = {
|
||||||
return loadedShortcuts;
|
return loadedShortcuts;
|
||||||
},
|
},
|
||||||
|
|
||||||
_applyShortcuts() {
|
get zenKeyset() {
|
||||||
for (const browser of ZenMultiWindowFeature.browsers) {
|
if (!this._zenKeyset) {
|
||||||
let mainKeyset = browser.document.getElementById('mainKeyset');
|
this._zenKeyset = document.createXULElement('keyset');
|
||||||
if (!mainKeyset) {
|
this._zenKeyset.id = ZEN_KEYSET_ID;
|
||||||
throw new Error('Main keyset not found');
|
|
||||||
|
const mainKeyset = document.getElementById(ZEN_MAIN_KEYSET_ID);
|
||||||
|
mainKeyset.after(this._zenKeyset);
|
||||||
}
|
}
|
||||||
|
return this._zenKeyset;
|
||||||
|
},
|
||||||
|
|
||||||
let parent = mainKeyset.parentElement;
|
clearMainKeyset(element) {
|
||||||
//mainKeyset.remove();
|
for (let key of element.children) {
|
||||||
|
|
||||||
const children = mainKeyset.children;
|
|
||||||
for (let i = children.length - 1; i >= 0; i--) {
|
|
||||||
let key = children[i];
|
|
||||||
// Do NOT remove the internal keys
|
|
||||||
if (key.getAttribute('internal') == 'true') {
|
if (key.getAttribute('internal') == 'true') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
key.remove();
|
key.remove();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_applyShortcuts() {
|
||||||
|
for (const browser of ZenMultiWindowFeature.browsers) {
|
||||||
|
let mainKeyset = browser.document.getElementById(ZEN_MAIN_KEYSET_ID);
|
||||||
|
if (!mainKeyset) {
|
||||||
|
throw new Error('Main keyset not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
let parent = mainKeyset.parentElement;
|
||||||
|
this.clearMainKeyset(mainKeyset);
|
||||||
|
|
||||||
|
const keyset = this.zenKeyset;
|
||||||
|
this.clearMainKeyset(keyset);
|
||||||
|
|
||||||
// We dont check this anymore since we are skiping internal keys
|
// We dont check this anymore since we are skiping internal keys
|
||||||
//if (mainKeyset.children.length > 0) {
|
//if (mainKeyset.children.length > 0) {
|
||||||
// throw new Error('Child list not empty');
|
// throw new Error('Child list not empty');
|
||||||
|
@ -819,10 +848,10 @@ var gZenKeyboardShortcutsManager = {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let child = key.toXHTMLElement(browser);
|
let child = key.toXHTMLElement(browser);
|
||||||
mainKeyset.appendChild(child);
|
keyset.appendChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.prepend(mainKeyset);
|
parent.prepend(keyset);
|
||||||
console.debug('Shortcuts applied...');
|
console.debug('Shortcuts applied...');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -897,6 +926,8 @@ var gZenKeyboardShortcutsManager = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("MozBeforeInitialXULLayout", async () => {
|
document.addEventListener("MozBeforeInitialXULLayout", () => {
|
||||||
await gZenKeyboardShortcutsManager.init();
|
gZenKeyboardShortcutsManager.beforeInit();
|
||||||
});
|
// Async init
|
||||||
|
gZenKeyboardShortcutsManager.init();
|
||||||
|
}, { once: true });
|
Loading…
Add table
Add a link
Reference in a new issue