Skip to content

Commit

Permalink
Bugfix, remove shortcutkey management (managed by browser) (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanmahieu committed Nov 3, 2023
1 parent 42a3aac commit 0993b27
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 494 deletions.
4 changes: 0 additions & 4 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@
"message": "(Subdialog)",
"description": "Options window: Shortcut-keys label opening FHC main dialog, additional text to distinguish from small"
},
"optionsShortcutsUpdateNotSupported": {
"message": "Aktualisieren von Tastenkombinationen wird (aktuell) nicht vom Browser unterstützt!",
"description": "Options window: Message displayed when updating Shortcut-keys is not (yet) supported by the browser."
},
"optionsSaveNewVersionMultiline": {
"message": "Eine neue Version von mehrzeiligen Eingabefeldern speichern wenn:",
"description": "Options window, sub heading: Save a new version of a multiline field when:."
Expand Down
4 changes: 0 additions & 4 deletions _locales/el/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@
"message": "(μικρό παράθυρο)",
"description": "Options window: Shortcut-keys label opening FHC main dialog, additional text to distinguish from small"
},
"optionsShortcutsUpdateNotSupported": {
"message": "Η ενημέρωση των συντομεύσεων δεν υποστηρίζεται (ακόμα) από τον περιηγητή!",
"description": "Options window: Message displayed when updating Shortcut-keys is not (yet) supported by the browser."
},
"optionsSaveNewVersionMultiline": {
"message": "Αποθήκευση μιας νέας έκδοσης ενός πολλαπλού πεδίου όταν:",
"description": "Options window, sub heading: Save a new version of a multiline field when:."
Expand Down
4 changes: 0 additions & 4 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@
"message": "(small dialog)",
"description": "Options window: Shortcut-keys label opening FHC main dialog, additional text to distinguish from small"
},
"optionsShortcutsUpdateNotSupported": {
"message": "Updating shortcuts is not (yet) supported by the browser!",
"description": "Options window: Message displayed when updating Shortcut-keys is not (yet) supported by the browser."
},
"optionsSaveNewVersionMultiline": {
"message": "Save a new version of a multiline field when:",
"description": "Options window, sub heading: Save a new version of a multiline field when:."
Expand Down
4 changes: 0 additions & 4 deletions _locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@
"message": "(작은 대화상자)",
"description": "Options window: Shortcut-keys label opening FHC main dialog, additional text to distinguish from small"
},
"optionsShortcutsUpdateNotSupported": {
"message": "단축 키 교체가 이 브라우저에서는 (아직) 지원되지 않습니다!",
"description": "Options window: Message displayed when updating Shortcut-keys is not (yet) supported by the browser."
},
"optionsSaveNewVersionMultiline": {
"message": "여러 줄 필드의 새 기록을 저장할 시기:",
"description": "Options window, sub heading: Save a new version of a multiline field when:."
Expand Down
4 changes: 0 additions & 4 deletions _locales/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@
"message": "(kleine venster)",
"description": "Options window: Shortcut-keys label opening FHC main dialog, additional text to distinguish from small"
},
"optionsShortcutsUpdateNotSupported": {
"message": "Aanpassen van de sneltoetsen wordt (nog) niet ondersteund door de browser!",
"description": "Options window: Message displayed when updating Shortcut-keys is not (yet) supported by the browser."
},
"optionsSaveNewVersionMultiline": {
"message": "Bewaar een nieuwe versie van een meerregelig veld als:",
"description": "Options window, sub heading: Save a new version of a multiline field when:."
Expand Down
4 changes: 0 additions & 4 deletions _locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@
"message": "(малый диалог)",
"description": "Options window: Shortcut-keys label opening FHC main dialog, additional text to distinguish from small"
},
"optionsShortcutsUpdateNotSupported": {
"message": "Обновление сочетаний (пока) не поддерживается браузером!",
"description": "Options window: Message displayed when updating Shortcut-keys is not (yet) supported by the browser."
},
"optionsSaveNewVersionMultiline": {
"message": "Заменить запись многострочного поля, если:",
"description": "Options window, sub heading: Save a new version of a multiline field when:."
Expand Down
74 changes: 30 additions & 44 deletions background/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ function receiveContextEvents(fhcEvent, sender, sendResponse) {
// create the context menus
initBrowserMenus();

// set the preferred shortcut keys and add a shortcutKey listener
initShortcutKeys();
// set the shortcutKey listener
browser.commands.onCommand.addListener(handleShortcutKeys);

const MAX_LENGTH_EDITFIELD_ITEM = 35;
Expand Down Expand Up @@ -868,52 +867,39 @@ function getBrowserMenusOnClickedHandler() {
return chrome.contextMenus.onClicked;
}

function initShortcutKeys() {
OptionsUtil.applyShortcutKeysPrefs();
}

/**\
*
* Invoke function when shortcutkey command fired.
*/
function handleShortcutKeys(command) {
// console.log("Command! " + command);
OptionsUtil.getShortcutKeysEnablePrefs().then(res => {
switch (command) {
case "open_fhc":
if (res.prefShortcutKeys['open_fhc_enable']) {
WindowUtil.createOrFocusWindow(FHC_WINDOW_MANAGE);
}
break;

case "toggle_display_fields":
if (res.prefShortcutKeys['toggle_display_fields_enable']) {
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
showformfields(tabInfo[0].id);
});
}
break;
switch (command) {
case "open_fhc":
WindowUtil.createOrFocusWindow(FHC_WINDOW_MANAGE);
break;

case "fill_recent":
if (res.prefShortcutKeys['fill_recent_enable']) {
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
fillformfields(tabInfo[0].id, "fillMostRecent");
});
}
break;
case "toggle_display_fields":
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
showformfields(tabInfo[0].id);
});
break;

case "fill_often":
if (res.prefShortcutKeys['fill_often_enable']) {
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
fillformfields(tabInfo[0].id, "fillMostUsed");
});
}
break;
case "fill_recent":
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
fillformfields(tabInfo[0].id, "fillMostRecent");
});
break;

case "clear_filled":
if (res.prefShortcutKeys['clear_filled_enable']) {
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
fillformfields(tabInfo[0].id, "clearFields");
});
}
break;
}
case "fill_often":
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
fillformfields(tabInfo[0].id, "fillMostUsed");
});
break;

});
case "clear_filled":
browser.tabs.query({active: true, currentWindow: true}).then(tabInfo => {
fillformfields(tabInfo[0].id, "clearFields");
});
break;
}
}
81 changes: 1 addition & 80 deletions common/OptionsUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class OptionsUtil {
});
}

// TODO prefFieldfillMode not implemented yet!
static getFieldfillModePrefs() {
const defaultValue = "auto";
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -84,86 +85,6 @@ class OptionsUtil {
});
}

static getShortcutKeysPrefs() {
return new Promise((resolve, reject) => {
browser.storage.local.get({
prefShortcutKeys: {
_execute_browser_action: OptionsUtil.getDefaultShortcutKey('_execute_browser_action'),
// MF3 _execute_action : OptionsUtil.getDefaultShortcutKey('_execute_action'),
open_fhc : OptionsUtil.getDefaultShortcutKey('open_fhc'),
toggle_display_fields : OptionsUtil.getDefaultShortcutKey('toggle_display_fields'),
fill_recent : OptionsUtil.getDefaultShortcutKey('fill_recent'),
fill_often : OptionsUtil.getDefaultShortcutKey('fill_often'),
clear_filled : OptionsUtil.getDefaultShortcutKey('clear_filled')
}
}).then(
result => {
resolve(result);
},
() => {
resolve();
}
);
});
}

static getShortcutKeysEnablePrefs() {
return new Promise((resolve, reject) => {
browser.storage.local.get({
prefShortcutKeys: {
open_fhc_enable : true,
toggle_display_fields_enable : true,
fill_recent_enable : true,
fill_often_enable : true,
clear_filled_enable : true
}
}).then(
result => {
resolve(result);
},
() => {
resolve();
}
);
});
}

static applyShortcutKeysPrefs() {
if (!browser.commands.update) {
return;
}
OptionsUtil.getShortcutKeysPrefs().then((prefs) => {

// get all shortcut commands (max 4 for chrome)
browser.commands.getAll().then( (commands) => (

// for each command change the shortcut where preference differs from default
commands.forEach(function(command) {
const prefShortcut = prefs.prefShortcutKeys[command.name];
if (prefShortcut !== command.shortcut) {
browser.commands.update({
name: command.name,
shortcut: prefShortcut
});
}
})
));
});
}

static getDefaultShortcutKey(commandName) {
// defaults must be equal to the defaults in manifest.json
switch(commandName) {
case '_execute_browser_action': return 'Alt+Shift+P';
// MF3 case '_execute_action': return 'Alt+Shift+P';
case 'open_fhc': return 'Alt+Shift+M';
case 'toggle_display_fields': return 'Alt+Shift+D';
case 'fill_recent': return 'Alt+Shift+R';
case 'fill_often': return 'Alt+Shift+O';
case 'clear_filled': return 'Alt+Shift+C';
}
}

static isDomainfilterActive(filterPrefs) {
return 'all' !== filterPrefs.prefDomainFilter;
}
Expand Down
Loading

0 comments on commit 0993b27

Please sign in to comment.