@@ -11,8 +11,9 @@ plugin: barcode-scanner
1111import PluginLinks from ' @components/PluginLinks.astro' ;
1212import Compatibility from ' @components/plugins/Compatibility.astro' ;
1313
14- import { Tabs , TabItem } from ' @astrojs/starlight/components' ;
14+ import { Tabs , TabItem , Steps } from ' @astrojs/starlight/components' ;
1515import CommandTabs from ' @components/CommandTabs.astro' ;
16+ import PluginPermissions from ' @components/PluginPermissions.astro' ;
1617
1718<PluginLinks plugin = { frontmatter .plugin } />
1819
@@ -24,12 +25,10 @@ import CommandTabs from '@components/CommandTabs.astro';
2425
2526## 设置
2627
27- _ 这个插件要求 Rust 版本至少是 ** 1.64** _
28-
29- 请安装条形码扫描器插件。
28+ 从安装条形码扫描器插件开始。
3029
3130<Tabs >
32- <TabItem label = " 自动" >
31+ <TabItem label = " 自动" >
3332
3433使用项目的包管理器来添加依赖。
3534
@@ -39,44 +38,75 @@ _这个插件要求 Rust 版本至少是 **1.64**_
3938 npm = " npm run tauri add barcode-scanner"
4039 yarn = " yarn run tauri add barcode-scanner"
4140 pnpm = " pnpm tauri add barcode-scanner"
41+ deno = " deno task tauri add barcode-scanner"
4242 bun = " bun tauri add barcode-scanner"
4343 cargo = " cargo tauri add barcode-scanner"
4444/>
4545
46- </TabItem >
47- <TabItem label = " 手动" >
46+ </TabItem >
47+ <TabItem label = " 手动" >
48+ <Steps >
49+ 1 . 在 ` src-tauri ` 文件夹中运行以下命令,将插件添加到 ` Cargo.toml ` 中的项目依赖项中。
50+
51+ ``` sh frame=none
52+ cargo add tauri-plugin-barcode-scanner --target ' cfg(any(target_os = "android", target_os = "ios"))'
53+ ```
54+
55+ 2 . 修改 ` lib.rs ` 来初始化插件。
56+
57+ ``` rust title="src-tauri/src/lib.rs" ins={5-6}
58+ #[cfg_attr(mobile, tauri:: mobile_entry_point)]
59+ pub fn run () {
60+ tauri :: Builder :: default ()
61+ . setup (| app | {
62+ #[cfg(mobile)]
63+ app . handle (). plugin (tauri_plugin_barcode_scanner :: init ());
64+ Ok (())
65+ })
66+ . run (tauri :: generate_context! ())
67+ . expect (" error while running tauri application" );
68+ }
69+ ```
70+
71+ 3 . 使用你喜欢的 JavaScript 包管理器安装 JavaScript Guest 绑定。
72+
73+ <CommandTabs
74+ npm = " npm install @tauri-apps/plugin-barcode-scanner"
75+ yarn = " yarn add @tauri-apps/plugin-barcode-scanner"
76+ pnpm = " pnpm add @tauri-apps/plugin-barcode-scanner"
77+ deno = " deno add npm:@tauri-apps/plugin-barcode-scanner"
78+ bun = " bun add @tauri-apps/plugin-barcode-scanner"
79+ />
80+ </Steps >
81+ </TabItem >
4882
49- 1 . 运行 ` cargo add tauri-plugin-barcode-scanner ` 以将插件添加到 ` Cargo.toml ` 的项目依赖中。
83+ </ Tabs >
5084
51- 2 . 修改 ` lib.rs ` 来初始化插件。
85+ ## 配置
5286
53- ``` rust title="lib.rs" ins={4}
54- #[cfg_attr(mobile, tauri:: mobile_entry_point)]
55- fn run () {
56- tauri :: Builder :: default ()
57- . plugin (tauri_plugin_barcode_scanner :: init ())
58- . run (tauri :: generate_context! ())
59- . expect (" error while running tauri application" );
60- }
61- ```
87+ 在 iOS 系统中,条形码扫描插件需要 ` NSCameraUsageDescription ` 信息属性列表值,该值应说明您的应用为何需要使用相机。
6288
63- 3 . 使用你喜欢的 JavaScript 包管理器安装 JavaScript Guest 绑定。
89+ 在 ` src-tauri/Info.ios.plist ` 文件中,添加以下代码片段:
6490
65- <CommandTabs
66- npm = " npm install @tauri-apps/plugin-barcode-scanner"
67- yarn = " yarn add @tauri-apps/plugin-barcode-scanner"
68- pnpm = " pnpm add @tauri-apps/plugin-barcode-scanner"
69- bun = " bun add @tauri-apps/plugin-barcode-scanner"
70- />
71- </TabItem >
72- </Tabs >
91+ ``` xml title=src-tauri/Info.ios.plist
92+ <?xml version =" 1.0" encoding =" UTF-8" ?>
93+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
94+ <plist version =" 1.0" >
95+ <dict >
96+ <key >NSCameraUsageDescription</key >
97+ <string >Read QR codes</string >
98+ </dict >
99+ </plist >
100+ ```
73101
74102## 用法
75103
76104条形码扫描器插件在 JavaScript 中可用。
77105
78106``` javascript
79107import { scan , Format } from ' @tauri-apps/plugin-barcode-scanner' ;
108+ // 当设置 `"withGlobalTauri": true` 时, 你可以使用
109+ // const { scan, Format } = window.__TAURI__.barcodeScanner;
80110
81111// `windowed: true` 实际上将 webview 设置为透明的
82112// 而不是为相机打开一个单独的视图
@@ -86,32 +116,18 @@ scan({ windowed: true, formats: [Format.QRCode] });
86116
87117## 权限
88118
89- 默认情况下,所有插件命令都被阻止,无法访问。
90- 你必须在你的 ` capabilities ` 配置中定义一个权限列表。
119+ 默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 ` capabilities ` 文件夹中的配置来启用它们。
91120
92- 更多信息请参见 [ 访问控制列表 ] ( /zh-cn/reference/acl/ ) 。
121+ 参见 [ 能力概览 ] ( /zh-cn/security/capabilities/ ) 以获取更多信息,以及插件的 [ 分步导览 ] ( /zh-cn/learn/security/using-plugin-permissions/ ) 来调整插件权限 。
93122
94123``` json title="src-tauri/capabilities/mobile.json"
95124{
96- "$schema" : " ./schemas/mobile-schema.json" ,
125+ "$schema" : " ../gen /schemas/mobile-schema.json" ,
97126 "identifier" : " mobile-capability" ,
98127 "windows" : [" main" ],
99128 "platforms" : [" iOS" , " android" ],
100129 "permissions" : [" barcode-scanner:allow-scan" , " barcode-scanner:allow-cancel" ]
101130}
102131```
103132
104- | 权限 | 描述 |
105- | ------------------------------------------- | ------------------------------------------------------------- |
106- | ` barcode-scanner:allow-cancel ` | 在没有预先配置作用域的情况下,启用 cancel 命令。 |
107- | ` barcode-scanner:deny-cancel ` | 拒绝没有任何预先配置的作用域的 cancel 命令。 |
108- | ` barcode-scanner:allow-check-permissions ` | 在没有预先配置作用域的情况下,启用 check_permissions 命令。 |
109- | ` barcode-scanner:deny-check-permissions ` | 拒绝没有任何预先配置的作用域的 check_permissions 命令。 |
110- | ` barcode-scanner:allow-open-app-settings ` | 在没有预先配置作用域的情况下,启用 open_app_settings 命令。 |
111- | ` barcode-scanner:deny-open-app-settings ` | 拒绝没有任何预先配置的作用域的 open_app_settings 命令。 |
112- | ` barcode-scanner:allow-request-permissions ` | 在没有预先配置作用域的情况下,启用 request_permissions 命令。 |
113- | ` barcode-scanner:deny-request-permissions ` | 拒绝没有任何预先配置的作用域的 request_permissions 命令。 |
114- | ` barcode-scanner:allow-scan ` | 在没有预先配置作用域的情况下,启用 scan 命令。 |
115- | ` barcode-scanner:deny-scan ` | 拒绝没有任何预先配置的作用域的 scan 命令。 |
116- | ` barcode-scanner:allow-vibrate ` | 在没有预先配置作用域的情况下,启用 vibrate 命令。 |
117- | ` barcode-scanner:deny-vibrate ` | 拒绝没有任何预先配置的作用域的 vibrate 命令。 |
133+ <PluginPermissions plugin = { frontmatter .plugin } />
0 commit comments