tauri_plugin_snap_layout/
desktop.rs1use tauri::{Emitter, Runtime, WebviewWindow};
2
3pub(crate) const WIN11_MIN_BUILD: u32 = 22000;
5
6pub struct Snap<R: Runtime> {
7 app: tauri::AppHandle<R>,
8}
9
10impl<R: Runtime> Snap<R> {
11 pub fn new(app: tauri::AppHandle<R>) -> Self {
12 Self { app }
13 }
14
15 pub fn app_handle(&self) -> &tauri::AppHandle<R> {
16 &self.app
17 }
18
19 pub fn attach(&self, window: &WebviewWindow<R>) -> crate::Result<()> {
20 #[cfg(windows)]
21 {
22 let version = windows_version::OsVersion::current();
23 if version.build >= WIN11_MIN_BUILD {
24 window.emit("tauri-snap://frontend-attach", ())?;
25 }
26 }
27 Ok(())
28 }
29
30 pub fn detach(&self, window: &WebviewWindow<R>) -> crate::Result<()> {
31 #[cfg(windows)]
32 {
33 let version = windows_version::OsVersion::current();
34 if version.build >= WIN11_MIN_BUILD {
35 window.emit("tauri-snap://frontend-detach", ())?;
36 return crate::platform::snap::uninstall(window);
37 }
38 }
39 Ok(())
40 }
41}