Skip to content

Commit

Permalink
feat: 新增剪切板历史窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Jun 6, 2024
1 parent e4cc0b2 commit cb63a1a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/layouts/Default/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const DefaultLayout = () => {
const { isDark } = useSnapshot(store);

useMount(() => {
createWindow("/clipboard-history");

listen("github", () => {
open("https://github.com/ayangweb/EcoCopy");
});
Expand Down
15 changes: 15 additions & 0 deletions src/pages/Clipboard/History/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { appWindow } from "@tauri-apps/api/window";

const ClipboardWindow = () => {
useMount(() => {
frostedWindow();
});

return (
<div className="h-screen" onMouseDown={() => appWindow.startDragging()}>
ClipboardWindow
</div>
);
};

export default ClipboardWindow;
File renamed without changes.
21 changes: 19 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { createBrowserRouter } from "react-router-dom";

import DefaultLayout from "@/layouts/Default";
import About from "@/pages/About";
import Clipboard from "@/pages/Clipboard";
import ClipboardHistory from "@/pages/Clipboard/History";
import ClipboardSettings from "@/pages/Clipboard/Settings";
import Settings from "@/pages/Settings";
import type { Route } from "@/types/router";

Expand All @@ -14,7 +15,7 @@ export const routes: Route[] = [
children: [
{
path: "/",
Component: Clipboard,
Component: ClipboardSettings,
meta: {
title: "剪切板",
icon: "i-lucide-clipboard-list",
Expand All @@ -38,6 +39,22 @@ export const routes: Route[] = [
},
],
},
{
path: "/clipboard-history",
Component: ClipboardHistory,
meta: {
windowOptions: {
width: 360,
height: 600,
resizable: false,
maximizable: false,
decorations: false,
// visible: false,
transparent: true,
alwaysOnTop: true,
},
},
},
];

export const router = createBrowserRouter(routes);
6 changes: 3 additions & 3 deletions src/stores/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { subscribeKey } from "valtio/utils";
export const store = proxyWithPersist<GlobalStore>({
name: "global",
initialState: {
theme: "auto",
isDark: false,
autoStart: false,
tabTrigger: "click",
},
Expand All @@ -30,9 +28,11 @@ subscribeKey(store._persist, "loaded", async (loaded) => {
name: await getName(),
version: await getVersion(),
};

store.theme ??= "auto";
});

subscribeKey(store, "theme", async (value) => {
subscribeKey(store, "theme", async (value = "auto") => {
let theme: Theme = value;

if (theme === "auto") {
Expand Down
2 changes: 1 addition & 1 deletion src/types/router.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { WindowOptions } from "@tauri-apps/api/window";
import type { ComponentType } from "react";

export type Path = "/" | "/settings" | "/about";
export type Path = "/" | "/settings" | "/about" | "/clipboard-history";

export interface Route {
path: Path;
Expand Down
4 changes: 2 additions & 2 deletions src/types/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export type Theme = "auto" | "light" | "dark";
export type TabTrigger = "click" | "hover";

export interface GlobalStore {
theme: Theme;
isDark: boolean;
theme?: Theme;
isDark?: boolean;
autoStart: boolean;
tabTrigger: TabTrigger;
wakeUpKey?: Key[];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const frostedWindow = () => invoke("frosted_window");
export const quitApp = () => invoke("quit_app");

/**
* 切换窗口是否可见
* 切换窗口的显示和隐藏
*/
export const toggleWindowVisible = async () => {
const focused = await appWindow.isFocused();
Expand Down

0 comments on commit cb63a1a

Please sign in to comment.