Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0736af1

Browse files
authoredNov 17, 2024
Merge pull request #37 from taroj1205/feat/html-clipboard-support
2 parents d10fd45 + 5793cca commit 0736af1

10 files changed

+75
-30
lines changed
 

‎.changeset/hot-falcons-jump.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"clippr": minor
3+
---
4+
5+
Add support for HTML and ignore file copies

‎.github/workflows/release.yml

+2-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches:
66
- main
77
paths:
8-
- '.changeset/**'
8+
- 'CHANGELOG.md'
99

1010
jobs:
1111
release:
@@ -117,20 +117,6 @@ jobs:
117117
Remove-Item -Path "node_modules" -Recurse -Force -ErrorAction SilentlyContinue
118118
shell: pwsh
119119

120-
- name: Upload Windows NSIS Installer
121-
if: success()
122-
uses: actions/upload-artifact@v3
123-
with:
124-
name: Clippr-nsis
125-
path: src-tauri/target/release/bundle/nsis/clippr_${{ steps.version.outputs.APP_VERSION }}_x64-setup.exe
126-
127-
- name: Upload Windows Executable
128-
if: steps.build-app.outcome == 'success'
129-
uses: actions/upload-artifact@v3
130-
with:
131-
name: Clippr-exe
132-
path: src-tauri/target/release/Clippr.exe
133-
134120
- name: Create Release
135121
id: create_release
136122
if: steps.build-app.outcome == 'success'
@@ -139,7 +125,7 @@ jobs:
139125
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140126
with:
141127
tag_name: v${{ steps.version.outputs.APP_VERSION }}
142-
release_name: Release v${{ steps.version.outputs.APP_VERSION }}
128+
release_name: Clippr v${{ steps.version.outputs.APP_VERSION }}
143129
body: ${{ github.event.pull_request.body }}
144130
draft: true
145131
prerelease: false

‎.github/workflows/version-pr.yml

-6
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ jobs:
6767
6868
gh pr edit $PR_NUMBER --body "This PR was automatically created by the Version PR workflow to update versions and changelogs.
6969
70-
## Changelog Updates
7170
$CHANGELOG_CONTENT
72-
73-
## Checklist
74-
- [ ] Review the changelog updates
75-
- [ ] Verify version bumps are correct
76-
- [ ] Check if any dependencies need manual updates"
7771
fi
7872
env:
7973
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎pnpm-lock.yaml

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/App.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createSignal, For, onCleanup, onMount } from "solid-js";
22
import { emit, listen } from "@tauri-apps/api/event";
33
import { getCurrentWindow } from "@tauri-apps/api/window";
4-
import { writeImageBase64, writeText } from "tauri-plugin-clipboard-api";
4+
import { writeHtml, writeImageBase64, writeText } from "tauri-plugin-clipboard-api";
55
import { invoke } from "@tauri-apps/api/core";
66
import type { ClipboardHistory } from "./types/clipboard";
77
import { SearchInput } from "./components/search-input";
@@ -131,11 +131,14 @@ export const App = ({ db_path }: { db_path: string }) => {
131131
emit("copy-from-app");
132132
if (item.type === "image") {
133133
writeImageBase64(item.image);
134-
} else {
134+
} else if (item.type === "html") {
135+
writeHtml(item.content);
136+
}
137+
else {
135138
writeText(item.content);
136139
}
137140
getCurrentWindow().hide();
138-
};
141+
}
139142

140143
// const handleDelete = async (item: ClipboardHistory) => {
141144
// await invoke<void>("delete_clipboard_from_db", { db_path, id: item.id });

‎src/components/clipboard-item.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ClipboardHistory } from "../types/clipboard";
33
import { cn } from "../utils/tailwind";
44
import { DocumentIcon } from "../icons";
55
import { ImageIcon } from "../icons/image";
6+
import { CodeIcon } from "../icons/code";
67
import { highlightText } from "../utils/highlight";
78

