mirror of
https://github.com/kunkunsh/kunkun.git
synced 2025-04-11 17:29:44 +00:00
feat: write clipboard data to clipboard in clipboard history
This commit is contained in:
parent
2bb24799f3
commit
dea35f261b
@ -2,7 +2,7 @@
|
|||||||
import { goBack, goHome } from "@/utils/route"
|
import { goBack, goHome } from "@/utils/route"
|
||||||
import { listenToNewClipboardItem } from "@/utils/tauri-events"
|
import { listenToNewClipboardItem } from "@/utils/tauri-events"
|
||||||
import Icon from "@iconify/svelte"
|
import Icon from "@iconify/svelte"
|
||||||
import { db } from "@kksh/api/commands"
|
import { ClipboardContentType, db } from "@kksh/api/commands"
|
||||||
import { SearchModeEnum, SQLSortOrderEnum, type ExtData } from "@kksh/api/models"
|
import { SearchModeEnum, SQLSortOrderEnum, type ExtData } from "@kksh/api/models"
|
||||||
import { Button, Command, Resizable } from "@kksh/svelte5"
|
import { Button, Command, Resizable } from "@kksh/svelte5"
|
||||||
import { Constants } from "@kksh/ui"
|
import { Constants } from "@kksh/ui"
|
||||||
@ -10,6 +10,8 @@
|
|||||||
import type { UnlistenFn } from "@tauri-apps/api/event"
|
import type { UnlistenFn } from "@tauri-apps/api/event"
|
||||||
import { ArrowLeft, FileQuestionIcon, ImageIcon, LetterTextIcon } from "lucide-svelte"
|
import { ArrowLeft, FileQuestionIcon, ImageIcon, LetterTextIcon } from "lucide-svelte"
|
||||||
import { onDestroy, onMount, type Snippet } from "svelte"
|
import { onDestroy, onMount, type Snippet } from "svelte"
|
||||||
|
import { toast } from "svelte-sonner"
|
||||||
|
import clipboard from "tauri-plugin-clipboard-api"
|
||||||
import ContentPreview from "./content-preview.svelte"
|
import ContentPreview from "./content-preview.svelte"
|
||||||
|
|
||||||
let searchTerm = $state("")
|
let searchTerm = $state("")
|
||||||
@ -152,6 +154,35 @@
|
|||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onItemSelected(dataId: number) {
|
||||||
|
// fetch data from db
|
||||||
|
db.getExtensionDataById(dataId)
|
||||||
|
.then((data) => {
|
||||||
|
if (!data || !data.data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const dataType = data?.dataType as ClipboardContentType
|
||||||
|
switch (dataType) {
|
||||||
|
case "Text":
|
||||||
|
return clipboard.writeText(data.data)
|
||||||
|
case "Image":
|
||||||
|
return clipboard.writeImageBase64(data.data)
|
||||||
|
case "Html":
|
||||||
|
return clipboard.writeHtml(data.data)
|
||||||
|
case "Rtf":
|
||||||
|
return clipboard.writeRtf(data.data)
|
||||||
|
default:
|
||||||
|
return Promise.reject(new Error("Unsupported data type: " + dataType))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => toast.success("Copied to clipboard"))
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error("Failed to fetch data from db", {
|
||||||
|
description: err.message
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet leftSlot()}
|
{#snippet leftSlot()}
|
||||||
@ -195,7 +226,7 @@
|
|||||||
<Command.List class="h-full max-h-full grow" onscroll={onScroll}>
|
<Command.List class="h-full max-h-full grow" onscroll={onScroll}>
|
||||||
<Command.Empty>No results found.</Command.Empty>
|
<Command.Empty>No results found.</Command.Empty>
|
||||||
{#each clipboardHistoryIds as dataId (dataId)}
|
{#each clipboardHistoryIds as dataId (dataId)}
|
||||||
<Command.Item value={dataId.toString()}>
|
<Command.Item value={dataId.toString()} onSelect={() => onItemSelected(dataId)}>
|
||||||
{@render typeIcon(clipboardHistoryMap[dataId].dataType)}
|
{@render typeIcon(clipboardHistoryMap[dataId].dataType)}
|
||||||
<span class="truncate">{clipboardHistoryMap[dataId].searchText}</span>
|
<span class="truncate">{clipboardHistoryMap[dataId].searchText}</span>
|
||||||
</Command.Item>
|
</Command.Item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user