deskulpt/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://github.com/CSCI-SHU-410-SE-Project/Deskulpt/raw/main/packages/deskulpt/public/deskulpt.svg",
4    html_favicon_url = "https://github.com/CSCI-SHU-410-SE-Project/Deskulpt/raw/main/packages/deskulpt/public/deskulpt.svg"
5)]
6
7use deskulpt_core::path::PathExt;
8use deskulpt_core::states::{
9    CanvasImodeStateExt, InitialRenderStateExt, SettingsStateExt, WidgetConfigMapStateExt,
10};
11use deskulpt_core::tray::TrayExt;
12use deskulpt_core::window::WindowExt;
13use tauri::image::Image;
14use tauri::{generate_context, include_image, Builder};
15
16/// Image object for the Deskulpt icon.
17const DESKULPT_ICON: Image = include_image!("./icons/icon.png");
18
19/// Entry point for the Deskulpt backend.
20pub fn run() {
21    Builder::default()
22        .setup(move |app| {
23            app.init_widgets_dir()?;
24            app.init_persist_dir()?;
25
26            app.manage_settings();
27            app.manage_initial_render();
28            app.manage_widget_config_map();
29            app.manage_canvas_imode();
30
31            // Hide the application from the dock on macOS because skipping
32            // taskbar is not applicable for macOS
33            #[cfg(target_os = "macos")]
34            app.set_activation_policy(tauri::ActivationPolicy::Accessory);
35
36            app.create_manager()?;
37            app.create_canvas()?;
38            app.create_tray(DESKULPT_ICON)?;
39
40            Ok(())
41        })
42        .on_window_event(deskulpt_core::window::on_window_event)
43        .plugin(tauri_plugin_clipboard_manager::init())
44        .plugin(tauri_plugin_global_shortcut::Builder::new().build())
45        // Prevent the opener plugin from registering handler for click event
46        // so we can register our own that opens non-_blank anchors in new tab
47        .plugin(
48            tauri_plugin_opener::Builder::new()
49                .open_js_links_on_click(false)
50                .build(),
51        )
52        .plugin(deskulpt_core::init())
53        .run(generate_context!())
54        .expect("Error running the Deskulpt application");
55}