diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 1f9cd8ec..16d3bc6f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1381,9 +1381,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" dependencies = [ "errno-dragonfly", "libc", diff --git a/src/index.tsx b/src/index.tsx index 4cc87de2..e6886879 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -19,12 +19,13 @@ const Index = () => { createResource(init); onMount(async () => { - appWindow.onFocusChanged(({ payload }) => { + console.log("mounted"); + const focus = await appWindow.onFocusChanged(({ payload }) => { console.log(payload); - // if (!payload) { - // appWindow.hide(); - // removeAllHotkeyListeners(); - // } + if (!payload) { + // appWindow.hide(); + // removeAllHotkeyListeners(); + } }); const clipboard_listener = await listen( @@ -41,14 +42,15 @@ const Index = () => { const init_listener = await listen("init_listener", init); - const init_hotkeys_listener = await listen("init_hotkeys_listener", () => { - registerHotkeys(hotkeys()); - }); + const init_hotkeys_listener = await listen("init_hotkeys_listener", () => + registerHotkeys(hotkeys()), + ); return async () => { clipboard_listener(); init_listener(); init_hotkeys_listener(); + focus(); }; }); diff --git a/src/store/HotkeyStore.ts b/src/store/HotkeyStore.ts index a350a0ba..c300722f 100644 --- a/src/store/HotkeyStore.ts +++ b/src/store/HotkeyStore.ts @@ -23,6 +23,8 @@ function createHotkeyStore() { hotkeys().find((h) => h.event === event); const initHotkeys = async (reg: boolean | undefined = false) => { + // await unregisterAll(); + const hotkeys = (await invoke("get_hotkeys")).map((h) => ({ ...h, shortcut: parseShortcut(h), @@ -36,15 +38,10 @@ function createHotkeyStore() { ); if (windowHotkey?.status && !(await isRegistered(windowHotkey.shortcut))) { - try { - register(windowHotkey.shortcut, () => { - console.log("window_display_toggle"); - AppStore.updateSidebarIcons("Recent Clipboards"); - invoke("window_display_toggle"); - }); - } catch (_) { - console.log("error"); - } + register(windowHotkey.shortcut, () => { + AppStore.updateSidebarIcons("Recent Clipboards"); + invoke("window_display_toggle"); + }).catch(() => {}); } if (reg) await registerHotkeys(hotkeys); diff --git a/src/utils/hotkeyRegister.ts b/src/utils/hotkeyRegister.ts index 9bc68334..b0dca646 100644 --- a/src/utils/hotkeyRegister.ts +++ b/src/utils/hotkeyRegister.ts @@ -54,13 +54,13 @@ export async function registerHotkeys(hotkeys: Hotkey[]) { for (const hotkey of siderbarHotkeys) { try { if (hotkey.status) - register(hotkey.shortcut, () => updateSidebarIcons(hotkey.name)); + await register(hotkey.shortcut, () => updateSidebarIcons(hotkey.name)); } catch (_) {} } // copy to clipboard try { - registerAll(CLIPBOARD_HOTKEYS, async (num) => { + await registerAll(CLIPBOARD_HOTKEYS, async (num) => { await invoke("copy_clipboard", { id: clipboards()[Number(num) - 1].id }); removeAllHotkeyListeners(); }); @@ -86,7 +86,7 @@ export async function registerHotkeys(hotkeys: Hotkey[]) { const about = hotkeys.find((h) => h.event === "about"); try { - if (about?.status) register(about.shortcut, createAboutWindow); + if (about?.status) await register(about.shortcut, createAboutWindow); } catch (_) {} //exit @@ -100,7 +100,9 @@ export async function registerHotkeys(hotkeys: Hotkey[]) { try { const scrollToTop = hotkeys.find((h) => h.event === "scroll_to_top"); if (scrollToTop?.status && getCurrentSidebarIcon()?.name !== "View more") { - register(scrollToTop.shortcut, () => clipboardRef()!.scrollTo(0, 0)); + await register(scrollToTop.shortcut, () => + clipboardRef()!.scrollTo(0, 0), + ); } } catch (_) {} @@ -111,7 +113,7 @@ export const removeAllHotkeyListeners = async () => { const { hotkeys, setGlobalHotkeyEvent } = HotkeyStore; for (const key of CLIPBOARD_HOTKEYS) { try { - unregister(key); + await unregister(key); } catch (_) {} } @@ -122,7 +124,7 @@ export const removeAllHotkeyListeners = async () => { ) continue; try { - unregister(hotkey.shortcut); + await unregister(hotkey.shortcut); } catch (_) {} } setGlobalHotkeyEvent(false); diff --git a/tsconfig.json b/tsconfig.json index e5ebb049..39999584 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,26 @@ { "compilerOptions": { - "strict": true, - "target": "ESNext", + "target": "ES2020", + "useDefineForClassFields": true, "module": "ESNext", - "moduleResolution": "Node", - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, "jsx": "preserve", "jsxImportSource": "solid-js", - "types": ["vite/client"], - "noEmit": true, - "isolatedModules": true, - "skipLibCheck": true - } + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 00000000..42872c59 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/vite-env.d.ts b/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/vite.config.ts b/vite.config.ts index 5bb28ad1..8fc7b982 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,3 @@ -import { join, resolve } from "path"; -import checker from "vite-plugin-checker"; import { defineConfig } from "vite"; import solidPlugin from "vite-plugin-solid"; @@ -7,36 +5,21 @@ import solidPlugin from "vite-plugin-solid"; export default defineConfig({ plugins: [ solidPlugin(), - checker({ - typescript: true, - }), + // checker({ + // typescript: true, + // }), ], // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` - // prevent vite from obscuring rust errors + // + // 1. prevent vite from obscuring rust errors clearScreen: false, - // tauri expects a fixed port, fail if that port is not available + // 2. tauri expects a fixed port, fail if that port is not available server: { port: 1420, strictPort: true, }, - // to make use of `TAURI_DEBUG` and other env variables + // 3. to make use of `TAURI_DEBUG` and other env variables // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand envPrefix: ["VITE_", "TAURI_"], - build: { - // Tauri supports es2021 - target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13", - // don't minify for debug builds - minify: !process.env.TAURI_DEBUG ? "esbuild" : false, - // produce sourcemaps for debug builds - sourcemap: !!process.env.TAURI_DEBUG, - - rollupOptions: { - input: { - main: join(resolve(), "index.html"), - about: join(resolve(), "pages/about.html"), - settings: join(resolve(), "pages/settings.html"), - }, - }, - }, });