Skip to content

Commit

Permalink
fix(clipboard): sync clipboard history on clear
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Aug 13, 2023
1 parent 1cbcce8 commit e6aaaa3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum Channel {
CLEAR_CACHE = "CLEAR_CACHE",
CLEAR_PROMPT_CACHE = "CLEAR_PROMPT_CACHE",
CLEAR_PREVIEW = "CLEAR_PREVIEW",
CLEAR_CLIPBOARD_HISTORY = "CLEAR_CLIPBOARD_HISTORY",
CLIPBOARD_SYNC_HISTORY = "CLIPBOARD_SYNC_HISTORY",
CONSOLE_CLEAR = "CONSOLE_CLEAR",
CONSOLE_LOG = "CONSOLE_LOG",
CONSOLE_INFO = "CONSOLE_INFO",
Expand Down
10 changes: 4 additions & 6 deletions src/main/clipboard-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ import {
let transformer = keywordInputTransformer(arg?.keyword)

let createPreview = (item, input) => {
if (item.preview) return item.preview
let content = escapeHTML(item.value)
if (
content === "__enable-clipboard__" ||
content === "__authorize-clipboard__"
) {
return ``
}

if (item?.type === "image") {
return `<div class="p-4 flex justify-center"><img src="${content}" /></div>`
Expand All @@ -45,6 +40,7 @@ let historyWithPreviews = async () => {
{
name: `Clipboard access is not enabled`,
description: `Press Enter to Start the Clipboard Watcher`,
preview: `<div></div>`,
value: "__enable-clipboard__",
},
]
Expand All @@ -55,6 +51,7 @@ let historyWithPreviews = async () => {
{
name: `Clipboard access is not authorized`,
description: `Please open your system preferences and authorize access to the clipboard`,
preview: `<div></div>`,
value: "__authorize-clipboard__",
},
]
Expand All @@ -64,6 +61,7 @@ let historyWithPreviews = async () => {
{
name: `Clipboard is empty`,
description: `Copy something to the clipboard to see it here`,
preview: `<div></div>`,
value: "__empty__",
},
]
Expand Down
6 changes: 5 additions & 1 deletion src/target/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ global.getClipboardHistory = async () => {

global.removeClipboardItem = async (itemId: string) => {
let clipboardStore = await getClipboardStore()
const clipboardHistory = (await clipboardStore.get(
let clipboardHistory = (await clipboardStore.get(
"history"
)) as ClipboardItem[]

Expand All @@ -2134,11 +2134,15 @@ global.removeClipboardItem = async (itemId: string) => {
}

await clipboardStore.set("history", clipboardHistory)

send(Channel.CLIPBOARD_SYNC_HISTORY)
}

global.clearClipboardHistory = async () => {
let clipboardStore = await getClipboardStore()
await clipboardStore.set("history", [])

send(Channel.CLIPBOARD_SYNC_HISTORY)
}

global.submit = async (value: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/types/kitapp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export type GetAppData =

export type SendNoOptions =
| Channel.CLEAR_CACHE
| Channel.CLEAR_CLIPBOARD_HISTORY
| Channel.CLIPBOARD_SYNC_HISTORY
| Channel.CLEAR_PREVIEW
| Channel.CLEAR_PROMPT_CACHE
| Channel.CLEAR_TABS
Expand Down Expand Up @@ -464,7 +464,7 @@ export interface ChannelMap {
[Channel.CLEAR_CACHE]: undefined
[Channel.CLEAR_SCRIPTS_MEMORY]: undefined
[Channel.CLEAR_TABS]: string[]
[Channel.CLEAR_CLIPBOARD_HISTORY]: undefined
[Channel.CLIPBOARD_SYNC_HISTORY]: undefined
[Channel.CLEAR_PROMPT_CACHE]: undefined
[Channel.CLEAR_PREVIEW]: undefined
[Channel.CONSOLE_CLEAR]: undefined
Expand Down

0 comments on commit e6aaaa3

Please sign in to comment.