Skip to content

Commit

Permalink
feat: 在 macos 中,磨砂窗口一直处于活跃状态和设置圆角
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Jun 7, 2024
1 parent cc42cc3 commit 11d544e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
9 changes: 7 additions & 2 deletions src-tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ pub fn quit_app() {
#[command]
pub fn frosted_window(window: Window) {
#[cfg(target_os = "macos")]
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
apply_vibrancy(
&window,
NSVisualEffectMaterial::HeaderView,
Some(NSVisualEffectState::Active),
Some(10.0),
)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

#[cfg(target_os = "windows")]
apply_blur(&window, Some((18, 18, 18, 125)))
Expand Down
8 changes: 4 additions & 4 deletions src/database/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export const initDatabase = async () => {
* 执行 sql 语句
* @param sql sql 语句
*/
export const executeSQL = async (query: string, values?: unknown[]) => {
export const executeSQL = async <List,>(query: string, values?: unknown[]) => {
if (!db) {
await initDatabase();
}

if (query.startsWith("SELECT")) {
return await db.select(query, values);
return await db.select<List>(query, values);
}

await db.execute(query, values);
Expand All @@ -41,7 +41,7 @@ export const executeSQL = async (query: string, values?: unknown[]) => {
* @param tableName 表名称
* @returns
*/
export const selectSQL = async (
export const selectSQL = async <List,>(
tableName: TableName,
payload: TablePayload = {},
) => {
Expand All @@ -51,7 +51,7 @@ export const selectSQL = async (

const whereClause = clause ? `WHERE ${clause}` : "";

return await executeSQL(
return await executeSQL<List>(
`SELECT * FROM ${tableName} ${whereClause} ORDER BY id DESC;`,
map(values, (item) => `%${item}%`),
);
Expand Down
48 changes: 28 additions & 20 deletions src/pages/Clipboard/History/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { HistoryItem } from "@/types/database";
import { appWindow } from "@tauri-apps/api/window";
import {
onSomethingUpdate,
Expand All @@ -10,52 +11,59 @@ import {
} from "tauri-plugin-clipboard-api";

const ClipboardWindow = () => {
useMount(() => {
const [, setHistoryList] = useState<HistoryItem[]>();

useMount(async () => {
frostedWindow();

getData();

startListening();

onSomethingUpdate(async (updateTypes) => {
if (updateTypes.files) {
return insertSQL("history", {
await insertSQL("history", {
type: "files",
content: JSON.stringify(await readFilesURIs()),
});
}

if (updateTypes.image) {
return insertSQL("history", {
} else if (updateTypes.image) {
await insertSQL("history", {
type: "image",
content: `data:image/png;base64, ${await readImageBase64()}`,
});
}

if (updateTypes.html) {
return insertSQL("history", {
} else if (updateTypes.html) {
await insertSQL("history", {
type: "html",
content: await readHtml(),
});
}

if (updateTypes.rtf) {
return insertSQL("history", {
} else if (updateTypes.rtf) {
await insertSQL("history", {
type: "rtf",
content: await readRtf(),
});
}

if (updateTypes.text) {
insertSQL("history", {
} else if (updateTypes.text) {
await insertSQL("history", {
type: "text",
content: await readText(),
});
}

getData();
});
});

const getData = async () => {
const list = await selectSQL<HistoryItem[]>("history");

setHistoryList(list);
};

return (
<div className="h-screen" onMouseDown={() => appWindow.startDragging()}>
ClipboardWindow
<div
className="h-screen rounded-8 p-16"
onMouseDown={() => appWindow.startDragging()}
>
1
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/types/database.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export type TableName = "history";

export type HistoryType = "files" | "image" | "html" | "rtf" | "text";

export interface HistoryPayload {
export interface HistoryItem {
id?: number;
type?: HistoryType;
content?: string;
createTime?: string;
isFavorite?: boolean;
}

export type TablePayload = HistoryPayload;
export type TablePayload = HistoryItem;

0 comments on commit 11d544e

Please sign in to comment.