89
interface ClipboardItemProps {
@@ -38,6 +39,16 @@ export const ClipboardItem: Component<ClipboardItemProps> = (props) => {
3839
class="h-full w-full object-cover overflow-hidden"
3940
/>
4041
</>
42+
) : props.item.type === "html" ? (
43+
<>
44+
<CodeIcon class="size-4" />
45+
<p class="w-full overflow-hidden text-left text-ellipsis">
46+
{highlightText(
47+
props.item.content.replace(/<[^>]*>/g, '').trim().split("\n")[0],
48+
props.searchQuery
49+
)}
50+
</p>
51+
</>
4152
) : (
4253
<>
4354
<DocumentIcon class="size-4" />

‎src/components/clipboard-preview.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export const ClipboardPreview: Component<ClipboardPreviewProps> = (props) => {
4040
class="w-full object-contain rounded"
4141
/>
4242
</div>
43+
) : props?.item?.type === "html" ? (
44+
<div class="h-full scroll-area w-full max-h-[390px] overflow-auto">
45+
<div
46+
class="max-w-none"
47+
innerHTML={props.item?.content}
48+
/>
49+
</div>
4350
) : (
4451
<div class="h-full scroll-area w-full max-h-[390px] overflow-auto whitespace-pre-wrap">
4552
{highlightText(props.item?.content, props.searchQuery)}

‎src/icons/code.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component } from "solid-js";
2+
3+
export const CodeIcon: Component<{ class?: string }> = (props) => {
4+
return (
5+
<svg
6+
xmlns="http://www.w3.org/2000/svg"
7+
width="24"
8+
height="24"
9+
viewBox="0 0 24 24"
10+
fill="none"
11+
stroke="currentColor"
12+
stroke-width="2"
13+
stroke-linecap="round"
14+
stroke-linejoin="round"
15+
class={props.class}
16+
>
17+
<polyline points="16 18 22 12 16 6" />
18+
<polyline points="8 6 2 12 8 18" />
19+
</svg>
20+
);
21+
};

‎src/index.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
55
import {
66
hasImage,
77
hasText,
8+
hasHTML,
89
onClipboardUpdate,
910
readText,
1011
readImageBase64,
12+
readHtml,
13+
hasFiles,
1114
} from "tauri-plugin-clipboard-api";
1215
import "./styles.css";
1316
import { App } from "./App";
@@ -26,6 +29,8 @@ const main = async () => {
2629

2730
const [hasImageSignal, setHasImageSignal] = createSignal(false);
2831
const [hasTextSignal, setHasTextSignal] = createSignal(false);
32+
const [hasHtmlSignal, setHasHtmlSignal] = createSignal(false);
33+
const [hasFileSignal, setHasFileSignal] = createSignal(false);
2934
const [prevImage, setPrevImage] = createSignal("");
3035

3136
const [isCopyingFromApp, setIsCopyingFromApp] = createSignal(false);
@@ -36,10 +41,16 @@ const main = async () => {
3641
setIsCopyingFromApp(false);
3742
return;
3843
}
44+
45+
// Skip if clipboard has file
46+
if (hasFileSignal()) return;
47+
3948
const windowTitle = (await appWindow.title()) || "unknown";
4049
const windowExe = "unknown";
4150
const type = hasImageSignal()
4251
? "image"
52+
: hasHtmlSignal()
53+
? "html"
4354
: hasTextSignal()
4455
? "text"
4556
: "unknown";
@@ -66,7 +77,7 @@ const main = async () => {
6677
image,
6778
});
6879
} else {
69-
const content = type === "text" ? await readText() : "";
80+
const content = type === "html" ? await readHtml() : await readText();
7081
await invoke("save_clipboard_to_db", {
7182
db_path,
7283
content,
@@ -87,6 +98,8 @@ const main = async () => {
8798
onClipboardUpdate(async () => {
8899
setHasImageSignal(await hasImage());
89100
setHasTextSignal(await hasText());
101+
setHasHtmlSignal(await hasHTML());
102+
setHasFileSignal(await hasFiles());
90103

91104
await saveClipboard();
92105
emit("clipboard_saved");

‎tailwind.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ export default {
1717
},
1818
},
1919
},
20-
plugins: [scrollbarGutter(), scrollbarWidth(), scrollbarColor()],
20+
plugins: [
21+
scrollbarGutter(),
22+
scrollbarWidth(),
23+
scrollbarColor(),
24+
],
2125
};

0 commit comments

Comments
 (0)
Failed to load comments.