From 8c19468e3255f4dee3e74733abe17d171df53c1a Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Mon, 8 Dec 2025 17:58:58 +0200 Subject: [PATCH] refactor(UI): remove unused structs and simplify GTK theme handling --- desktop/tauri/src-tauri/src/portapi/types.rs | 11 ---------- desktop/tauri/src-tauri/src/portmaster/mod.rs | 3 --- desktop/tauri/src-tauri/src/window.rs | 2 +- desktop/tauri/src-tauri/src/xdg/mod.rs | 21 ++++++------------- 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/desktop/tauri/src-tauri/src/portapi/types.rs b/desktop/tauri/src-tauri/src/portapi/types.rs index 632f24f4..e72ffee8 100644 --- a/desktop/tauri/src-tauri/src/portapi/types.rs +++ b/desktop/tauri/src-tauri/src/portapi/types.rs @@ -185,15 +185,4 @@ impl std::convert::TryFrom for Message { Response::Done => Ok(Message{id: 0, cmd: "done".to_string(), key: None, payload: None}), } } -} - - -#[derive(serde::Serialize, serde::Deserialize)] -#[serde(rename_all = "UPPERCASE")] -pub struct Record { - pub created: u64, - pub deleted: u64, - pub expires: u64, - pub modified: u64, - pub key: String, } \ No newline at end of file diff --git a/desktop/tauri/src-tauri/src/portmaster/mod.rs b/desktop/tauri/src-tauri/src/portmaster/mod.rs index 9ad81f69..71851744 100644 --- a/desktop/tauri/src-tauri/src/portmaster/mod.rs +++ b/desktop/tauri/src-tauri/src/portmaster/mod.rs @@ -329,9 +329,6 @@ pub trait PortmasterExt { fn portmaster(&self) -> &PortmasterInterface; } -#[derive(serde::Serialize, serde::Deserialize, Debug)] -pub struct Config {} - impl> PortmasterExt for T { fn portmaster(&self) -> &PortmasterInterface { self.state::>().inner() diff --git a/desktop/tauri/src-tauri/src/window.rs b/desktop/tauri/src-tauri/src/window.rs index 63ae2069..cf220368 100644 --- a/desktop/tauri/src-tauri/src/window.rs +++ b/desktop/tauri/src-tauri/src/window.rs @@ -67,7 +67,7 @@ pub fn create_main_window(app: &AppHandle) -> Result { // Issue: https://github.com/safing/portmaster/issues/1909 // Additional info: https://github.com/tauri-apps/tauri/issues/6162#issuecomment-1423304398 let win_clone = win.clone(); - win.listen("tauri://focus", move |event| { + win.listen("tauri://focus", move |_event| { let _ = win_clone.set_resizable(false); let _ = win_clone.set_resizable(true); }); diff --git a/desktop/tauri/src-tauri/src/xdg/mod.rs b/desktop/tauri/src-tauri/src/xdg/mod.rs index 3db67942..df77fb01 100644 --- a/desktop/tauri/src-tauri/src/xdg/mod.rs +++ b/desktop/tauri/src-tauri/src/xdg/mod.rs @@ -3,7 +3,7 @@ use dataurl::DataUrl; use gdk_pixbuf::{Pixbuf, PixbufError}; use gtk_sys::{ gtk_icon_info_free, gtk_icon_info_get_filename, gtk_icon_theme_get_default, - gtk_icon_theme_lookup_icon, GtkIconTheme, + gtk_icon_theme_lookup_icon, }; use log::{debug, error}; use std::collections::HashMap; @@ -20,8 +20,6 @@ use thiserror::Error; use ini::{Ini, ParseOption}; -static mut GTK_DEFAULT_THEME: Option<*mut GtkIconTheme> = None; - lazy_static! { static ref APP_INFO_CACHE: Arc>>> = Arc::new(RwLock::new(HashMap::new())); @@ -352,17 +350,10 @@ fn parse_app_info(props: &ini::Properties) -> AppInfo { } fn get_icon_as_png_dataurl(name: &str, size: i8) -> Result<(String, String)> { - unsafe { - if GTK_DEFAULT_THEME.is_none() { - let theme = gtk_icon_theme_get_default(); - if theme.is_null() { - debug!("You have to initialize GTK!"); - return Err(Error::new(ErrorKind::Other, "You have to initialize GTK!").into()); - } - - let theme = gtk_icon_theme_get_default(); - GTK_DEFAULT_THEME = Some(theme); - } + // gtk_icon_theme_get_default() is lightweight - it returns a borrowed reference to GTK's singleton icon theme + let theme = unsafe { gtk_icon_theme_get_default() }; + if theme.is_null() { + return Err(Error::new(ErrorKind::Other, "GTK not initialized").into()); } let mut icons = Vec::new(); @@ -402,7 +393,7 @@ fn get_icon_as_png_dataurl(name: &str, size: i8) -> Result<(String, String)> { let c_str = CString::new(name).unwrap(); let icon_info = gtk_icon_theme_lookup_icon( - GTK_DEFAULT_THEME.unwrap(), + theme, c_str.as_ptr() as *const c_char, size as c_int, 0,