44// Prevents additional console window on Windows in release, DO NOT REMOVE!!
55#![ cfg_attr( not( debug_assertions) , windows_subsystem = "windows" ) ]
66
7- use icrate:: AppKit :: NSWindow ;
8- use icrate:: objc2:: rc:: Id ;
97use tauri:: { AppHandle , CustomMenuItem , Manager , RunEvent , SystemTray , SystemTrayEvent , SystemTrayMenu , SystemTrayMenuItem , SystemTraySubmenu , WindowBuilder , WindowUrl } ;
108use libResourceManager:: { chec_for_local, delete_local_resource, get_full_database, LocalSaveCheck , WallpaperVideoEntry } ;
119use libVisualPanic:: ErrorHandlingOption ;
@@ -36,9 +34,8 @@ fn get_full_database_command(app_handle: AppHandle) -> Vec<WallpaperVideoEntry>{
3634 . add_submenu ( favorite_submenu)
3735 . add_submenu ( all_submenu)
3836 . add_native_item ( SystemTrayMenuItem :: Separator )
39- . add_item ( CustomMenuItem :: new ( "close_backgrounds" , "Remove all dynamic wallpapers" ) ) ;
40- // Currently produces a segfault.
41- //.add_item(CustomMenuItem::new("close_background_active_space", "Remove dynamic wallpapers on active space"))
37+ . add_item ( CustomMenuItem :: new ( "close_backgrounds" , "Remove all dynamic wallpapers" ) )
38+ . add_item ( CustomMenuItem :: new ( "close_background_active_space" , "Remove dynamic wallpapers on active space" ) ) ;
4239
4340 app_handle. tray_handle ( ) . set_menu ( tray_menu) . unwrap ( ) ;
4441
@@ -57,21 +54,31 @@ fn check_if_local_exists(identifier: String) -> LocalSaveCheck {
5754
5855#[ tauri:: command]
5956fn apply_to_screen ( identifier : String ) {
60- let window = libDynamicWallpapaper:: apply_to_screen ( identifier) ;
61- unsafe { WINDOW_VEC . push ( window ) ; } ;
57+ let window_identifier = libDynamicWallpapaper:: apply_to_screen ( identifier) ;
58+ unsafe { WINDOW_VEC . push ( window_identifier ) ; } ;
6259}
6360
6461#[ tauri:: command]
6562fn remove_all ( ) {
6663 unsafe {
67- WINDOW_VEC . retain ( |window | {
68- libDynamicWallpapaper:: close_window ( window ) ;
69- return true ;
64+ WINDOW_VEC . retain ( |window_identfier | {
65+ libDynamicWallpapaper:: close_window ( window_identfier . to_string ( ) ) ;
66+ return false ;
7067 } ) ;
7168 }
7269}
7370
74- static mut WINDOW_VEC : Vec < Id < NSWindow > > = vec ! [ ] ;
71+ #[ tauri:: command]
72+ fn remove_current_space ( ) {
73+ unsafe {
74+ WINDOW_VEC . retain ( |window_identfier| {
75+ let remove_this = libDynamicWallpapaper:: close_window_on_screen ( window_identfier. to_string ( ) ) ;
76+ return remove_this;
77+ } ) ;
78+ }
79+ }
80+
81+ static mut WINDOW_VEC : Vec < String > = vec ! [ ] ;
7582
7683fn main ( ) {
7784
@@ -87,15 +94,14 @@ fn main() {
8794 . add_submenu ( favorite_submenu)
8895 . add_submenu ( all_submenu)
8996 . add_native_item ( SystemTrayMenuItem :: Separator )
90- . add_item ( CustomMenuItem :: new ( "close_backgrounds" , "Remove all dynamic wallpapers" ) ) ;
91- // Currently produces a segfault.
92- //.add_item(CustomMenuItem::new("close_background_active_space", "Remove dynamic wallpapers on active space"));
97+ . add_item ( CustomMenuItem :: new ( "close_backgrounds" , "Remove all dynamic wallpapers" ) )
98+ . add_item ( CustomMenuItem :: new ( "close_background_active_space" , "Remove dynamic wallpapers on active space" ) ) ;
9399
94100 let tray = SystemTray :: new ( ) . with_menu ( tray_menu) . with_tooltip ( "WavyBackgrounds" ) ;
95101
96102 tauri:: Builder :: default ( )
97103 . system_tray ( tray)
98- . invoke_handler ( tauri:: generate_handler![ get_full_database_command, download_file, delete_local, check_if_local_exists, apply_to_screen, remove_all] )
104+ . invoke_handler ( tauri:: generate_handler![ get_full_database_command, download_file, delete_local, check_if_local_exists, apply_to_screen, remove_all, remove_current_space ] )
99105 . setup ( |_app| {
100106 Ok ( ( ) )
101107 } )
@@ -117,23 +123,20 @@ fn main() {
117123 }
118124 else if id. as_str ( ) == "close_backgrounds" {
119125 unsafe {
120- unsafe {
121- WINDOW_VEC . retain ( |window| {
122- libDynamicWallpapaper:: close_window ( window) ;
123- return true ;
124- } ) ;
125- }
126+ WINDOW_VEC . retain ( |window_identfier| {
127+ libDynamicWallpapaper:: close_window ( window_identfier. to_string ( ) ) ;
128+ return false ;
129+ } ) ;
126130 }
127131 }
128- /* Currently produces a segfault.
129132 else if id. as_str ( ) == "close_background_active_space" {
130133 unsafe {
131- WINDOW_VEC.retain(|window| {
132- return !libDynamicWallpapaper::close_window_on_screen(window.clone());
134+ WINDOW_VEC . retain ( |window_identfier| {
135+ let remove_this = libDynamicWallpapaper:: close_window_on_screen ( window_identfier. to_string ( ) ) ;
136+ return remove_this;
133137 } ) ;
134138 }
135139 }
136- */
137140 else {
138141 apply_to_screen ( id) ;
139142 }
0 commit comments