Skip to content

Commit 00749a9

Browse files
committed
refactor: cleaning and formatting
1 parent e674e0a commit 00749a9

File tree

12 files changed

+480
-121
lines changed

12 files changed

+480
-121
lines changed

pages/settings.vue

+68-54
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
<p>Save</p>
1515
<div>
1616
<img alt="" src="../public/cmd.svg" v-if="os === 'macos'" />
17-
<img alt="" src="../public/ctrl.svg" v-if="os === 'linux' || os === 'windows'" />
17+
<img
18+
alt=""
19+
src="../public/ctrl.svg"
20+
v-if="os === 'linux' || os === 'windows'" />
1821
<img alt="" src="../public/enter.svg" />
1922
</div>
2023
</div>
@@ -28,16 +31,14 @@
2831
@keydown="onKeyDown"
2932
class="keybind-input"
3033
ref="keybindInput"
31-
tabindex="0"
32-
>
34+
tabindex="0">
3335
<span class="key" v-if="keybind.length === 0">Click here</span>
3436
<template v-else>
3537
<span
3638
:key="index"
3739
class="key"
3840
:class="{ modifier: isModifier(key) }"
39-
v-for="(key, index) in keybind"
40-
>
41+
v-for="(key, index) in keybind">
4142
{{ keyToDisplay(key) }}
4243
</span>
4344
</template>
@@ -47,46 +48,54 @@
4748
</template>
4849

