[desktop] Add support for system theme detection

This commit is contained in:
Vladimir Stoilov
2024-07-24 10:53:58 +03:00
parent 5b03076fac
commit a6e1a37239
6 changed files with 159 additions and 20 deletions

View File

@@ -1,11 +1,15 @@
use log::{debug, error};
use tauri::{
AppHandle, Listener, Manager, Result, Theme, UserAttentionType, WebviewUrl, WebviewWindow,
WebviewWindowBuilder,
image::Image, AppHandle, Listener, Manager, Result, Theme, UserAttentionType, WebviewUrl,
WebviewWindow, WebviewWindowBuilder,
};
use crate::portmaster::PortmasterExt;
const LIGHT_PM_ICON: &'static [u8] =
include_bytes!("../../../../assets/data/icons/pm_light_512.png");
const DARK_PM_ICON: &'static [u8] = include_bytes!("../../../../assets/data/icons/pm_dark_512.png");
/// Either returns the existing "main" window or creates a new one.
///
/// The window is not automatically shown (i.e it starts hidden).
@@ -47,6 +51,11 @@ pub fn create_main_window(app: &AppHandle) -> Result<WebviewWindow> {
// If the window is not yet navigated to the Portmaster UI, do it now.
may_navigate_to_ui(&mut window, false);
let _ = match dark_light::detect() {
dark_light::Mode::Light => window.set_icon(Image::from_bytes(DARK_PM_ICON).unwrap()),
_ => window.set_icon(Image::from_bytes(LIGHT_PM_ICON).unwrap()),
};
#[cfg(debug_assertions)]
if let Ok(_) = std::env::var("TAURI_SHOW_IMMEDIATELY") {
debug!("[tauri] TAURI_SHOW_IMMEDIATELY is set, opening window");