Skip to content

Commit 4134c43

Browse files
committed
chore: document behaviors and requirements.
1 parent a102ae1 commit 4134c43

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

plugins/recent-doc/guest-js/index.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,76 @@
44

55
import { invoke } from '@tauri-apps/api/core'
66

7+
/**
8+
* Manage the operating system recent documents list.
9+
*
10+
* @module
11+
*/
12+
13+
/**
14+
* Adds a document to this app's recent documents list.
15+
*
16+
* #### Platform-specific
17+
*
18+
* - **Linux / Android / iOS:** Unsupported.
19+
*
20+
* @param path Local filesystem path to the document.
21+
*
22+
* @example
23+
* ```typescript
24+
* import { addRecentDocument } from '@tauri-apps/plugin-recent-doc';
25+
* await addRecentDocument('/path/to/document.txt');
26+
* ```
27+
*
28+
* This function rejects when called on an unsupported platform.
29+
* On Windows, it also rejects if the native shell API fails (for example, when the path cannot be resolved).
30+
*
31+
* @since 2.0.0
32+
*/
733
async function addRecentDocument(path: string): Promise<void> {
834
return invoke('plugin:recent-doc|add_recent_document', { path })
935
}
1036

37+
/**
38+
* Gets this app's recent documents list from the operating system.
39+
*
40+
* #### Platform-specific
41+
*
42+
* - **Linux / Android / iOS:** Unsupported.
43+
*
44+
* @example
45+
* ```typescript
46+
* import { getRecentDocuments } from '@tauri-apps/plugin-recent-doc';
47+
* const recent = await getRecentDocuments();
48+
* ```
49+
*
50+
* This function rejects when called on an unsupported platform.
51+
* On Windows, it also rejects if the native shell API fails.
52+
*
53+
* @since 2.0.0
54+
*/
1155
async function getRecentDocuments(): Promise<string[]> {
1256
return invoke<string[]>('plugin:recent-doc|get_recent_documents')
1357
}
1458

59+
/**
60+
* Clears this app's recent documents list in the operating system.
61+
*
62+
* #### Platform-specific
63+
*
64+
* - **Linux / Android / iOS:** Unsupported.
65+
*
66+
* @example
67+
* ```typescript
68+
* import { clearRecentDocuments } from '@tauri-apps/plugin-recent-doc';
69+
* await clearRecentDocuments();
70+
* ```
71+
*
72+
* This function rejects when called on an unsupported platform.
73+
* On Windows, it also rejects if the native shell API fails.
74+
*
75+
* @since 2.0.0
76+
*/
1577
async function clearRecentDocuments(): Promise<void> {
1678
return invoke('plugin:recent-doc|clear_recent_documents')
1779
}

plugins/recent-doc/src/commands.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ impl Drop for ComGuard {
5252
}
5353
}
5454

55+
/// Adds a document to this app's recent documents list on the host OS.
56+
/// You can see the added document in the Jump List on Windows or the Recent Items menu on macOS.
57+
///
58+
/// # Requirements
59+
///
60+
/// - This API is supported on Windows and macOS only.
61+
/// - `path` should be a local filesystem path that the operating system can resolve.
62+
///
63+
/// # Errors
64+
///
65+
/// Returns:
66+
/// - `Error::UnsupportedPlatform` when called on an unsupported platform.
67+
/// - `Error::WindowsError` on Windows when native shell APIs fail.
5568
#[command]
5669
pub fn add_recent_document<R: Runtime>(_app: AppHandle<R>, _path: &str) -> Result<()> {
5770
#[cfg(target_os = "windows")]
@@ -91,6 +104,18 @@ pub fn add_recent_document<R: Runtime>(_app: AppHandle<R>, _path: &str) -> Resul
91104
Ok(())
92105
}
93106

107+
/// Clears this app's recent documents list on the host OS.
108+
/// After clearing, the Jump List on Windows or the Recent Items menu on macOS will be empty until new documents are added with `add_recent_document`.
109+
///
110+
/// # Requirements
111+
///
112+
/// - This API is supported on Windows and macOS only.
113+
///
114+
/// # Errors
115+
///
116+
/// Returns:
117+
/// - `Error::UnsupportedPlatform` when called on an unsupported platform.
118+
/// - `Error::WindowsError` on Windows when native shell APIs fail.
94119
#[command]
95120
pub fn clear_recent_documents<R: Runtime>(_app: AppHandle<R>) -> Result<()> {
96121
#[cfg(target_os = "windows")]
@@ -121,6 +146,17 @@ pub fn clear_recent_documents<R: Runtime>(_app: AppHandle<R>) -> Result<()> {
121146
Ok(())
122147
}
123148

149+
/// Gets this app's recent documents list from the host OS.
150+
///
151+
/// # Requirements
152+
///
153+
/// - This API is supported on Windows and macOS only.
154+
///
155+
/// # Errors
156+
///
157+
/// Returns:
158+
/// - `Error::UnsupportedPlatform` when called on an unsupported platform.
159+
/// - `Error::WindowsError` on Windows when native shell APIs fail.
124160
#[command]
125161
pub fn get_recent_documents<R: Runtime>(_app: AppHandle<R>) -> Result<Vec<String>> {
126162
#[allow(unused_mut)]

0 commit comments

Comments
 (0)