1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! Control display brightness through DDC/CI and the Linux kernel backlight.
//!
//! The plugin is a thin layer over the
//! [`tauri-brightness-core`](https://crates.io/crates/tauri-brightness-core)
//! crate: it exposes the same operations as commands, adds the permission
//! definitions Tauri requires, and ships JavaScript bindings.
//!
//! # Setup
//!
//! ```rust,no_run
//! # fn main() {
//! tauri::Builder::default().plugin(tauri_plugin_brightness::init());
//! # }
//! ```
//!
//! The plugin can also be used directly from Rust, through the
//! [`BrightnessExt`] extension trait:
//!
//! ```rust,no_run
//! use tauri::Manager;
//! use tauri_plugin_brightness::BrightnessExt;
//!
//! # fn inspect(app: &tauri::AppHandle) {
//! let monitors = app.brightness().list_monitors();
//! println!("{} display(s) detected", monitors.len());
//! # }
//! ```
//!
//! # Permissions
//!
//! The commands are not reachable from the webview until they are allowed by a
//! capability. `default.toml` allows all of them, so the common case only needs
//! the plugin to be registered:
//!
//! ```json
//! {
//! "permissions": ["brightness:default"]
//! }
//! ```
//!
//! Grant `brightness:allow-set-brightness` alone when an application should be
//! able to change brightness but not read it.
//!
//! # Linux permissions
//!
//! DDC/CI needs the `i2c-dev` kernel module and usually membership of the `i2c`
//! group. Internal panels need neither. When no display is detected, the
//! `diagnose` command reports exactly which piece is missing.
// The two implementations expose the same operations but are only ever
// compiled for their own platform family, which is why `cfg` is used here and
// not inside a single module.
use desktop as platform;
use mobile as platform;
/// Data types shared with the JavaScript bindings.
pub use ;
pub use ;
use Brightness;
use ;
/// Extends a Tauri manager with access to the brightness API.
///
/// The trait is implemented for every [`Manager`], so it is available on
/// [`AppHandle`](tauri::AppHandle), [`App`](tauri::App) and
/// [`Window`](tauri::Window).
///
/// # Example
///
/// ```rust,no_run
/// use tauri::Manager;
/// use tauri_plugin_brightness::BrightnessExt;
///
/// # fn run(app: tauri::AppHandle) {
/// let monitors = app.brightness().list_monitors();
/// # let _ = monitors;
/// # }
/// ```
/// Initializes the plugin.
///
/// Registers the commands, manages the brightness state, and loads the global
/// API script so the bindings are reachable from `window.__TAURI__.brightness`
/// in applications built with `withGlobalTauri`.