Refactor ZenKeyboardShortcuts to migrate from version 2 to 3

This commit is contained in:
mr. M 2024-10-15 15:05:27 +02:00
parent ecdc196752
commit cdc9fb4980
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB

View file

@ -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;
}
}