mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:29:59 +02:00
Refactor ZenKeyboardShortcuts to migrate from version 2 to 3
This commit is contained in:
parent
ecdc196752
commit
cdc9fb4980
1 changed files with 21 additions and 1 deletions
|
@ -397,6 +397,10 @@ class KeyShortcut {
|
|||
return key;
|
||||
}
|
||||
|
||||
_modifyInternalAttribute(value) {
|
||||
this.#internal = value;
|
||||
}
|
||||
|
||||
getRealKeycode() {
|
||||
if (this.#keycode === '') {
|
||||
return null;
|
||||
|
@ -707,7 +711,7 @@ function zenGetDefaultShortcuts() {
|
|||
}
|
||||
|
||||
class ZenKeyboardShortcutsVersioner {
|
||||
static LATEST_KBS_VERSION = 2;
|
||||
static LATEST_KBS_VERSION = 3;
|
||||
|
||||
constructor() {}
|
||||
|
||||
|
@ -785,6 +789,22 @@ class ZenKeyboardShortcutsVersioner {
|
|||
)
|
||||
);
|
||||
}
|
||||
if (version < 3) {
|
||||
// Migrate from 2 to 3
|
||||
// In this new version, there was this *really* annoying bug. Shortcuts
|
||||
// detection for internal keys was not working properly, so every internal
|
||||
// shortcut was being saved as a user-editable shortcut.
|
||||
// This migration will fix this issue.
|
||||
const defaultShortcuts = zenGetDefaultShortcuts();
|
||||
// Get the default shortcut, compare the id and set the internal flag if needed
|
||||
for (let shortcut of data) {
|
||||
for (let defaultShortcut of defaultShortcuts) {
|
||||
if (shortcut.getID() == defaultShortcut.getID()) {
|
||||
shortcut._modifyInternalAttribute(defaultShortcut.isInternal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue