FF: register hotkeys on startup; reset if empty
This commit is contained in:
parent
5bc6ce33be
commit
32f05861e3
15
js/prefs.js
15
js/prefs.js
|
@ -299,6 +299,21 @@ var prefs = new function Prefs() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// register hotkeys
|
||||||
|
if (FIREFOX && (browser.commands || {}).update) {
|
||||||
|
const hotkeyPrefs = Object.keys(values).filter(k => k.startsWith('hotkey.'));
|
||||||
|
this.subscribe(hotkeyPrefs, (name, value) => {
|
||||||
|
try {
|
||||||
|
name = name.split('.')[1];
|
||||||
|
if (value.trim()) {
|
||||||
|
browser.commands.update({name, shortcut: value}).catch(ignoreChromeError);
|
||||||
|
} else {
|
||||||
|
browser.commands.reset(name).catch(ignoreChromeError);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
function doBroadcast() {
|
function doBroadcast() {
|
||||||
|
|
|
@ -159,6 +159,7 @@ function customizeHotkeys() {
|
||||||
$create('td',
|
$create('td',
|
||||||
$create('input', {
|
$create('input', {
|
||||||
id: 'hotkey.' + cmd,
|
id: 'hotkey.' + cmd,
|
||||||
|
type: 'search',
|
||||||
//placeholder: t('helpKeyMapHotkey'),
|
//placeholder: t('helpKeyMapHotkey'),
|
||||||
})),
|
})),
|
||||||
]))),
|
]))),
|
||||||
|
@ -181,16 +182,15 @@ function customizeHotkeys() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function onInput() {
|
function onInput() {
|
||||||
const hotkey = this.value.trim();
|
const name = this.id.split('.')[1];
|
||||||
if (!hotkey) {
|
const shortcut = this.value.trim();
|
||||||
|
if (!shortcut) {
|
||||||
|
browser.commands.reset(name).catch(ignoreChromeError);
|
||||||
this.setCustomValidity('');
|
this.setCustomValidity('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
browser.commands.update({
|
browser.commands.update({name, shortcut}).then(
|
||||||
name: this.id.split('.')[1],
|
|
||||||
shortcut: hotkey,
|
|
||||||
}).then(
|
|
||||||
() => this.setCustomValidity(''),
|
() => this.setCustomValidity(''),
|
||||||
err => this.setCustomValidity(err)
|
err => this.setCustomValidity(err)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user