Skip to content

Commit c13bbee

Browse files
committed
feat: add recent-doc to examples/api.
1 parent 6acd4f0 commit c13bbee

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

examples/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@tauri-apps/plugin-opener": "^2.5.3",
2727
"@tauri-apps/plugin-os": "^2.3.2",
2828
"@tauri-apps/plugin-process": "^2.3.1",
29+
"@tauri-apps/plugin-recent-doc": "1.0.0",
2930
"@tauri-apps/plugin-shell": "^2.3.5",
3031
"@tauri-apps/plugin-store": "^2.4.2",
3132
"@tauri-apps/plugin-updater": "^2.10.0",

examples/api/src/App.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import Shortcuts from './views/Shortcuts.svelte'
1515
import Shell from './views/Shell.svelte'
1616
import Opener from './views/Opener.svelte'
17+
import RecentDoc from './views/RecentDoc.svelte'
1718
import Store from './views/Store.svelte'
1819
import Updater from './views/Updater.svelte'
1920
import Upload from './views/Upload.svelte'
@@ -98,6 +99,11 @@
9899
component: Opener,
99100
icon: 'i-codicon-link-external'
100101
},
102+
{
103+
label: 'Recent Doc',
104+
component: RecentDoc,
105+
icon: 'i-codicon-history'
106+
},
101107
{
102108
label: 'Store',
103109
component: Store,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script>
2+
import { addRecentDocument, getRecentDocuments, clearRecentDocuments } from '@tauri-apps/plugin-recent-doc'
3+
import { open } from '@tauri-apps/plugin-dialog'
4+
5+
export let onMessage
6+
</script>
7+
8+
<div class="flex flex-col gap-2">
9+
<button
10+
class="btn"
11+
on:click={async () => {
12+
try {
13+
const file = await open({
14+
multiple: false,
15+
title: 'Select a file to add to recent documents'
16+
})
17+
if (file) {
18+
await addRecentDocument(file)
19+
onMessage(`Added "${file}" to recent documents.`)
20+
} else {
21+
onMessage('No file selected.')
22+
}
23+
} catch (e) {
24+
onMessage(e)
25+
}
26+
}}>Add document to recent list</button
27+
>
28+
<button
29+
class="btn"
30+
on:click={async () => {
31+
try {
32+
const files = await getRecentDocuments()
33+
onMessage(files)
34+
} catch (e) {
35+
onMessage(e)
36+
}
37+
}}>Get recent documents</button
38+
>
39+
<button
40+
class="btn"
41+
on:click={async () => {
42+
try {
43+
await clearRecentDocuments()
44+
onMessage('Cleared recent documents.')
45+
} catch (e) {
46+
onMessage(e)
47+
}
48+
}}>Clear recent documents</button
49+
>
50+
</div>

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)