forked from agentic-review-benchmarks/tauri
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.rs
More file actions
148 lines (130 loc) · 3.6 KB
/
plugin.rs
File metadata and controls
148 lines (130 loc) · 3.6 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tauri_utils::{config::BundleType, Theme};
use crate::{
command,
plugin::{Builder, TauriPlugin},
AppHandle, Manager, ResourceId, Runtime, Webview,
};
#[command(root = "crate")]
pub fn version<R: Runtime>(app: AppHandle<R>) -> String {
app.package_info().version.to_string()
}
#[command(root = "crate")]
pub fn name<R: Runtime>(app: AppHandle<R>) -> String {
app.package_info().name.clone()
}
#[command(root = "crate")]
pub fn tauri_version() -> &'static str {
crate::VERSION
}
#[command(root = "crate")]
pub fn identifier<R: Runtime>(app: AppHandle<R>) -> String {
app.config().identifier.clone()
}
#[command(root = "crate")]
#[allow(unused_variables)]
pub fn app_show<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
#[cfg(target_os = "macos")]
app.show()?;
Ok(())
}
#[command(root = "crate")]
#[allow(unused_variables)]
pub fn app_hide<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
#[cfg(target_os = "macos")]
app.hide()?;
Ok(())
}
#[command(root = "crate")]
#[allow(unused_variables)]
pub async fn fetch_data_store_identifiers<R: Runtime>(
app: AppHandle<R>,
) -> crate::Result<Vec<[u8; 16]>> {
#[cfg(target_vendor = "apple")]
return app.fetch_data_store_identifiers().await;
#[cfg(not(target_vendor = "apple"))]
return Ok(Vec::new());
}
#[command(root = "crate")]
#[allow(unused_variables)]
pub async fn remove_data_store<R: Runtime>(app: AppHandle<R>, uuid: [u8; 16]) -> crate::Result<()> {
#[cfg(target_vendor = "apple")]
app.remove_data_store(uuid).await?;
#[cfg(not(target_vendor = "apple"))]
let _ = uuid;
Ok(())
}
#[command(root = "crate")]
pub fn default_window_icon<R: Runtime>(
webview: Webview<R>,
app: AppHandle<R>,
) -> Option<ResourceId> {
app.default_window_icon().cloned().map(|icon| {
let mut resources_table = webview.resources_table();
resources_table.add(icon.to_owned())
})
}
#[command(root = "crate")]
pub async fn set_app_theme<R: Runtime>(app: AppHandle<R>, theme: Option<Theme>) {
app.set_theme(theme);
}
#[command(root = "crate")]
pub async fn set_dock_visibility<R: Runtime>(
app: AppHandle<R>,
visible: bool,
) -> crate::Result<()> {
#[cfg(target_os = "macos")]
{
let mut focused_window = None;
for window in app.manager.windows().into_values() {
if window.is_focused().unwrap_or_default() {
focused_window.replace(window);
break;
}
}
app.set_dock_visibility(visible)?;
// retain focus
if let Some(focused_window) = focused_window {
let _ = focused_window.set_focus();
}
}
#[cfg(not(target_os = "macos"))]
let (_app, _visible) = (app, visible);
Ok(())
}
#[command(root = "crate")]
pub fn bundle_type() -> Option<BundleType> {
tauri_utils::platform::bundle_type()
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("app")
.invoke_handler(crate::generate_handler![
#![plugin(app)]
version,
name,
tauri_version,
identifier,
app_show,
app_hide,
fetch_data_store_identifiers,
remove_data_store,
default_window_icon,
set_app_theme,
set_dock_visibility,
bundle_type,
])
.setup(|_app, _api| {
#[cfg(target_os = "android")]
{
let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
let handle_ref = &handle;
_app.manage(AppPlugin(*handle_ref));
}
Ok(())
})
.build()
}
#[cfg(target_os = "android")]
pub(crate) struct AppPlugin<R: Runtime>(pub crate::plugin::PluginHandle<R>);