Skip to main content

tauri_plugin_snap_layout/
desktop.rs

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