Skip to content

Commit

Permalink
easy
Browse files Browse the repository at this point in the history
  • Loading branch information
0-don committed Oct 1, 2023
1 parent 141d932 commit bdcd53b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Clips>(
Expand All @@ -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();
};
});

Expand Down
15 changes: 6 additions & 9 deletions src/store/HotkeyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hotkey[]>("get_hotkeys")).map((h) => ({
...h,
shortcut: parseShortcut(h),
Expand All @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/utils/hotkeyRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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
Expand All @@ -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 (_) {}

Expand All @@ -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 (_) {}
}

Expand All @@ -122,7 +124,7 @@ export const removeAllHotkeyListeners = async () => {
)
continue;
try {
unregister(hotkey.shortcut);
await unregister(hotkey.shortcut);
} catch (_) {}
}
setGlobalHotkeyEvent(false);
Expand Down
30 changes: 20 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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" }]
}
10 changes: 10 additions & 0 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
1 change: 1 addition & 0 deletions vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
31 changes: 7 additions & 24 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import { join, resolve } from "path";
import checker from "vite-plugin-checker";
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

// https://vitejs.dev/config/
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"),
},
},
},
});

0 comments on commit bdcd53b

Please sign in to comment.