Skip to content

Commit

Permalink
easy
Browse files Browse the repository at this point in the history
  • Loading branch information
0-don committed Oct 4, 2023
1 parent f6cbed0 commit 5928a14
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/@types/images.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.png";
declare module "*.svg";
declare module "*.jpeg";
declare module "*.jpg";
19 changes: 12 additions & 7 deletions src/components/pages/app/Clipboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const Clipboards: Component<ClipboardsProps> = ({}) => {
star: !clipboard.star,
});
setClipboards((prev) =>
prev.map((o) => (o.id === id ? { ...o, star: !clipboard.star } : o))
prev.map((o) =>
o.id === id ? { ...o, star: !clipboard.star } : o,
),
);
}}
class={`${
Expand Down Expand Up @@ -133,7 +135,7 @@ export const Clipboards: Component<ClipboardsProps> = ({}) => {
? URL.createObjectURL(
new Blob([new Uint8Array(blob)], {
type: "image/png",
})
}),
)
: null;

Expand All @@ -145,10 +147,13 @@ export const Clipboards: Component<ClipboardsProps> = ({}) => {
e.stopPropagation();

if (e.detail === 1) {
dbClickTimer = setTimeout(async () => {
await invoke("copy_clipboard", { id });
removeAllHotkeyListeners();
}, clipboard.type === "image" ? 200 : 0);
dbClickTimer = setTimeout(
async () => {
await invoke("copy_clipboard", { id });
removeAllHotkeyListeners();
},
clipboard.type === "image" ? 200 : 0,
);
}
}}
onDblClick={async (e) => {
Expand Down Expand Up @@ -187,7 +192,7 @@ export const Clipboards: Component<ClipboardsProps> = ({}) => {
class="relative max-h-64 w-full"
alt={`${width}x${height} ${size}`}
title={`${width}x${height} ${formatBytes(
Number(size || "0")
Number(size || "0"),
)}`}
/>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/app/RecentClipboards.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, createEffect, onMount } from "solid-js";
import { Component, onMount } from "solid-js";
import ClipboardStore from "../../../store/ClipboardStore";
import { Clipboards } from "./Clipboards";

Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/app/StarredClipboards.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, createEffect, onMount } from "solid-js";
import { Component, onMount } from "solid-js";
import ClipboardStore, { initialWhere } from "../../../store/ClipboardStore";
import { Clipboards } from "./Clipboards";

Expand Down
18 changes: 8 additions & 10 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { invoke } from "@tauri-apps/api";
import { listen } from "@tauri-apps/api/event";
import { appWindow } from "@tauri-apps/api/window";
import { createResource, onMount } from "solid-js";
import { render } from "solid-js/web";
import App from "./components/pages/app/App";
Expand All @@ -17,17 +15,17 @@ const Index = () => {
onMount(async () => {
setGlobalHotkeyEvent(true);

const focus = await appWindow.onFocusChanged(
async ({ payload }) =>
!payload && (await invoke("window_display_toggle")),
);
// const focus = await appWindow.onFocusChanged(
// async ({ payload }) =>
// !payload && (await invoke("window_display_toggle")),
// );

const init_listener = await listen("init_listener", init);

setTimeout(async () => {
await invoke("stop_hotkeys");
setGlobalHotkeyEvent(false);
}, 5000);
// setTimeout(async () => {
// await invoke("stop_hotkeys");
// setGlobalHotkeyEvent(false);
// }, 5000);

return async () => {
init_listener();
Expand Down
2 changes: 1 addition & 1 deletion src/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Settings = () => {
const { getCurrentTab, initSettings } = SettingsStore;
const { initHotkeys } = HotkeyStore;

initHotkeys(false);
initHotkeys();
initSettings();

return (
Expand Down
6 changes: 2 additions & 4 deletions src/store/HotkeyStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { invoke } from "@tauri-apps/api";
import { createRoot, createSignal } from "solid-js";
import { Hotkey, HotkeyEvent } from "../@types";
import { parseShortcut, registerHotkeys } from "../utils/hotkeyRegister";
import { parseShortcut } from "../utils/hotkeyRegister";

function createHotkeyStore() {
const [globalHotkeyEvent, setGlobalHotkeyEvent] = createSignal<boolean>(true);
Expand All @@ -20,7 +20,7 @@ function createHotkeyStore() {
const getHotkey = (event: HotkeyEvent) =>
hotkeys().find((h) => h.event === event);

const initHotkeys = async (reg: boolean | undefined = false) => {
const initHotkeys = async () => {
// await unregisterAll();

const hotkeys = (await invoke<Hotkey[]>("get_hotkeys")).map((h) => ({
Expand All @@ -41,8 +41,6 @@ function createHotkeyStore() {
// invoke("window_display_toggle");
// }).catch(() => {});
// }

if (reg) await registerHotkeys(hotkeys);
};

return {
Expand Down
2 changes: 1 addition & 1 deletion src/store/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function createSettingsStore() {

const init = async () => {
await initSettings();
// HotkeyStore.initHotkeys(true);
HotkeyStore.initHotkeys();
darkMode();
};

Expand Down
8 changes: 4 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineConfig } from "vite";
import checker from "vite-plugin-checker";
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`
//
// 1. prevent vite from obscuring rust errors
Expand Down

0 comments on commit 5928a14

Please sign in to comment.