-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mod.rs
76 lines (67 loc) · 1.91 KB
/
mod.rs
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
use tauri::{
plugin::TauriPlugin, AppHandle, GlobalWindowEvent, Manager, RunEvent, Window, WindowEvent,
};
use tauri_plugin_spotlight::{PluginConfig, WindowConfig};
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial, NSVisualEffectState};
use crate::shortcuts;
pub const MAIN: &str = "main";
pub const SETTINGS: &str = "settings";
pub mod main_window;
pub mod settings;
#[allow(clippy::collapsible_if)]
pub fn handler(event: GlobalWindowEvent) {
match event.event() {
WindowEvent::Focused(true) => {
if event.window().label() == MAIN {
main_window::on_open(event.window().clone());
}
},
WindowEvent::Focused(is_focused) => {
if !is_focused {
if event.window().label() == MAIN {
main_window::on_close(event.window())
}
}
},
WindowEvent::CloseRequested { api, .. } => {
if event.window().label() == MAIN {
api.prevent_close();
main_window::hide(event.window()).unwrap();
}
if event.window().label() == SETTINGS {
api.prevent_close();
event.window().hide().unwrap();
}
},
_ => {},
}
}
pub fn prevent_exit(app: &AppHandle, event: RunEvent) {
if let tauri::RunEvent::ExitRequested { api, .. } = event {
api.prevent_exit();
main_window::hide(&app.get_window(MAIN).unwrap()).unwrap();
}
}
pub fn spotlight() -> TauriPlugin<tauri::Wry, Option<PluginConfig>> {
tauri_plugin_spotlight::init(Some(tauri_plugin_spotlight::PluginConfig {
windows: Some(vec![WindowConfig {
label: String::from(MAIN),
macos_window_level: Some(20),
shortcut: String::from(shortcuts::DEFAULT_SHORTCUT),
}]),
global_close_shortcut: None,
}))
}
pub trait TransparentWindow {
fn make_transparent(&self) -> Result<(), window_vibrancy::Error>;
}
impl TransparentWindow for Window {
fn make_transparent(&self) -> Result<(), window_vibrancy::Error> {
apply_vibrancy(
self,
NSVisualEffectMaterial::HudWindow,
Some(NSVisualEffectState::Active),
Some(10.0),
)
}
}