4950
<script setup lang="ts">
50-
import { invoke } from '@tauri-apps/api/core';
51-
import { onMounted, onUnmounted, reactive, ref } from 'vue';
52-
import { platform } from '@tauri-apps/plugin-os';
53-
import { useRouter } from 'vue-router';
51+
import { invoke } from "@tauri-apps/api/core";
52+
import { onMounted, onUnmounted, reactive, ref } from "vue";
53+
import { platform } from "@tauri-apps/plugin-os";
54+
import { useRouter } from "vue-router";
5455
5556
const activeModifiers = reactive<Set<string>>(new Set());
5657
const isKeybindInputFocused = ref(false);
5758
const keybind = ref<string[]>([]);
5859
const keybindInput = ref<HTMLElement | null>(null);
5960
const lastBlurTime = ref(0);
60-
const os = ref('');
61+
const os = ref("");
6162
const router = useRouter();
6263
const keyboard = useKeyboard();
6364
6465
const keyToDisplayMap: Record<string, string> = {
65-
' ': 'Space',
66-
Alt: 'Alt',
67-
AltLeft: 'Alt L',
68-
AltRight: 'Alt R',
69-
ArrowDown: '',
70-
ArrowLeft: '',
71-
ArrowRight: '',
72-
ArrowUp: '',
73-
Control: 'Ctrl',
74-
ControlLeft: 'Ctrl L',
75-
ControlRight: 'Ctrl R',
76-
Enter: '',
77-
Meta: 'Meta',
78-
MetaLeft: 'Meta L',
79-
MetaRight: 'Meta R',
80-
Shift: '',
81-
ShiftLeft: '⇧ L',
82-
ShiftRight: '⇧ R',
66+
" ": "Space",
67+
Alt: "Alt",
68+
AltLeft: "Alt L",
69+
AltRight: "Alt R",
70+
ArrowDown: "",
71+
ArrowLeft: "",
72+
ArrowRight: "",
73+
ArrowUp: "",
74+
Control: "Ctrl",
75+
ControlLeft: "Ctrl L",
76+
ControlRight: "Ctrl R",
77+
Enter: "",
78+
Meta: "Meta",
79+
MetaLeft: "Meta L",
80+
MetaRight: "Meta R",
81+
Shift: "",
82+
ShiftLeft: "⇧ L",
83+
ShiftRight: "⇧ R",
8384
};
8485
8586
const modifierKeySet = new Set([
86-
'Alt', 'AltLeft', 'AltRight',
87-
'Control', 'ControlLeft', 'ControlRight',
88-
'Meta', 'MetaLeft', 'MetaRight',
89-
'Shift', 'ShiftLeft', 'ShiftRight'
87+
"Alt",
88+
"AltLeft",
89+
"AltRight",
90+
"Control",
91+
"ControlLeft",
92+
"ControlRight",
93+
"Meta",
94+
"MetaLeft",
95+
"MetaRight",
96+
"Shift",
97+
"ShiftLeft",
98+
"ShiftRight",
9099
]);
91100
92101
const isModifier = (key: string): boolean => {
@@ -99,7 +108,7 @@ const keyToDisplay = (key: string): string => {
99108
100109
const updateKeybind = () => {
101110
const modifiers = Array.from(activeModifiers).sort();
102-
const nonModifiers = keybind.value.filter(key => !isModifier(key));
111+
const nonModifiers = keybind.value.filter((key) => !isModifier(key));
103112
keybind.value = [...modifiers, ...nonModifiers];
104113
};
105114
@@ -118,7 +127,7 @@ const onKeyDown = (event: KeyboardEvent) => {
118127
event.preventDefault();
119128
const key = event.code;
120129
121-
if (key === 'Escape') {
130+
if (key === "Escape") {
122131
if (keybindInput.value) {
123132
keybindInput.value.blur();
124133
}
@@ -128,48 +137,53 @@ const onKeyDown = (event: KeyboardEvent) => {
128137
if (isModifier(key)) {
129138
activeModifiers.add(key);
130139
} else if (!keybind.value.includes(key)) {
131-
keybind.value = keybind.value.filter(k => isModifier(k));
140+
keybind.value = keybind.value.filter((k) => isModifier(k));
132141
keybind.value.push(key);
133142
}
134-
143+
135144
updateKeybind();
136145
};
137146
138147
const saveKeybind = async () => {
139-
console.log('New:', keybind.value);
140-
const oldKeybind = await invoke<string[]>('get_keybind');
141-
console.log('Old:', oldKeybind);
142-
await invoke('save_keybind', { keybind: keybind.value });
148+
console.log("New:", keybind.value);
149+
const oldKeybind = await invoke<string[]>("get_keybind");
150+
console.log("Old:", oldKeybind);
151+
await invoke("save_keybind", { keybind: keybind.value });
143152
};
144153
145154
onMounted(() => {
146155
os.value = platform();
147156
148-
keyboard.down('all', (event) => {
149-
const isMacSaveCombo = os.value === 'macos' &&
150-
(event.code === 'MetaLeft' || event.code === 'MetaRight') &&
151-
event.key === 'Enter';
152-
153-
const isOtherOsSaveCombo = os.value !== 'macos' &&
154-
(event.code === 'ControlLeft' || event.code === 'ControlRight') &&
155-
event.key === 'Enter';
156-
157-
if ((isMacSaveCombo || isOtherOsSaveCombo) && !isKeybindInputFocused.value) {
157+
keyboard.down("all", (event) => {
158+
const isMacSaveCombo =
159+
os.value === "macos" &&
160+
(event.code === "MetaLeft" || event.code === "MetaRight") &&
161+
event.key === "Enter";
162+
163+
const isOtherOsSaveCombo =
164+
os.value !== "macos" &&
165+
(event.code === "ControlLeft" || event.code === "ControlRight") &&
166+
event.key === "Enter";
167+
168+
if (
169+
(isMacSaveCombo || isOtherOsSaveCombo) &&
170+
!isKeybindInputFocused.value
171+
) {
158172
event.preventDefault();
159173
saveKeybind();
160174
}
161175
});
162176
163-
keyboard.down('Escape', (event) => {
177+
keyboard.down("Escape", (event) => {
164178
const now = Date.now();
165179
if (!isKeybindInputFocused.value && now - lastBlurTime.value > 100) {
166180
event.preventDefault();
167-
router.push('/');
181+
router.push("/");
168182
}
169183
});
170184
});
171185
</script>
172186

173187
<style scoped lang="scss">
174-
@use '~/assets/css/settings.scss';
175-
</style>
188+
@use "~/assets/css/settings.scss";
189+
</style>

plugins/history.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ export default defineNuxtPlugin(() => {
2727
});
2828
},
2929

30-
async getImagePath(path: string): Promise<string> {
31-
return await invoke<string>("get_image_path", { path });
30+
async deleteHistoryItem(id: string): Promise<void> {
31+
await invoke<void>("delete_history_item", { id });
32+
},
33+
34+
async clearHistory(): Promise<void> {
35+
await invoke<void>("clear_history");
3236
},
3337

3438
async writeAndPaste(data: {

0 commit comments

Comments
 (0)