diff --git a/.changes/config.json b/.changes/config.json index 93ed46e3fc..f7083d55a5 100644 --- a/.changes/config.json +++ b/.changes/config.json @@ -73,6 +73,7 @@ "fs", "global-shortcut", "opener", + "recent-doc", "http", "nfc", "notification", @@ -207,6 +208,14 @@ "path": "./plugins/opener", "manager": "javascript" }, + "recent-doc": { + "path": "./plugins/recent-doc", + "manager": "rust" + }, + "recent-doc-js": { + "path": "./plugins/recent-doc", + "manager": "javascript" + }, "haptics": { "path": "./plugins/haptics", "manager": "rust" diff --git a/.changes/recent-doc-initial.md b/.changes/recent-doc-initial.md new file mode 100644 index 0000000000..b2081a7af7 --- /dev/null +++ b/.changes/recent-doc-initial.md @@ -0,0 +1,6 @@ +--- +"recent-doc": "major" +"recent-doc-js": "major" +--- + +Initial Release diff --git a/.github/workflows/check-generated-files.yml b/.github/workflows/check-generated-files.yml index 6a513b2374..901a74e061 100644 --- a/.github/workflows/check-generated-files.yml +++ b/.github/workflows/check-generated-files.yml @@ -66,6 +66,11 @@ jobs: - pnpm-lock.yaml - plugins/opener/guest-js/** - plugins/opener/src/api-iife.js + recent-doc: + - .github/workflows/check-generated-files.yml + - pnpm-lock.yaml + - plugins/recent-doc/guest-js/** + - plugins/recent-doc/src/api-iife.js haptics: - .github/workflows/check-generated-files.yml - pnpm-lock.yaml diff --git a/.github/workflows/lint-rust.yml b/.github/workflows/lint-rust.yml index 7b4ad191d0..90750a170f 100644 --- a/.github/workflows/lint-rust.yml +++ b/.github/workflows/lint-rust.yml @@ -69,6 +69,9 @@ jobs: tauri-plugin-opener: - .github/workflows/lint-rust.yml - plugins/opener/** + tauri-plugin-recent-doc: + - .github/workflows/lint-rust.yml + - plugins/recent-doc/** tauri-plugin-haptics: - .github/workflows/lint-rust.yml - plugins/haptics/** diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 76f2e0ecd9..0616a07359 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -90,6 +90,11 @@ jobs: - Cargo.toml - Cargo.lock - plugins/opener/** + tauri-plugin-recent-doc: + - .github/workflows/test-rust.yml + - Cargo.toml + - Cargo.lock + - plugins/recent-doc/** tauri-plugin-haptics: - .github/workflows/test-rust.yml - Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index a91e02bc3e..99330d9d91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -230,6 +230,7 @@ dependencies = [ "tauri-plugin-opener", "tauri-plugin-os", "tauri-plugin-process", + "tauri-plugin-recent-doc", "tauri-plugin-shell", "tauri-plugin-store", "tauri-plugin-updater", @@ -293,11 +294,11 @@ dependencies = [ "clipboard-win", "image", "log", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", "windows-sys 0.59.0", @@ -691,7 +692,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" dependencies = [ - "objc2 0.6.3", + "objc2 0.6.4", ] [[package]] @@ -1551,7 +1552,7 @@ dependencies = [ "bitflags 2.9.0", "block2 0.6.2", "libc", - "objc2 0.6.3", + "objc2 0.6.4", ] [[package]] @@ -2445,7 +2446,7 @@ checksum = "b9247516746aa8e53411a0db9b62b0e24efbcf6a76e0ba73e5a91b512ddabed7" dependencies = [ "crossbeam-channel", "keyboard-types", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "once_cell", "serde", @@ -3479,8 +3480,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b95dfb34071d1592b45622bf93e315e3a72d414b6782aca9a015c12bec367ef" dependencies = [ "cc", - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "objc2 0.6.4", + "objc2-foundation 0.3.2", "time", ] @@ -3633,10 +3634,10 @@ dependencies = [ "dpi", "gtk", "keyboard-types", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "once_cell", "png", "serde", @@ -3893,9 +3894,9 @@ dependencies = [ [[package]] name = "objc2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05" +checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f" dependencies = [ "objc2-encode", "objc2-exception-helper", @@ -3903,75 +3904,104 @@ dependencies = [ [[package]] name = "objc2-app-kit" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5906f93257178e2f7ae069efb89fbd6ee94f0592740b5f8a1512ca498814d0fb" +checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.9.0", "block2 0.6.2", "libc", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-cloud-kit", "objc2-core-data", "objc2-core-foundation", "objc2-core-graphics", "objc2-core-image", - "objc2-foundation 0.3.0", - "objc2-quartz-core 0.3.0", + "objc2-core-text", + "objc2-core-video", + "objc2-foundation 0.3.2", + "objc2-quartz-core 0.3.2", ] [[package]] name = "objc2-cloud-kit" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c1948a9be5f469deadbd6bcb86ad7ff9e47b4f632380139722f7d9840c0d42c" +checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "objc2 0.6.4", + "objc2-foundation 0.3.2", ] [[package]] name = "objc2-core-data" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f860f8e841f6d32f754836f51e6bc7777cd7e7053cf18528233f6811d3eceb4" +checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "objc2 0.6.4", + "objc2-foundation 0.3.2", ] [[package]] name = "objc2-core-foundation" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daeaf60f25471d26948a1c2f840e3f7d86f4109e3af4e8e4b5cd70c39690d925" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", + "dispatch2", + "objc2 0.6.4", ] [[package]] name = "objc2-core-graphics" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dca602628b65356b6513290a21a6405b4d4027b8b250f0b98dddbb28b7de02" +checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", + "dispatch2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-io-surface", ] [[package]] name = "objc2-core-image" -version = "0.3.0" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006" +dependencies = [ + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-core-text" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ffa6bea72bf42c78b0b34e89c0bafac877d5f80bf91e159a5d96ea7f693ca56" +checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d" dependencies = [ - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "bitflags 2.9.0", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-core-graphics", +] + +[[package]] +name = "objc2-core-video" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6" +dependencies = [ + "bitflags 2.9.0", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-io-surface", ] [[package]] @@ -4003,25 +4033,25 @@ dependencies = [ [[package]] name = "objc2-foundation" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a21c6c9014b82c39515db5b396f91645182611c97d24637cf56ac01e5f8d998" +checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.9.0", "block2 0.6.2", "libc", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-core-foundation", ] [[package]] name = "objc2-io-surface" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161a8b87e32610086e1a7a9e9ec39f84459db7b3a0881c1f16ca5a2605581c19" +checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-core-foundation", ] @@ -4044,9 +4074,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1ac59da3ceebc4a82179b35dc550431ad9458f9cc326e053f49ba371ce76c5a" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -4064,13 +4094,13 @@ dependencies = [ [[package]] name = "objc2-quartz-core" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb3794501bb1bee12f08dcad8c61f2a5875791ad1c6f47faa71a0f033f20071" +checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "objc2 0.6.4", + "objc2-foundation 0.3.2", ] [[package]] @@ -4080,7 +4110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3126341c65c5d5728423ae95d788e1b660756486ad0592307ab87ba02d9a7268" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-core-foundation", ] @@ -4091,9 +4121,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "777a571be14a42a3990d4ebedaeb8b54cd17377ec21b92e8200ac03797b3bee1" dependencies = [ "bitflags 2.9.0", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -4104,10 +4134,10 @@ checksum = "b717127e4014b0f9f3e8bba3d3f2acec81f1bde01f656823036e823ed2c94dce" dependencies = [ "bitflags 2.9.0", "block2 0.6.2", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-security", ] @@ -4251,8 +4281,8 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "732c71caeaa72c065bb69d7ea08717bd3f4863a4f451402fc9513e29dbd5261b" dependencies = [ - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "objc2 0.6.4", + "objc2-foundation 0.3.2", "objc2-osa-kit", "serde", "serde_json", @@ -5152,10 +5182,10 @@ dependencies = [ "gtk-sys", "js-sys", "log", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "pollster", "raw-window-handle", "urlencoding", @@ -6413,9 +6443,9 @@ dependencies = [ "ndk", "ndk-context", "ndk-sys", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "once_cell", "parking_lot", "raw-window-handle", @@ -6487,9 +6517,9 @@ dependencies = [ "log", "mime", "muda", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-ui-kit", "objc2-web-kit", "percent-encoding", @@ -6707,7 +6737,7 @@ dependencies = [ "log", "notify", "notify-debouncer-full", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "percent-encoding", "schemars", "serde", @@ -6804,8 +6834,8 @@ dependencies = [ "byte-unit", "fern", "log", - "objc2 0.6.3", - "objc2-foundation 0.3.0", + "objc2 0.6.4", + "objc2-foundation 0.3.2", "serde", "serde_json", "serde_repr", @@ -6856,7 +6886,7 @@ dependencies = [ "dunce", "glob", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "open", "schemars", "serde", @@ -6920,6 +6950,22 @@ dependencies = [ "tauri-plugin", ] +[[package]] +name = "tauri-plugin-recent-doc" +version = "1.0.0" +dependencies = [ + "log", + "objc2 0.6.4", + "objc2-app-kit", + "objc2-foundation 0.3.2", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.12", + "windows 0.61.1", +] + [[package]] name = "tauri-plugin-shell" version = "2.3.5" @@ -7099,7 +7145,7 @@ dependencies = [ "gtk", "http", "jni", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-ui-kit", "objc2-web-kit", "raw-window-handle", @@ -7123,9 +7169,9 @@ dependencies = [ "http", "jni", "log", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "once_cell", "percent-encoding", "raw-window-handle", @@ -7636,11 +7682,11 @@ dependencies = [ "dirs 6.0.0", "libappindicator", "muda", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "once_cell", "png", "serde", @@ -8368,10 +8414,10 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9bec5a31f3f9362f2258fd0e9c9dd61a9ca432e7306cc78c444258f0dce9a9c" dependencies = [ - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "raw-window-handle", "windows-sys 0.59.0", "windows-version", @@ -8437,9 +8483,9 @@ dependencies = [ [[package]] name = "windows-implement" -version = "0.60.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", @@ -8448,9 +8494,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.1" +version = "0.59.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", @@ -8927,10 +8973,10 @@ dependencies = [ "kuchikiki", "libc", "ndk", - "objc2 0.6.3", + "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-ui-kit", "objc2-web-kit", "once_cell", diff --git a/examples/api/package.json b/examples/api/package.json index 4d28727bb5..cd9e83abda 100644 --- a/examples/api/package.json +++ b/examples/api/package.json @@ -26,6 +26,7 @@ "@tauri-apps/plugin-opener": "^2.5.3", "@tauri-apps/plugin-os": "^2.3.2", "@tauri-apps/plugin-process": "^2.3.1", + "@tauri-apps/plugin-recent-doc": "1.0.0", "@tauri-apps/plugin-shell": "^2.3.5", "@tauri-apps/plugin-store": "^2.4.2", "@tauri-apps/plugin-updater": "^2.10.1", diff --git a/examples/api/src-tauri/Cargo.toml b/examples/api/src-tauri/Cargo.toml index caf45ed673..81002e2a88 100644 --- a/examples/api/src-tauri/Cargo.toml +++ b/examples/api/src-tauri/Cargo.toml @@ -36,6 +36,7 @@ tauri-plugin-notification = { path = "../../../plugins/notification", version = tauri-plugin-os = { path = "../../../plugins/os", version = "2.3.2" } tauri-plugin-process = { path = "../../../plugins/process", version = "2.3.1" } tauri-plugin-opener = { path = "../../../plugins/opener", version = "2.5.3" } +tauri-plugin-recent-doc = { path = "../../../plugins/recent-doc", version = "1.0.0" } tauri-plugin-shell = { path = "../../../plugins/shell", version = "2.3.5" } tauri-plugin-store = { path = "../../../plugins/store", version = "2.4.2" } tauri-plugin-upload = { path = "../../../plugins/upload", version = "2.3.0" } diff --git a/examples/api/src-tauri/capabilities/base.json b/examples/api/src-tauri/capabilities/base.json index f7fd7dff01..138bae6b06 100644 --- a/examples/api/src-tauri/capabilities/base.json +++ b/examples/api/src-tauri/capabilities/base.json @@ -98,6 +98,7 @@ "identifier": "opener:allow-open-path", "allow": [{ "path": "$APPDATA" }, { "path": "$APPDATA/**" }] }, - "upload:default" + "upload:default", + "recent-doc:default" ] } diff --git a/examples/api/src-tauri/src/lib.rs b/examples/api/src-tauri/src/lib.rs index 3c58f2c81d..f5c79738a9 100644 --- a/examples/api/src-tauri/src/lib.rs +++ b/examples/api/src-tauri/src/lib.rs @@ -37,6 +37,7 @@ pub fn run() { .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_opener::init()) + .plugin(tauri_plugin_recent_doc::init()) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_store::Builder::default().build()) .plugin(tauri_plugin_upload::init()) diff --git a/examples/api/src/App.svelte b/examples/api/src/App.svelte index 8e114c4b9d..37313e37d1 100644 --- a/examples/api/src/App.svelte +++ b/examples/api/src/App.svelte @@ -14,6 +14,7 @@ import Shortcuts from './views/Shortcuts.svelte' import Shell from './views/Shell.svelte' import Opener from './views/Opener.svelte' + import RecentDoc from './views/RecentDoc.svelte' import Store from './views/Store.svelte' import Updater from './views/Updater.svelte' import Upload from './views/Upload.svelte' @@ -98,6 +99,11 @@ component: Opener, icon: 'i-codicon-link-external' }, + { + label: 'Recent Doc', + component: RecentDoc, + icon: 'i-codicon-history' + }, { label: 'Store', component: Store, diff --git a/examples/api/src/views/RecentDoc.svelte b/examples/api/src/views/RecentDoc.svelte new file mode 100644 index 0000000000..2564c82120 --- /dev/null +++ b/examples/api/src/views/RecentDoc.svelte @@ -0,0 +1,54 @@ + + +
+ + + +
diff --git a/plugins/recent-doc/Cargo.toml b/plugins/recent-doc/Cargo.toml new file mode 100644 index 0000000000..1e69f4e067 --- /dev/null +++ b/plugins/recent-doc/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "tauri-plugin-recent-doc" +version = "1.0.0" +description = "Manage recent documents in your Tauri application." +edition = { workspace = true } +authors = { workspace = true } +license = { workspace = true } +rust-version = { workspace = true } +repository = { workspace = true } +links = "tauri-plugin-recent-doc" + +# Platforms supported by the plugin +# Support levels are "full", "partial", "none", "unknown" +# Details of the support level are left to plugin maintainer +[package.metadata.platforms] +windows = { level = "full", notes = "" } +linux = { level = "none", notes = "" } +macos = { level = "full", notes = "" } +android = { level = "none", notes = "" } +ios = { level = "none", notes = "" } + + +[build-dependencies] +tauri-plugin = { workspace = true, features = ["build"] } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { workspace = true } +serde_json = { workspace = true } +tauri = { workspace = true } +log = { workspace = true } +thiserror = { workspace = true } + +[target."cfg(target_os = \"macos\")".dependencies] +objc2 = "0.6.0" +objc2-foundation = { version = "0.3.2", features = [ + "NSString", + "NSURL", + "NSArray", +] } +objc2-app-kit = { version = "0.3.2", features = ["NSDocumentController"] } + +[target."cfg(target_os = \"windows\")".dependencies] +windows = { version = "0.61", features = [ + "Win32_Foundation", + "Win32_System_Com", + "Win32_UI_Shell", + "Win32_UI_Shell_Common", + "Win32_Storage_FileSystem", +] } diff --git a/plugins/recent-doc/LICENSE.spdx b/plugins/recent-doc/LICENSE.spdx new file mode 100644 index 0000000000..cdd0df5ad7 --- /dev/null +++ b/plugins/recent-doc/LICENSE.spdx @@ -0,0 +1,20 @@ +SPDXVersion: SPDX-2.1 +DataLicense: CC0-1.0 +PackageName: tauri +DataFormat: SPDXRef-1 +PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy +PackageHomePage: https://tauri.app +PackageLicenseDeclared: Apache-2.0 +PackageLicenseDeclared: MIT +PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy +PackageSummary: Tauri is a rust project that enables developers to make secure +and small desktop applications using a web frontend. + +PackageComment: The package includes the following libraries; see +Relationship information. + +Created: 2019-05-20T09:00:00Z +PackageDownloadLocation: git://github.com/tauri-apps/tauri +PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git +PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git +Creator: Person: Daniel Thompson-Yvetot \ No newline at end of file diff --git a/plugins/recent-doc/LICENSE_APACHE-2.0 b/plugins/recent-doc/LICENSE_APACHE-2.0 new file mode 100644 index 0000000000..4947287f7b --- /dev/null +++ b/plugins/recent-doc/LICENSE_APACHE-2.0 @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/plugins/recent-doc/LICENSE_MIT b/plugins/recent-doc/LICENSE_MIT new file mode 100644 index 0000000000..4d75472566 --- /dev/null +++ b/plugins/recent-doc/LICENSE_MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 - Present Tauri Apps Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/plugins/recent-doc/README.md b/plugins/recent-doc/README.md new file mode 100644 index 0000000000..b6c537c5e8 --- /dev/null +++ b/plugins/recent-doc/README.md @@ -0,0 +1,102 @@ +![plugin-recent-doc](https://github.com/tauri-apps/plugins-workspace/raw/v2/plugins/recent-doc/banner.png) + + + +| Platform | Supported | +| -------- | --------- | +| Linux | x | +| Windows | ✓ | +| macOS | ✓ | +| Android | x | +| iOS | x | + +## Install + +_This plugin requires a Rust version of at least **1.77.2**_ + +There are three general methods of installation that we can recommend. + +1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked) +2. Pull sources directly from Github using git tags / revision hashes (most secure) +3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use) + +Install the Core plugin by adding the following to your `Cargo.toml` file: + +`src-tauri/Cargo.toml` + +```toml +[dependencies] +tauri-plugin-recent-doc = "1.0.0" +# alternatively with Git: +tauri-plugin-recent-doc = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } +``` + +You can install the JavaScript Guest bindings using your preferred JavaScript package manager: + +```sh +pnpm add @tauri-apps/plugin-recent-doc +# or +npm add @tauri-apps/plugin-recent-doc +# or +yarn add @tauri-apps/plugin-recent-doc +``` + +## Usage + +First you need to register the core plugin with Tauri: + +`src-tauri/src/lib.rs` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_recent_doc::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} +``` + +Afterwards all the plugin's APIs are available through the JavaScript guest bindings: + +```javascript +import { + addRecentDocument, + clearRecentDocuments, + getRecentDocument +} from '@tauri-apps/plugin-recent-doc' + +// Add a file to the OS recent documents list +await addRecentDocument('/path/to/your/document.txt') + +// Get the recent documents list +const recentDocs = await getRecentDocument() + +// Clear all recent documents from the OS list +await clearRecentDocuments() +``` + +## Contributing + +PRs accepted. Please make sure to read the Contributing Guide before making a pull request. + +## Partners + + + + + + + +
+ + CrabNebula + +
+ +For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri). + +## License + +Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy. + +MIT or MIT/Apache 2.0 where applicable. diff --git a/plugins/recent-doc/SECURITY.md b/plugins/recent-doc/SECURITY.md new file mode 100644 index 0000000000..4f09bbacd4 --- /dev/null +++ b/plugins/recent-doc/SECURITY.md @@ -0,0 +1,23 @@ +# Security Policy + +**Do not report security vulnerabilities through public GitHub issues.** + +**Please use the [Private Vulnerability Disclosure](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability#privately-reporting-a-security-vulnerability) feature of GitHub.** + +Include as much of the following information: + +- Type of issue (e.g. improper input parsing, privilege escalation, etc.) +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- The distribution affected or used to help us with reproduction of the issue +- Step-by-step instructions to reproduce the issue +- Ideally a reproduction repository +- Impact of the issue, including how an attacker might exploit the issue + +We prefer to receive reports in English. + +## Contact + +Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new). + +Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app). diff --git a/plugins/recent-doc/api-iife.js b/plugins/recent-doc/api-iife.js new file mode 100644 index 0000000000..9e81ea182e --- /dev/null +++ b/plugins/recent-doc/api-iife.js @@ -0,0 +1 @@ +if("__TAURI__"in window){var __TAURI_PLUGIN_RECENT_DOC__=function(e){"use strict";async function n(e,n={},t){return window.__TAURI_INTERNALS__.invoke(e,n,t)}return"function"==typeof SuppressedError&&SuppressedError,e.addRecentDocument=async function(e){return n("plugin:recent-doc|add_recent_document",{path:e})},e.clearRecentDocuments=async function(){return n("plugin:recent-doc|clear_recent_documents")},e.getRecentDocuments=async function(){return n("plugin:recent-doc|get_recent_documents")},e}({});Object.defineProperty(window.__TAURI__,"recentDoc",{value:__TAURI_PLUGIN_RECENT_DOC__})} diff --git a/plugins/recent-doc/build.rs b/plugins/recent-doc/build.rs new file mode 100644 index 0000000000..cee653f951 --- /dev/null +++ b/plugins/recent-doc/build.rs @@ -0,0 +1,15 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +const COMMANDS: &[&str] = &[ + "add_recent_document", + "get_recent_documents", + "clear_recent_documents", +]; + +fn main() { + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); +} diff --git a/plugins/recent-doc/guest-js/index.ts b/plugins/recent-doc/guest-js/index.ts new file mode 100644 index 0000000000..98883dd796 --- /dev/null +++ b/plugins/recent-doc/guest-js/index.ts @@ -0,0 +1,69 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +import { invoke } from '@tauri-apps/api/core' + +/** + * Manage the operating system recent documents list. + * + * @module + */ + +/** + * Adds a document to this app's recent documents list. + * + * @param path Local filesystem path to the document. + * + * @example + * ```typescript + * import { addRecentDocument } from '@tauri-apps/plugin-recent-doc'; + * await addRecentDocument('/path/to/document.txt'); + * ``` + * + * This function rejects when called on an unsupported platform. + * On Windows, it also rejects if the native shell API fails (for example, when the path cannot be resolved). + * + * @since 2.0.0 + */ +async function addRecentDocument(path: string): Promise { + return invoke('plugin:recent-doc|add_recent_document', { path }) +} + +/** + * Gets this app's recent documents list from the operating system. + * + * @example + * ```typescript + * import { getRecentDocuments } from '@tauri-apps/plugin-recent-doc'; + * const recent = await getRecentDocuments(); + * ``` + * + * This function rejects when called on an unsupported platform. + * On Windows, it also rejects if the native shell API fails. + * + * @since 2.0.0 + */ +async function getRecentDocuments(): Promise { + return invoke('plugin:recent-doc|get_recent_documents') +} + +/** + * Clears this app's recent documents list in the operating system. + * + * @example + * ```typescript + * import { clearRecentDocuments } from '@tauri-apps/plugin-recent-doc'; + * await clearRecentDocuments(); + * ``` + * + * This function rejects when called on an unsupported platform. + * On Windows, it also rejects if the native shell API fails. + * + * @since 2.0.0 + */ +async function clearRecentDocuments(): Promise { + return invoke('plugin:recent-doc|clear_recent_documents') +} + +export { addRecentDocument, getRecentDocuments, clearRecentDocuments } diff --git a/plugins/recent-doc/package.json b/plugins/recent-doc/package.json new file mode 100644 index 0000000000..bba67e9c7f --- /dev/null +++ b/plugins/recent-doc/package.json @@ -0,0 +1,29 @@ +{ + "name": "@tauri-apps/plugin-recent-doc", + "version": "1.0.0", + "license": "MIT OR Apache-2.0", + "authors": [ + "Tauri Programme within The Commons Conservancy" + ], + "repository": "https://github.com/tauri-apps/plugins-workspace", + "type": "module", + "types": "./dist-js/index.d.ts", + "main": "./dist-js/index.cjs", + "module": "./dist-js/index.js", + "exports": { + "types": "./dist-js/index.d.ts", + "import": "./dist-js/index.js", + "require": "./dist-js/index.cjs" + }, + "scripts": { + "build": "rollup -c" + }, + "files": [ + "dist-js", + "README.md", + "LICENSE" + ], + "dependencies": { + "@tauri-apps/api": "^2.6.0" + } +} diff --git a/plugins/recent-doc/permissions/autogenerated/commands/add_recent_document.toml b/plugins/recent-doc/permissions/autogenerated/commands/add_recent_document.toml new file mode 100644 index 0000000000..b3b66eba01 --- /dev/null +++ b/plugins/recent-doc/permissions/autogenerated/commands/add_recent_document.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-add-recent-document" +description = "Enables the add_recent_document command without any pre-configured scope." +commands.allow = ["add_recent_document"] + +[[permission]] +identifier = "deny-add-recent-document" +description = "Denies the add_recent_document command without any pre-configured scope." +commands.deny = ["add_recent_document"] diff --git a/plugins/recent-doc/permissions/autogenerated/commands/clear_recent_documents.toml b/plugins/recent-doc/permissions/autogenerated/commands/clear_recent_documents.toml new file mode 100644 index 0000000000..a3cf12abe0 --- /dev/null +++ b/plugins/recent-doc/permissions/autogenerated/commands/clear_recent_documents.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-clear-recent-documents" +description = "Enables the clear_recent_documents command without any pre-configured scope." +commands.allow = ["clear_recent_documents"] + +[[permission]] +identifier = "deny-clear-recent-documents" +description = "Denies the clear_recent_documents command without any pre-configured scope." +commands.deny = ["clear_recent_documents"] diff --git a/plugins/recent-doc/permissions/autogenerated/commands/get_recent_documents.toml b/plugins/recent-doc/permissions/autogenerated/commands/get_recent_documents.toml new file mode 100644 index 0000000000..8c28a20949 --- /dev/null +++ b/plugins/recent-doc/permissions/autogenerated/commands/get_recent_documents.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-get-recent-documents" +description = "Enables the get_recent_documents command without any pre-configured scope." +commands.allow = ["get_recent_documents"] + +[[permission]] +identifier = "deny-get-recent-documents" +description = "Denies the get_recent_documents command without any pre-configured scope." +commands.deny = ["get_recent_documents"] diff --git a/plugins/recent-doc/permissions/autogenerated/reference.md b/plugins/recent-doc/permissions/autogenerated/reference.md new file mode 100644 index 0000000000..091d1c5c6c --- /dev/null +++ b/plugins/recent-doc/permissions/autogenerated/reference.md @@ -0,0 +1,102 @@ +## Default Permission + +This permission set configures what kind of +operations are available from the recent-doc plugin. + +#### Granted Permissions + +All operations are enabled by default. + +#### This default permission set includes the following: + +- `allow-add-recent-document` +- `allow-get-recent-documents` +- `allow-clear-recent-documents` + +## Permission Table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdentifierDescription
+ +`recent-doc:allow-add-recent-document` + + + +Enables the add_recent_document command without any pre-configured scope. + +
+ +`recent-doc:deny-add-recent-document` + + + +Denies the add_recent_document command without any pre-configured scope. + +
+ +`recent-doc:allow-clear-recent-documents` + + + +Enables the clear_recent_documents command without any pre-configured scope. + +
+ +`recent-doc:deny-clear-recent-documents` + + + +Denies the clear_recent_documents command without any pre-configured scope. + +
+ +`recent-doc:allow-get-recent-documents` + + + +Enables the get_recent_documents command without any pre-configured scope. + +
+ +`recent-doc:deny-get-recent-documents` + + + +Denies the get_recent_documents command without any pre-configured scope. + +
diff --git a/plugins/recent-doc/permissions/default.toml b/plugins/recent-doc/permissions/default.toml new file mode 100644 index 0000000000..4e3c984435 --- /dev/null +++ b/plugins/recent-doc/permissions/default.toml @@ -0,0 +1,17 @@ +"$schema" = "schemas/schema.json" + +[default] +description = """ +This permission set configures what kind of +operations are available from the recent-doc plugin. + +#### Granted Permissions + +All operations are enabled by default. + +""" +permissions = [ + "allow-add-recent-document", + "allow-get-recent-documents", + "allow-clear-recent-documents", +] diff --git a/plugins/recent-doc/permissions/schemas/schema.json b/plugins/recent-doc/permissions/schemas/schema.json new file mode 100644 index 0000000000..6a31119dee --- /dev/null +++ b/plugins/recent-doc/permissions/schemas/schema.json @@ -0,0 +1,342 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PermissionFile", + "description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.", + "type": "object", + "properties": { + "default": { + "description": "The default permission set for the plugin", + "anyOf": [ + { + "$ref": "#/definitions/DefaultPermission" + }, + { + "type": "null" + } + ] + }, + "set": { + "description": "A list of permissions sets defined", + "type": "array", + "items": { + "$ref": "#/definitions/PermissionSet" + } + }, + "permission": { + "description": "A list of inlined permissions", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/Permission" + } + } + }, + "definitions": { + "DefaultPermission": { + "description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.", + "type": "object", + "required": [ + "permissions" + ], + "properties": { + "version": { + "description": "The version of the permission.", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 1.0 + }, + "description": { + "description": "Human-readable description of what the permission does. Tauri convention is to use `

` headings in markdown content for Tauri documentation generation purposes.", + "type": [ + "string", + "null" + ] + }, + "permissions": { + "description": "All permissions this set contains.", + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "PermissionSet": { + "description": "A set of direct permissions grouped together under a new name.", + "type": "object", + "required": [ + "description", + "identifier", + "permissions" + ], + "properties": { + "identifier": { + "description": "A unique identifier for the permission.", + "type": "string" + }, + "description": { + "description": "Human-readable description of what the permission does.", + "type": "string" + }, + "permissions": { + "description": "All permissions this set contains.", + "type": "array", + "items": { + "$ref": "#/definitions/PermissionKind" + } + } + } + }, + "Permission": { + "description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.", + "type": "object", + "required": [ + "identifier" + ], + "properties": { + "version": { + "description": "The version of the permission.", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 1.0 + }, + "identifier": { + "description": "A unique identifier for the permission.", + "type": "string" + }, + "description": { + "description": "Human-readable description of what the permission does. Tauri internal convention is to use `

` headings in markdown content for Tauri documentation generation purposes.", + "type": [ + "string", + "null" + ] + }, + "commands": { + "description": "Allowed or denied commands when using this permission.", + "default": { + "allow": [], + "deny": [] + }, + "allOf": [ + { + "$ref": "#/definitions/Commands" + } + ] + }, + "scope": { + "description": "Allowed or denied scoped when using this permission.", + "allOf": [ + { + "$ref": "#/definitions/Scopes" + } + ] + }, + "platforms": { + "description": "Target platforms this permission applies. By default all platforms are affected by this permission.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Target" + } + } + } + }, + "Commands": { + "description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.", + "type": "object", + "properties": { + "allow": { + "description": "Allowed command.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "deny": { + "description": "Denied command, which takes priority.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "Scopes": { + "description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```", + "type": "object", + "properties": { + "allow": { + "description": "Data that defines what is allowed by the scope.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Value" + } + }, + "deny": { + "description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Value" + } + } + } + }, + "Value": { + "description": "All supported ACL values.", + "anyOf": [ + { + "description": "Represents a null JSON value.", + "type": "null" + }, + { + "description": "Represents a [`bool`].", + "type": "boolean" + }, + { + "description": "Represents a valid ACL [`Number`].", + "allOf": [ + { + "$ref": "#/definitions/Number" + } + ] + }, + { + "description": "Represents a [`String`].", + "type": "string" + }, + { + "description": "Represents a list of other [`Value`]s.", + "type": "array", + "items": { + "$ref": "#/definitions/Value" + } + }, + { + "description": "Represents a map of [`String`] keys to [`Value`]s.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Value" + } + } + ] + }, + "Number": { + "description": "A valid ACL number.", + "anyOf": [ + { + "description": "Represents an [`i64`].", + "type": "integer", + "format": "int64" + }, + { + "description": "Represents a [`f64`].", + "type": "number", + "format": "double" + } + ] + }, + "Target": { + "description": "Platform target.", + "oneOf": [ + { + "description": "MacOS.", + "type": "string", + "enum": [ + "macOS" + ] + }, + { + "description": "Windows.", + "type": "string", + "enum": [ + "windows" + ] + }, + { + "description": "Linux.", + "type": "string", + "enum": [ + "linux" + ] + }, + { + "description": "Android.", + "type": "string", + "enum": [ + "android" + ] + }, + { + "description": "iOS.", + "type": "string", + "enum": [ + "iOS" + ] + } + ] + }, + "PermissionKind": { + "type": "string", + "oneOf": [ + { + "description": "Enables the add_recent_document command without any pre-configured scope.", + "type": "string", + "const": "allow-add-recent-document", + "markdownDescription": "Enables the add_recent_document command without any pre-configured scope." + }, + { + "description": "Denies the add_recent_document command without any pre-configured scope.", + "type": "string", + "const": "deny-add-recent-document", + "markdownDescription": "Denies the add_recent_document command without any pre-configured scope." + }, + { + "description": "Enables the clear_recent_documents command without any pre-configured scope.", + "type": "string", + "const": "allow-clear-recent-documents", + "markdownDescription": "Enables the clear_recent_documents command without any pre-configured scope." + }, + { + "description": "Denies the clear_recent_documents command without any pre-configured scope.", + "type": "string", + "const": "deny-clear-recent-documents", + "markdownDescription": "Denies the clear_recent_documents command without any pre-configured scope." + }, + { + "description": "Enables the get_recent_documents command without any pre-configured scope.", + "type": "string", + "const": "allow-get-recent-documents", + "markdownDescription": "Enables the get_recent_documents command without any pre-configured scope." + }, + { + "description": "Denies the get_recent_documents command without any pre-configured scope.", + "type": "string", + "const": "deny-get-recent-documents", + "markdownDescription": "Denies the get_recent_documents command without any pre-configured scope." + }, + { + "description": "This permission set configures what kind of\noperations are available from the recent-doc plugin.\n\n#### Granted Permissions\n\nAll operations are enabled by default.\n\n\n#### This default permission set includes:\n\n- `allow-add-recent-document`\n- `allow-get-recent-documents`\n- `allow-clear-recent-documents`", + "type": "string", + "const": "default", + "markdownDescription": "This permission set configures what kind of\noperations are available from the recent-doc plugin.\n\n#### Granted Permissions\n\nAll operations are enabled by default.\n\n\n#### This default permission set includes:\n\n- `allow-add-recent-document`\n- `allow-get-recent-documents`\n- `allow-clear-recent-documents`" + } + ] + } + } +} \ No newline at end of file diff --git a/plugins/recent-doc/rollup.config.js b/plugins/recent-doc/rollup.config.js new file mode 100644 index 0000000000..1f349ec8a2 --- /dev/null +++ b/plugins/recent-doc/rollup.config.js @@ -0,0 +1,7 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +import { createConfig } from '../../shared/rollup.config.js' + +export default createConfig() diff --git a/plugins/recent-doc/src/commands.rs b/plugins/recent-doc/src/commands.rs new file mode 100644 index 0000000000..8c8aa2fffc --- /dev/null +++ b/plugins/recent-doc/src/commands.rs @@ -0,0 +1,213 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use crate::error::Result; +use tauri::{command, AppHandle, Runtime}; + +#[cfg(target_os = "windows")] +use windows::{ + core::{HSTRING, PCWSTR}, + Win32::{ + System::Com::{ + CoCreateInstance, CoInitializeEx, CoTaskMemFree, CoUninitialize, CLSCTX_INPROC_SERVER, + COINIT_APARTMENTTHREADED, + }, + UI::Shell::{ + ApplicationDestinations, ApplicationDocumentLists, Common::IObjectArray, + IApplicationDestinations, IApplicationDocumentLists, IShellItem, SHAddToRecentDocs, + SHCreateItemFromParsingName, ADLT_RECENT, SHARDAPPIDINFO, SHARD_APPIDINFO, + SIGDN_FILESYSPATH, + }, + }, +}; + +#[cfg(target_os = "macos")] +use { + objc2::MainThreadMarker, + objc2_app_kit::NSDocumentController, + objc2_foundation::{NSString, NSURL}, +}; + +/// ComGuard ensures that the COM library is properly initialized and uninitialized on Windows. +#[cfg(target_os = "windows")] +struct ComGuard; + +#[cfg(target_os = "windows")] +impl ComGuard { + fn new() -> Self { + unsafe { + let _ = CoInitializeEx(None, COINIT_APARTMENTTHREADED); + } + ComGuard + } +} + +#[cfg(target_os = "windows")] +impl Drop for ComGuard { + fn drop(&mut self) { + unsafe { + CoUninitialize(); + } + } +} + +/// Adds a document to this app's recent documents list on the host OS. +/// You can see the added document in the Jump List on Windows or the Recent Items menu on macOS. +/// +/// # Requirements +/// +/// - This API is supported on Windows and macOS only. +/// - `path` should be a local filesystem path that the operating system can resolve. +/// - For installer-based Windows builds, declare handled extensions in `tauri.conf.json` under `bundle.fileAssociations` so install/uninstall manages associations automatically. +/// +/// # Errors +/// +/// Returns: +/// - `Error::UnsupportedPlatform` when called on an unsupported platform. +/// - `Error::WindowsError` on Windows when native shell APIs fail. +#[command] +pub fn add_recent_document(_app: AppHandle, _path: &str) -> Result<()> { + #[cfg(target_os = "windows")] + unsafe { + let _com_guard = ComGuard::new(); + + let app_id = &_app.config().identifier; + let app_id_hstring = HSTRING::from(app_id); + + let path_hstring = HSTRING::from(_path); + let item = SHCreateItemFromParsingName(&path_hstring, None)?; + + let info = SHARDAPPIDINFO { + pszAppID: PCWSTR::from_raw(app_id_hstring.as_ptr()), + psi: std::mem::ManuallyDrop::new(Some(item)), + }; + + SHAddToRecentDocs( + SHARD_APPIDINFO.0 as u32, + Some(&info as *const _ as *const core::ffi::c_void), + ); + } + + #[cfg(target_os = "macos")] + { + let ns_path = NSURL::fileURLWithPath(&NSString::from_str(_path)); + let mtm = MainThreadMarker::new().expect("AppKit API must be called on the main thread"); + let controller = NSDocumentController::sharedDocumentController(mtm); + controller.noteNewRecentDocumentURL(&ns_path); + } + + #[cfg(all(unix, not(target_os = "macos")))] + { + Err(crate::error::Error::UnsupportedPlatform)?; + } + + Ok(()) +} + +/// Clears this app's recent documents list on the host OS. +/// 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`. +/// +/// # Requirements +/// +/// - This API is supported on Windows and macOS only. +/// +/// # Errors +/// +/// Returns: +/// - `Error::UnsupportedPlatform` when called on an unsupported platform. +/// - `Error::WindowsError` on Windows when native shell APIs fail. +#[command] +pub fn clear_recent_documents(_app: AppHandle) -> Result<()> { + #[cfg(target_os = "windows")] + unsafe { + let _guard = ComGuard::new(); + + let app_id = &_app.config().identifier; + let app_id_hstring = HSTRING::from(app_id); + + let dests: IApplicationDestinations = + CoCreateInstance(&ApplicationDestinations, None, CLSCTX_INPROC_SERVER)?; + dests.SetAppID(&app_id_hstring)?; + dests.RemoveAllDestinations()?; + } + + #[cfg(target_os = "macos")] + unsafe { + let mtm = MainThreadMarker::new().expect("AppKit API must be called on the main thread"); + let controller = NSDocumentController::sharedDocumentController(mtm); + controller.clearRecentDocuments(None); + } + + #[cfg(all(unix, not(target_os = "macos")))] + { + Err(crate::error::Error::UnsupportedPlatform)?; + } + + Ok(()) +} + +/// Gets this app's recent documents list from the host OS. +/// +/// # Requirements +/// +/// - This API is supported on Windows and macOS only. +/// +/// # Errors +/// +/// Returns: +/// - `Error::UnsupportedPlatform` when called on an unsupported platform. +/// - `Error::WindowsError` on Windows when native shell APIs fail. +#[command] +pub fn get_recent_documents(_app: AppHandle) -> Result> { + #[allow(unused_mut)] + let mut recent_docs = Vec::new(); + + #[cfg(target_os = "windows")] + unsafe { + let _guard = ComGuard::new(); + + let app_id = &_app.config().identifier; + let app_id_hstring = HSTRING::from(app_id); + + let doc_lists: IApplicationDocumentLists = + CoCreateInstance(&ApplicationDocumentLists, None, CLSCTX_INPROC_SERVER)?; + doc_lists.SetAppID(&app_id_hstring)?; + let obj_array: IObjectArray = doc_lists.GetList(ADLT_RECENT, 30)?; + let count = obj_array.GetCount()?; + + for i in 0..count { + if let Ok(shell_item) = obj_array.GetAt::(i) { + if let Ok(name_pwstr) = shell_item.GetDisplayName(SIGDN_FILESYSPATH) { + if let Ok(path) = name_pwstr.to_string() { + if !path.is_empty() { + recent_docs.push(path); + } + } + + CoTaskMemFree(Some(name_pwstr.as_ptr() as *const core::ffi::c_void)); + } + } + } + } + + #[cfg(target_os = "macos")] + { + let mtm = MainThreadMarker::new().expect("AppKit API must be called on the main thread"); + let controller = NSDocumentController::sharedDocumentController(mtm); + let urls = controller.recentDocumentURLs(); + + for url in &*urls { + if let Some(ns_path) = url.path() { + recent_docs.push(ns_path.to_string()); + } + } + } + + #[cfg(all(unix, not(target_os = "macos")))] + { + Err(crate::error::Error::UnsupportedPlatform)?; + } + + Ok(recent_docs) +} diff --git a/plugins/recent-doc/src/error.rs b/plugins/recent-doc/src/error.rs new file mode 100644 index 0000000000..846fc980f1 --- /dev/null +++ b/plugins/recent-doc/src/error.rs @@ -0,0 +1,32 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use serde::{ser::Serializer, Serialize}; + +pub type Result = std::result::Result; + +#[derive(Debug, thiserror::Error)] +#[allow(unused)] +pub enum Error { + #[error("API not supported on the current platform")] + UnsupportedPlatform, + #[error("Invalid path: {0}")] + InvalidPath(String), + // Transform windows error into our error type + #[error(transparent)] + #[cfg(target_os = "windows")] + WindowsError(#[from] windows::core::Error), + #[error(transparent)] + #[cfg(target_os = "windows")] + Utf16(#[from] std::string::FromUtf16Error), +} + +impl Serialize for Error { + fn serialize(&self, serializer: S) -> std::result::Result + where + S: Serializer, + { + serializer.serialize_str(self.to_string().as_ref()) + } +} diff --git a/plugins/recent-doc/src/lib.rs b/plugins/recent-doc/src/lib.rs new file mode 100644 index 0000000000..4d6fed791e --- /dev/null +++ b/plugins/recent-doc/src/lib.rs @@ -0,0 +1,24 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +mod commands; +mod error; + +pub use commands::{add_recent_document, clear_recent_documents, get_recent_documents}; +pub use error::{Error, Result}; + +use tauri::{ + plugin::{Builder, TauriPlugin}, + Runtime, +}; + +pub fn init() -> TauriPlugin { + Builder::new("recent-doc") + .invoke_handler(tauri::generate_handler![ + commands::add_recent_document, + commands::clear_recent_documents, + commands::get_recent_documents + ]) + .build() +} diff --git a/plugins/recent-doc/tsconfig.json b/plugins/recent-doc/tsconfig.json new file mode 100644 index 0000000000..5098169aa9 --- /dev/null +++ b/plugins/recent-doc/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ac2c7f158..d7f6768cab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,6 +98,9 @@ importers: '@tauri-apps/plugin-process': specifier: ^2.3.1 version: link:../../plugins/process + '@tauri-apps/plugin-recent-doc': + specifier: 1.0.0 + version: link:../../plugins/recent-doc '@tauri-apps/plugin-shell': specifier: ^2.3.5 version: link:../../plugins/shell @@ -276,6 +279,12 @@ importers: specifier: ^2.10.1 version: 2.10.1 + plugins/recent-doc: + dependencies: + '@tauri-apps/api': + specifier: ^2.6.0 + version: 2.10.1 + plugins/shell: dependencies: '@tauri-apps/api':