chore: fix 'space' key not being recognised (#21)

This commit is contained in:
Parth Jadhav
2023-01-02 20:40:24 +05:30
committed by GitHub
parent 39e4355aa1
commit 177e4d6fd2
3 changed files with 27 additions and 13 deletions
+3
View File
@@ -50,10 +50,13 @@ fn main() {
"Show" => {
let window = app.get_window("main").unwrap();
window.show().unwrap();
window.center().unwrap();
}
"Preferences" => {
let window = app.get_window("main").unwrap();
window.emit("PreferencesClicked", Some("Yes")).unwrap();
window.show().unwrap();
window.center().unwrap();
}
"Quit" => {
std::process::exit(0);
+6 -7
View File
@@ -53,7 +53,6 @@ const reloadTheme = async () => {
settings: true
}
});
appWindow.show();
});
@@ -61,18 +60,18 @@ const reloadTheme = async () => {
enable: preferences.get("launch_on_login"),
});
await changeAppHotkey(preferences.get("shortcut"));
await listenForHotkey(preferences.get("shortcut"));
})();
export async function changeAppHotkey(shortcut: string) {
export async function listenForHotkey(shortcut: string) {
await register(shortcut, async () => {
if (document.hasFocus()) {
await appWindow.hide()
} else {
await appWindow.show()
await appWindow.center()
await appWindow.setFocus()
document.getElementById('searchBarInput').focus()
await appWindow.show();
await appWindow.center();
await appWindow.setFocus();
document.getElementById('searchBarInput').focus();
}
})
}
@@ -2,7 +2,7 @@
import hotkeys from "hotkeys-js";
import { preferences, paths } from "../../../../cache";
import { writeTextFile } from "@tauri-apps/api/fs";
import { changeAppHotkey } from "../../../../main";
import { listenForHotkey } from "../../../../main";
import { unregister } from "@tauri-apps/api/globalShortcut";
let shortcutArray: string[] = preferences.get("shortcut").split("+");
@@ -27,7 +27,7 @@
).then(() => {
unregister(preferences.get("shortcut")).then(() => {
preferences.set("shortcut", newShortcutString);
changeAppHotkey(newShortcutString);
listenForHotkey(newShortcutString);
});
});
}
@@ -40,16 +40,28 @@
if (shortcutArray.length < 3) {
if (shortcutArray.length === 0) {
if (modifiers.includes(event.key)) {
shortcutArray.push(event.key);
if (event.key === " "){
shortcutArray.push("Space");
} else {
shortcutArray.push(event.key);
}
shortcutArray = shortcutArray;
}
} else {
if (!modifiers.includes(event.key)) {
shortcutArray.push(event.key);
if (event.key === " "){
shortcutArray.push("Space");
} else {
shortcutArray.push(event.key);
}
updateShortcutPreference(shortcutArray);
hotkeys.unbind();
} else {
shortcutArray.push(event.key);
if (event.key === " "){
shortcutArray.push("Space");
} else {
shortcutArray.push(event.key);
}
}
shortcutArray = shortcutArray.filter(
(value, index, self) => {
@@ -64,7 +76,7 @@
}
if (event.type === "keyup") {
if (shortcutArray.length === 1) {
shortcutArray = ["Command", "G"];
shortcutArray = ["Command", "Shift", "G"];
updateShortcutPreference(shortcutArray);
hotkeys.unbind();
} else if (shortcutArray.length > 1) {