Skip to content

Commit

Permalink
Adds an optional, second hotkey modifier (oliverschwendener#456)
Browse files Browse the repository at this point in the history
* 🐛 Replaced `Command` key with `CommandOrControl`, as it has no effect on Windows (see https://www.electronjs.org/docs/api/accelerator)

* ✨ Added option to add a second hotkey modifier

* 🚸 Don't offer modifier keys that have already been selected

* 👌 Reverted reformatted imports

* 💚 Added missing super key to new translation files

* 👌 Renamed `firstModifier` into `modifier` + added small fallback logic to remain backwards compatibility

* 👌 Update src/common/global-hot-key/global-hot-key-helpers.ts
  • Loading branch information
tvollstaedt authored Feb 20, 2021
1 parent 1f2a0d0 commit 5f10c1b
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
!.vscode/launch.example.json
!.vscode/extensions.json

# IntelliJ
.idea/

#Bundled files
bundle/

Expand Down
1 change: 1 addition & 0 deletions src/common/config/general-options.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const defaultGeneralOptions: GeneralOptions = {
hotKey: {
key: GlobalHotKeyKey.Space,
modifier: GlobalHotKeyModifier.Alt,
secondModifier: GlobalHotKeyModifier.None,
},
language: Language.English,
logExecution: true,
Expand Down
5 changes: 3 additions & 2 deletions src/common/global-hot-key/global-hot-key-helpers.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GlobalHotKeyKey } from "./global-hot-key-key";
import { GlobalHotKeyModifier } from "./global-hot-key-modifier";

export function isValidHotKey(hotKey: GlobalHotKey) {
return Object.keys(GlobalHotKeyKey).find((k) => k === hotKey.key) !== undefined
&& (hotKey.modifier ? Object.keys(GlobalHotKeyModifier).find((m) => m === hotKey.modifier) : true);
return Object.values(GlobalHotKeyModifier).includes(hotKey.modifier!) &&
Object.values(GlobalHotKeyModifier).includes(hotKey.secondModifier!) &&
Object.values(GlobalHotKeyKey).includes(hotKey.key);
}
26 changes: 26 additions & 0 deletions src/common/global-hot-key/global-hot-key-key.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
export enum GlobalHotKeyKey {
"A" = "A",
"B" = "B",
"C" = "C",
"D" = "D",
"E" = "E",
"F" = "F",
"G" = "G",
"H" = "H",
"I" = "I",
"J" = "J",
"K" = "K",
"L" = "L",
"M" = "M",
"N" = "N",
"O" = "O",
"P" = "P",
"Q" = "Q",
"R" = "R",
"S" = "S",
"T" = "T",
"U" = "U",
"V" = "V",
"W" = "W",
"X" = "X",
"Y" = "Y",
"Z" = "Z",
Plus = "Plus",
Space = "Space",
Tab = "Tab",
Expand Down
3 changes: 2 additions & 1 deletion src/common/global-hot-key/global-hot-key-modifier.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export enum GlobalHotKeyModifier {
None = "-",
Alt = "Alt",
Shift = "Shift",
Control = "Control",
Command = "Command",
Command = "CommandOrControl",
Option = "Option",
AltGr = "AltGr",
Super = "Super",
Expand Down
1 change: 1 addition & 0 deletions src/common/global-hot-key/global-hot-key.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import { GlobalHotKeyKey } from "./global-hot-key-key";
export interface GlobalHotKey {
key: GlobalHotKeyKey;
modifier?: GlobalHotKeyModifier;
secondModifier?: GlobalHotKeyModifier;
}
5 changes: 5 additions & 0 deletions src/common/helpers/config-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UserConfigOptions } from "../config/user-config-options";
import { GlobalHotKeyModifier } from "../global-hot-key/global-hot-key-modifier";
import { deepCopy } from "./object-helpers";

export function mergeUserConfigWithDefault(userConfig: any, defaultUserConfig: UserConfigOptions): UserConfigOptions {
Expand All @@ -11,6 +12,10 @@ export function mergeUserConfigWithDefault(userConfig: any, defaultUserConfig: U
result[key] = merged;
});

if(!result.generalOptions.hotKey.secondModifier) {
result.generalOptions.hotKey.secondModifier = GlobalHotKeyModifier.None;
}

return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/common/translation/chinese-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const chineseTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "外观",
appearanceSettingsWindowWidth: "窗口宽度(像素)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/czech-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const englishTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "Vzhled",
appearanceSettingsWindowWidth: "Šířka okna (v pixelech)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/english-translation-set.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const englishTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "Appearance",
appearanceSettingsWindowWidth: "Window width (in pixels)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/german-translation-set.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const germanTranslationSet: TranslationSet = {
hotkeyModifierControl: "Strg",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "Erscheinungsbild",
appearanceSettingsWindowWidth: "Fensterbreite (in Pixel)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/portuguese-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const portugueseTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "Aparência",
appearanceSettingsWindowWidth: "Largura da janela (em pixels)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/russian-translation-set.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const russianTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "Внешний вид",
appearanceSettingsWindowWidth: "Ширина окна (в пикселях)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/spanish-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const spanishTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Opción",
hotkeyModifierShift: "Mayúsculas",
hotkeyModifierSuper: "Super",

appearanceSettings: "Apariencia",
appearanceSettingsWindowWidth: "Ancho de la ventana (en píxeles)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/translation-set.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface TranslationSet {
hotkeyModifierControl: string;
hotkeyModifierOption: string;
hotkeyModifierShift: string;
hotkeyModifierSuper: string;

appearanceSettings: string;
appearanceSettingsWindowWidth: string;
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/turkish-translation-set.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const turkishTranslationSet: TranslationSet = {
hotkeyModifierControl: "Ctrl",
hotkeyModifierOption: "Option",
hotkeyModifierShift: "Shift",
hotkeyModifierSuper: "Super",

appearanceSettings: "Görünüm",
appearanceSettingsWindowWidth: "Pencere genişliği (piksel olarak)",
Expand Down
19 changes: 18 additions & 1 deletion src/main/main.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { PluginType } from "./plugin-type";
import { getRescanIntervalInMilliseconds } from "./helpers/rescan-interval-helpers";
import { openUrlInBrowser } from "./executors/url-executor";
import { OperatingSystem } from "../common/operating-system";
import { GlobalHotKeyModifier } from "../common/global-hot-key/global-hot-key-modifier";
import { GlobalHotKeyKey } from "../common/global-hot-key/global-hot-key-key";

if (!FileHelpers.fileExistsSync(ueliTempFolder)) {
FileHelpers.createFolderSync(ueliTempFolder);
Expand Down Expand Up @@ -140,7 +142,22 @@ function clearAllCaches() {
function registerGlobalKeyboardShortcut(toggleAction: () => void, newHotKey: GlobalHotKey) {
newHotKey = isValidHotKey(newHotKey) ? newHotKey : defaultGeneralOptions.hotKey;
globalShortcut.unregisterAll();
globalShortcut.register(`${newHotKey.modifier ? `${newHotKey.modifier}+` : ``}${newHotKey.key}`, toggleAction);

const hotKeyParts: (GlobalHotKeyKey | GlobalHotKeyModifier)[] = [];

// Add first key modifier, if any
if (newHotKey.modifier && newHotKey.modifier !== GlobalHotKeyModifier.None) {
hotKeyParts.push(newHotKey.modifier);
}

// Add second key modifier, if any
if (newHotKey.secondModifier && newHotKey.secondModifier !== GlobalHotKeyModifier.None) {
hotKeyParts.push(newHotKey.secondModifier);
}

// Add actual key
hotKeyParts.push(newHotKey.key);
globalShortcut.register(hotKeyParts.join("+"), toggleAction);
}

function calculateX(display: Electron.Display): number {
Expand Down
20 changes: 19 additions & 1 deletion src/renderer/settings/general-settings-component.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const generalSettingsComponent = Vue.extend({
return translations.hotkeyModifierOption;
case GlobalHotKeyModifier.Shift:
return translations.hotkeyModifierShift;
case GlobalHotKeyModifier.Super:
return translations.hotkeyModifierSuper;
default:
return hotkeyModifier;
}
Expand Down Expand Up @@ -392,7 +394,23 @@ export const generalSettingsComponent = Vue.extend({
<div class="control">
<div class="select">
<select v-model="config.generalOptions.hotKey.modifier" @change="updateConfig()">
<option v-for="globalHotKeyModifier in globalHotKeyModifiers" :value="globalHotKeyModifier">
<option v-for="globalHotKeyModifier in globalHotKeyModifiers.filter(key => key != config.generalOptions.hotKey.secondModifier)" :value="globalHotKeyModifier">
{{ getTranslatedGlobalHotKeyModifier(globalHotKeyModifier) }}
</option>
</select>
</div>
</div>
<div class="control">
<button class="button is-static">
<span class="icon">
<i class="fa fa-plus"></i>
</span>
</button>
</div>
<div class="control">
<div class="select">
<select v-model="config.generalOptions.hotKey.secondModifier" @change="updateConfig()">
<option v-for="globalHotKeyModifier in globalHotKeyModifiers.filter(key => key != config.generalOptions.hotKey.modifier)" :value="globalHotKeyModifier">
{{ getTranslatedGlobalHotKeyModifier(globalHotKeyModifier) }}
</option>
</select>
Expand Down

0 comments on commit 5f10c1b

Please sign in to comment.