mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-06-16 11:57:38 +02:00
refactor: replace wrdu-keyboard with @waradu/keyboard for keyboard handling
This commit is contained in:
parent
95a4ad624a
commit
5fd0485aa7
3 changed files with 47 additions and 42 deletions
2
app.vue
2
app.vue
|
@ -10,10 +10,8 @@ import { listen } from "@tauri-apps/api/event";
|
||||||
import { app, window } from "@tauri-apps/api";
|
import { app, window } from "@tauri-apps/api";
|
||||||
import { disable, enable } from "@tauri-apps/plugin-autostart";
|
import { disable, enable } from "@tauri-apps/plugin-autostart";
|
||||||
import { onMounted } from "vue";
|
import { onMounted } from "vue";
|
||||||
import { keyboard } from "wrdu-keyboard";
|
|
||||||
|
|
||||||
const { $settings } = useNuxtApp();
|
const { $settings } = useNuxtApp();
|
||||||
keyboard.init();
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await listen("settings", async () => {
|
await listen("settings", async () => {
|
||||||
|
|
|
@ -73,7 +73,6 @@ import type {
|
||||||
InfoColor,
|
InfoColor,
|
||||||
InfoCode,
|
InfoCode,
|
||||||
} from "~/types/types";
|
} from "~/types/types";
|
||||||
import { Key, keyboard } from "wrdu-keyboard";
|
|
||||||
import {
|
import {
|
||||||
selectedGroupIndex,
|
selectedGroupIndex,
|
||||||
selectedItemIndex,
|
selectedItemIndex,
|
||||||
|
@ -82,6 +81,7 @@ import {
|
||||||
} from "~/lib/selectedResult";
|
} from "~/lib/selectedResult";
|
||||||
import IconsEnter from "~/components/Icons/Enter.vue";
|
import IconsEnter from "~/components/Icons/Enter.vue";
|
||||||
import IconsK from "~/components/Icons/K.vue";
|
import IconsK from "~/components/Icons/K.vue";
|
||||||
|
import { Key, useKeyboard } from "@waradu/keyboard";
|
||||||
|
|
||||||
interface GroupedHistory {
|
interface GroupedHistory {
|
||||||
label: string;
|
label: string;
|
||||||
|
@ -90,6 +90,8 @@ interface GroupedHistory {
|
||||||
|
|
||||||
const { $history } = useNuxtApp();
|
const { $history } = useNuxtApp();
|
||||||
|
|
||||||
|
const keyboard = useKeyboard();
|
||||||
|
|
||||||
const CHUNK_SIZE = 50;
|
const CHUNK_SIZE = 50;
|
||||||
const SCROLL_THRESHOLD = 100;
|
const SCROLL_THRESHOLD = 100;
|
||||||
const SCROLL_PADDING = 8;
|
const SCROLL_PADDING = 8;
|
||||||
|
@ -527,33 +529,33 @@ const setupEventListeners = async (): Promise<void> => {
|
||||||
}
|
}
|
||||||
focusSearchInput();
|
focusSearchInput();
|
||||||
|
|
||||||
keyboard.clear();
|
keyboard.init();
|
||||||
keyboard.prevent.down([Key.DownArrow], () => {
|
keyboard.listen([Key.DownArrow], () => {
|
||||||
selectNext();
|
selectNext();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.UpArrow], () => {
|
keyboard.listen([Key.UpArrow], () => {
|
||||||
selectPrevious();
|
selectPrevious();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.Enter], () => {
|
keyboard.listen([Key.Enter], () => {
|
||||||
pasteSelectedItem();
|
pasteSelectedItem();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.Escape], () => {
|
keyboard.listen([Key.Escape], () => {
|
||||||
hideApp();
|
hideApp();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
switch (os.value) {
|
switch (os.value) {
|
||||||
case "macos":
|
case "macos":
|
||||||
keyboard.prevent.down([Key.LeftMeta, Key.K], () => { });
|
keyboard.listen([Key.Meta, Key.K], () => { }, { prevent: true });
|
||||||
keyboard.prevent.down([Key.RightMeta, Key.K], () => { });
|
keyboard.listen([Key.Meta, Key.K], () => { }, { prevent: true });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "linux":
|
case "linux":
|
||||||
case "windows":
|
case "windows":
|
||||||
keyboard.prevent.down([Key.LeftControl, Key.K], () => { });
|
keyboard.listen([Key.Control, Key.K], () => { }, { prevent: true });
|
||||||
keyboard.prevent.down([Key.RightControl, Key.K], () => { });
|
keyboard.listen([Key.Control, Key.K], () => { }, { prevent: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -563,32 +565,32 @@ const setupEventListeners = async (): Promise<void> => {
|
||||||
keyboard.clear();
|
keyboard.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
keyboard.prevent.down([Key.DownArrow], () => {
|
keyboard.listen([Key.DownArrow], () => {
|
||||||
selectNext();
|
selectNext();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.UpArrow], () => {
|
keyboard.listen([Key.UpArrow], () => {
|
||||||
selectPrevious();
|
selectPrevious();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.Enter], () => {
|
keyboard.listen([Key.Enter], () => {
|
||||||
pasteSelectedItem();
|
pasteSelectedItem();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.Escape], () => {
|
keyboard.listen([Key.Escape], () => {
|
||||||
hideApp();
|
hideApp();
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
switch (os.value) {
|
switch (os.value) {
|
||||||
case "macos":
|
case "macos":
|
||||||
keyboard.prevent.down([Key.LeftMeta, Key.K], () => { });
|
keyboard.listen([Key.Meta, Key.K], () => { }, { prevent: true });
|
||||||
keyboard.prevent.down([Key.RightMeta, Key.K], () => { });
|
keyboard.listen([Key.Meta, Key.K], () => { }, { prevent: true });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "linux":
|
case "linux":
|
||||||
case "windows":
|
case "windows":
|
||||||
keyboard.prevent.down([Key.LeftControl, Key.K], () => { });
|
keyboard.listen([Key.Control, Key.K], () => { }, { prevent: true });
|
||||||
keyboard.prevent.down([Key.RightControl, Key.K], () => { });
|
keyboard.listen([Key.Control, Key.K], () => { }, { prevent: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -633,6 +635,10 @@ onMounted(async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
keyboard.clear();
|
||||||
|
});
|
||||||
|
|
||||||
const getFormattedDate = computed(() => {
|
const getFormattedDate = computed(() => {
|
||||||
if (!selectedItem.value?.timestamp) return "";
|
if (!selectedItem.value?.timestamp) return "";
|
||||||
return new Intl.DateTimeFormat("en-US", {
|
return new Intl.DateTimeFormat("en-US", {
|
||||||
|
|
|
@ -79,9 +79,9 @@ import { platform } from "@tauri-apps/plugin-os";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import { KeyValues, KeyLabels } from "../types/keys";
|
import { KeyValues, KeyLabels } from "../types/keys";
|
||||||
import { disable, enable } from "@tauri-apps/plugin-autostart";
|
import { disable, enable } from "@tauri-apps/plugin-autostart";
|
||||||
import { Key, keyboard } from "wrdu-keyboard";
|
|
||||||
import BottomBar from "../components/BottomBar.vue";
|
import BottomBar from "../components/BottomBar.vue";
|
||||||
import IconsEnter from "~/components/Icons/Enter.vue";
|
import IconsEnter from "~/components/Icons/Enter.vue";
|
||||||
|
import { Key, useKeyboard } from "@waradu/keyboard";
|
||||||
|
|
||||||
const activeModifiers = reactive<Set<KeyValues>>(new Set());
|
const activeModifiers = reactive<Set<KeyValues>>(new Set());
|
||||||
const isKeybindInputFocused = ref(false);
|
const isKeybindInputFocused = ref(false);
|
||||||
|
@ -93,6 +93,7 @@ const router = useRouter();
|
||||||
const showEmptyKeybindError = ref(false);
|
const showEmptyKeybindError = ref(false);
|
||||||
const autostart = ref(false);
|
const autostart = ref(false);
|
||||||
const { $settings } = useNuxtApp();
|
const { $settings } = useNuxtApp();
|
||||||
|
const keyboard = useKeyboard();
|
||||||
|
|
||||||
const modifierKeySet = new Set([
|
const modifierKeySet = new Set([
|
||||||
KeyValues.AltLeft,
|
KeyValues.AltLeft,
|
||||||
|
@ -174,48 +175,48 @@ const toggleAutostart = async () => {
|
||||||
os.value = platform();
|
os.value = platform();
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
keyboard.prevent.down([Key.All], (event: KeyboardEvent) => {
|
keyboard.listen([Key.All], (event: KeyboardEvent) => {
|
||||||
if (isKeybindInputFocused.value) {
|
if (isKeybindInputFocused.value) {
|
||||||
onKeyDown(event);
|
onKeyDown(event);
|
||||||
}
|
}
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.Escape], () => {
|
keyboard.listen([Key.Escape], () => {
|
||||||
if (isKeybindInputFocused.value) {
|
if (isKeybindInputFocused.value) {
|
||||||
keybindInput.value?.blur();
|
keybindInput.value?.blur();
|
||||||
} else {
|
} else {
|
||||||
router.push("/");
|
router.push("/");
|
||||||
}
|
}
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
switch (os.value) {
|
switch (os.value) {
|
||||||
case "macos":
|
case "macos":
|
||||||
keyboard.prevent.down([Key.LeftMeta, Key.Enter], () => {
|
keyboard.listen([Key.Meta, Key.Enter], () => {
|
||||||
if (!isKeybindInputFocused.value) {
|
if (!isKeybindInputFocused.value) {
|
||||||
saveKeybind();
|
saveKeybind();
|
||||||
}
|
}
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.RightMeta, Key.Enter], () => {
|
keyboard.listen([Key.Meta, Key.Enter], () => {
|
||||||
if (!isKeybindInputFocused.value) {
|
if (!isKeybindInputFocused.value) {
|
||||||
saveKeybind();
|
saveKeybind();
|
||||||
}
|
}
|
||||||
});
|
}, { prevent: true });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "linux":
|
case "linux":
|
||||||
case "windows":
|
case "windows":
|
||||||
keyboard.prevent.down([Key.LeftControl, Key.Enter], () => {
|
keyboard.listen([Key.Control, Key.Enter], () => {
|
||||||
if (!isKeybindInputFocused.value) {
|
if (!isKeybindInputFocused.value) {
|
||||||
saveKeybind();
|
saveKeybind();
|
||||||
}
|
}
|
||||||
});
|
}, { prevent: true });
|
||||||
|
|
||||||
keyboard.prevent.down([Key.RightControl, Key.Enter], () => {
|
keyboard.listen([Key.Control, Key.Enter], () => {
|
||||||
if (!isKeybindInputFocused.value) {
|
if (!isKeybindInputFocused.value) {
|
||||||
saveKeybind();
|
saveKeybind();
|
||||||
}
|
}
|
||||||
});
|
}, { prevent: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue