From 762b013a397d1f6a92bf7ae1ae799beb645b8e13 Mon Sep 17 00:00:00 2001 From: xubeiyan Date: Thu, 23 Jan 2025 14:00:38 +0800 Subject: [PATCH 1/6] docs(src/content/docs/zh-cn/plugin/opener.mdx): translate opener.mdx to zh-cn --- src/content/docs/zh-cn/plugin/opener.mdx | 135 +++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/content/docs/zh-cn/plugin/opener.mdx diff --git a/src/content/docs/zh-cn/plugin/opener.mdx b/src/content/docs/zh-cn/plugin/opener.mdx new file mode 100644 index 0000000000..e30dee92c7 --- /dev/null +++ b/src/content/docs/zh-cn/plugin/opener.mdx @@ -0,0 +1,135 @@ +--- +title: 指定打开应用 +description: 在外部应用中打开文件和URL。 +plugin: opener +--- + +import PluginLinks from '@components/PluginLinks.astro'; +import Compatibility from '@components/plugins/Compatibility.astro'; + +import { Tabs, TabItem, Steps } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; +import PluginPermissions from '@components/PluginPermissions.astro'; + + + +此插件允许你使用特定或者默认的应用程序打开文件或者 URL。它还可以在系统文件管理器中“显示”这些文件。 + +## 支持的平台 + + + +## 设置 + +首先安装“指定打开应用”插件。 + + + + 使用项目的包管理器来添加依赖: + { ' ' } + + + + + + 1. 在 `src-tauri` 目录下,运行下面的命令。将此插件添加到项目的 `Cargo.toml` 文件的 `dependecnies` 字段中: + + ```sh frame=none + cargo add tauri-plugin-opener + ``` + + 2. 修改 `lib.rs` 文件,初始化此插件: + + ```rust title="src-tauri/src/lib.rs" ins={4} + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + .plugin(tauri_plugin_opener::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. 使用你喜欢的 JavaScript 包管理器来添加 JavaScript 端的插件绑定: + + + + + + + +## 用法 + +此插件有 JavaScript 和 Rust 两种调用方式。 + + + + +```javascript +import { openPath } from '@tauri-apps/plugin-opener'; +// 当配置为 `"withGlobalTauri": true` 时,你可以使用下面方式引入此插件 +// const { openPath } = window.__TAURI__.opener; + +// 使用默认的应用来打开文件 +await openPath('/path/to/file'); +// 在 Windows 上使用 `vlc` 打开文件 +await openPath('C:/path/to/file', 'vlc'); +``` + + + + +下面代码中的 `app` 变量是 `App` 或者 [`AppHandle`](https://docs.rs/tauri/2.0.0/tauri/struct.AppHandle.html) 实例化后的结果。 + +```rust +use tauri_plugin_opener::OpenerExt; + +// 使用默认的应用来打开文件: +app.opener().open_path("/path/to/file", None::<&str>); +// 在 Windows 上使用 `vlc` 打开文件: +app.opener().open_path("C:/path/to/file", Some("vlc")); +``` + + + + + +## 权限 + +默认情况下,所有插件命令都被阻止,无法访问。你必须修改 `tauri` 端的 `capabilities` 文件夹中的配置来启用它们。 + +参见[能力概览](/zh-cn/security/capabilities/)以获取更多信息,以及[调整权限分步导览](/zh-cn/learn/security/using-plugin-permissions/)来调整插件的权限。 + +```json title="src-tauri/capabilities/default.json" ins={6-15} +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "main-capability", + "description": "Capability for the main window", + "windows": ["main"], + "permissions": [ + { + "identifier": "opener:allow-open-path", + "allow": [ + { + "path": "/path/to/file" + } + ] + } + ] +} +``` + + From e1995040163826cf88139ba161ec2a46fd83d6e7 Mon Sep 17 00:00:00 2001 From: xubeiyan Date: Mon, 10 Feb 2025 09:39:40 +0800 Subject: [PATCH 2/6] Update src/content/docs/zh-cn/plugin/opener.mdx Co-authored-by: Vitor Ayres --- src/content/docs/zh-cn/plugin/opener.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/plugin/opener.mdx b/src/content/docs/zh-cn/plugin/opener.mdx index e30dee92c7..e769681f2d 100644 --- a/src/content/docs/zh-cn/plugin/opener.mdx +++ b/src/content/docs/zh-cn/plugin/opener.mdx @@ -39,7 +39,7 @@ import PluginPermissions from '@components/PluginPermissions.astro'; - 1. 在 `src-tauri` 目录下,运行下面的命令。将此插件添加到项目的 `Cargo.toml` 文件的 `dependecnies` 字段中: + 1. 在 `src-tauri` 目录下,运行下面的命令。将此插件添加到项目的 `Cargo.toml` 文件的 `dependencies` 字段中: ```sh frame=none cargo add tauri-plugin-opener From 4185578f3ffe451be4485c5dda4461d41d282a7a Mon Sep 17 00:00:00 2001 From: xubeiyan Date: Mon, 10 Feb 2025 10:04:24 +0800 Subject: [PATCH 3/6] Update src/content/docs/zh-cn/plugin/opener.mdx Co-authored-by: _zhiqiu --- src/content/docs/zh-cn/plugin/opener.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/plugin/opener.mdx b/src/content/docs/zh-cn/plugin/opener.mdx index e769681f2d..4121d02cbc 100644 --- a/src/content/docs/zh-cn/plugin/opener.mdx +++ b/src/content/docs/zh-cn/plugin/opener.mdx @@ -92,7 +92,7 @@ await openPath('C:/path/to/file', 'vlc'); -下面代码中的 `app` 变量是 `App` 或者 [`AppHandle`](https://docs.rs/tauri/2.0.0/tauri/struct.AppHandle.html) 实例化后的结果。 +下面代码中的 `app` 变量是 `App` 或者 [`AppHandle`](https://docs.rs/tauri/2.0.0/tauri/struct.AppHandle.html) 的实例。 ```rust use tauri_plugin_opener::OpenerExt; From d81d8190ae6759f8cd68f871c4130484805d947a Mon Sep 17 00:00:00 2001 From: xubeiyan Date: Mon, 10 Feb 2025 10:04:47 +0800 Subject: [PATCH 4/6] Update src/content/docs/zh-cn/plugin/opener.mdx Co-authored-by: _zhiqiu --- src/content/docs/zh-cn/plugin/opener.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/plugin/opener.mdx b/src/content/docs/zh-cn/plugin/opener.mdx index 4121d02cbc..a44f1c60f3 100644 --- a/src/content/docs/zh-cn/plugin/opener.mdx +++ b/src/content/docs/zh-cn/plugin/opener.mdx @@ -111,7 +111,7 @@ app.opener().open_path("C:/path/to/file", Some("vlc")); 默认情况下,所有插件命令都被阻止,无法访问。你必须修改 `tauri` 端的 `capabilities` 文件夹中的配置来启用它们。 -参见[能力概览](/zh-cn/security/capabilities/)以获取更多信息,以及[调整权限分步导览](/zh-cn/learn/security/using-plugin-permissions/)来调整插件的权限。 +参见[能力概览](/zh-cn/security/capabilities/)以获取更多信息,以及插件的[分步导览](/zh-cn/learn/security/using-plugin-permissions/)来调整插件权限。 ```json title="src-tauri/capabilities/default.json" ins={6-15} { From b7cb3efcc9aa15f5ee1f97c7f76f211b67d7db7e Mon Sep 17 00:00:00 2001 From: xubeiyan Date: Mon, 10 Feb 2025 10:05:02 +0800 Subject: [PATCH 5/6] Update src/content/docs/zh-cn/plugin/opener.mdx Co-authored-by: _zhiqiu --- src/content/docs/zh-cn/plugin/opener.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/plugin/opener.mdx b/src/content/docs/zh-cn/plugin/opener.mdx index a44f1c60f3..0577a3b167 100644 --- a/src/content/docs/zh-cn/plugin/opener.mdx +++ b/src/content/docs/zh-cn/plugin/opener.mdx @@ -109,7 +109,7 @@ app.opener().open_path("C:/path/to/file", Some("vlc")); ## 权限 -默认情况下,所有插件命令都被阻止,无法访问。你必须修改 `tauri` 端的 `capabilities` 文件夹中的配置来启用它们。 +默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 `capabilities` 文件夹中的配置来启用它们。 参见[能力概览](/zh-cn/security/capabilities/)以获取更多信息,以及插件的[分步导览](/zh-cn/learn/security/using-plugin-permissions/)来调整插件权限。 From c8a7b2aad94f706e3796008969c3e38b17cde144 Mon Sep 17 00:00:00 2001 From: xubeiyan Date: Mon, 10 Feb 2025 10:32:20 +0800 Subject: [PATCH 6/6] Update src/content/docs/zh-cn/plugin/opener.mdx Co-authored-by: _zhiqiu --- src/content/docs/zh-cn/plugin/opener.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/plugin/opener.mdx b/src/content/docs/zh-cn/plugin/opener.mdx index 0577a3b167..afc511a5a2 100644 --- a/src/content/docs/zh-cn/plugin/opener.mdx +++ b/src/content/docs/zh-cn/plugin/opener.mdx @@ -109,7 +109,7 @@ app.opener().open_path("C:/path/to/file", Some("vlc")); ## 权限 -默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 `capabilities` 文件夹中的配置来启用它们。 +默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 `capabilities` 文件夹中的配置来启用它们。 参见[能力概览](/zh-cn/security/capabilities/)以获取更多信息,以及插件的[分步导览](/zh-cn/learn/security/using-plugin-permissions/)来调整插件权限。