@@ -5,6 +5,7 @@ use crate::plugins::fav::{load_favs, FavEntry, FAV_FILE};
55use crate :: plugins:: note:: { load_notes, Note } ;
66use crate :: plugins:: snippets:: { load_snippets, SnippetEntry , SNIPPETS_FILE } ;
77use crate :: plugins:: todo:: { load_todos, TodoEntry , TODO_FILE } ;
8+ use crate :: { launcher, launcher:: RecycleBinInfo } ;
89use std:: sync:: { Arc , Mutex } ;
910use std:: time:: { Duration , Instant } ;
1011use sysinfo:: { Disks , Networks , System } ;
@@ -20,6 +21,21 @@ pub struct SystemStatusSnapshot {
2021 pub brightness_percent : Option < u8 > ,
2122}
2223
24+ #[ derive( Clone , Debug , Default ) ]
25+ pub struct RecycleBinSnapshot {
26+ pub size_bytes : u64 ,
27+ pub items : u64 ,
28+ }
29+
30+ impl From < RecycleBinInfo > for RecycleBinSnapshot {
31+ fn from ( info : RecycleBinInfo ) -> Self {
32+ Self {
33+ size_bytes : info. size_bytes ,
34+ items : info. items ,
35+ }
36+ }
37+ }
38+
2339#[ derive( Clone ) ]
2440pub struct DashboardDataSnapshot {
2541 pub clipboard_history : Arc < Vec < String > > ,
@@ -30,6 +46,7 @@ pub struct DashboardDataSnapshot {
3046 pub favorites : Arc < Vec < FavEntry > > ,
3147 pub process_error : Option < String > ,
3248 pub system_status : Option < SystemStatusSnapshot > ,
49+ pub recycle_bin : Option < RecycleBinSnapshot > ,
3350}
3451
3552impl Default for DashboardDataSnapshot {
@@ -43,6 +60,7 @@ impl Default for DashboardDataSnapshot {
4360 favorites : Arc :: new ( Vec :: new ( ) ) ,
4461 process_error : None ,
4562 system_status : None ,
63+ recycle_bin : None ,
4664 }
4765 }
4866}
@@ -58,6 +76,7 @@ impl DashboardDataSnapshot {
5876 favorites : Arc :: clone ( & self . favorites ) ,
5977 process_error : self . process_error . clone ( ) ,
6078 system_status : self . system_status . clone ( ) ,
79+ recycle_bin : self . recycle_bin . clone ( ) ,
6180 }
6281 }
6382
@@ -71,6 +90,7 @@ impl DashboardDataSnapshot {
7190 favorites : Arc :: clone ( & self . favorites ) ,
7291 process_error : self . process_error . clone ( ) ,
7392 system_status : self . system_status . clone ( ) ,
93+ recycle_bin : self . recycle_bin . clone ( ) ,
7494 }
7595 }
7696
@@ -84,6 +104,7 @@ impl DashboardDataSnapshot {
84104 favorites : Arc :: clone ( & self . favorites ) ,
85105 process_error : self . process_error . clone ( ) ,
86106 system_status : self . system_status . clone ( ) ,
107+ recycle_bin : self . recycle_bin . clone ( ) ,
87108 }
88109 }
89110
@@ -97,6 +118,7 @@ impl DashboardDataSnapshot {
97118 favorites : Arc :: clone ( & self . favorites ) ,
98119 process_error : self . process_error . clone ( ) ,
99120 system_status : self . system_status . clone ( ) ,
121+ recycle_bin : self . recycle_bin . clone ( ) ,
100122 }
101123 }
102124
@@ -110,6 +132,7 @@ impl DashboardDataSnapshot {
110132 favorites : Arc :: new ( favorites) ,
111133 process_error : self . process_error . clone ( ) ,
112134 system_status : self . system_status . clone ( ) ,
135+ recycle_bin : self . recycle_bin . clone ( ) ,
113136 }
114137 }
115138
@@ -123,6 +146,7 @@ impl DashboardDataSnapshot {
123146 favorites : Arc :: clone ( & self . favorites ) ,
124147 process_error,
125148 system_status : self . system_status . clone ( ) ,
149+ recycle_bin : self . recycle_bin . clone ( ) ,
126150 }
127151 }
128152
@@ -136,6 +160,21 @@ impl DashboardDataSnapshot {
136160 favorites : Arc :: clone ( & self . favorites ) ,
137161 process_error : self . process_error . clone ( ) ,
138162 system_status,
163+ recycle_bin : self . recycle_bin . clone ( ) ,
164+ }
165+ }
166+
167+ fn with_recycle_bin ( & self , recycle_bin : Option < RecycleBinSnapshot > ) -> Self {
168+ Self {
169+ clipboard_history : Arc :: clone ( & self . clipboard_history ) ,
170+ snippets : Arc :: clone ( & self . snippets ) ,
171+ notes : Arc :: clone ( & self . notes ) ,
172+ todos : Arc :: clone ( & self . todos ) ,
173+ processes : Arc :: clone ( & self . processes ) ,
174+ favorites : Arc :: clone ( & self . favorites ) ,
175+ process_error : self . process_error . clone ( ) ,
176+ system_status : self . system_status . clone ( ) ,
177+ recycle_bin,
139178 }
140179 }
141180}
@@ -144,6 +183,7 @@ struct DashboardDataState {
144183 snapshot : Arc < DashboardDataSnapshot > ,
145184 last_process_refresh : Instant ,
146185 last_system_refresh : Instant ,
186+ last_recycle_refresh : Instant ,
147187 last_network_totals : ( u64 , u64 ) ,
148188 last_network_time : Instant ,
149189}
@@ -159,6 +199,7 @@ impl DashboardDataCache {
159199 snapshot : Arc :: new ( DashboardDataSnapshot :: default ( ) ) ,
160200 last_process_refresh : Instant :: now ( ) - Duration :: from_secs ( 60 ) ,
161201 last_system_refresh : Instant :: now ( ) - Duration :: from_secs ( 60 ) ,
202+ last_recycle_refresh : Instant :: now ( ) - Duration :: from_secs ( 60 ) ,
162203 last_network_totals : ( 0 , 0 ) ,
163204 last_network_time : Instant :: now ( ) - Duration :: from_secs ( 60 ) ,
164205 } ) ,
@@ -180,6 +221,7 @@ impl DashboardDataCache {
180221 self . refresh_favorites ( ) ;
181222 self . refresh_processes ( plugins) ;
182223 self . refresh_system_status ( ) ;
224+ self . refresh_recycle_bin ( ) ;
183225 }
184226
185227 pub fn refresh_clipboard ( & self ) {
@@ -314,6 +356,25 @@ impl DashboardDataCache {
314356 }
315357 }
316358
359+ pub fn maybe_refresh_recycle_bin ( & self , interval : Duration ) {
360+ let should_refresh = self
361+ . state
362+ . lock ( )
363+ . map ( |state| state. last_recycle_refresh . elapsed ( ) >= interval)
364+ . unwrap_or ( false ) ;
365+ if should_refresh {
366+ self . refresh_recycle_bin ( ) ;
367+ }
368+ }
369+
370+ pub fn refresh_recycle_bin ( & self ) {
371+ let snapshot = launcher:: query_recycle_bin ( ) . map ( |data| RecycleBinSnapshot :: from ( data) ) ;
372+ if let Ok ( mut state) = self . state . lock ( ) {
373+ state. snapshot = Arc :: new ( state. snapshot . with_recycle_bin ( snapshot) ) ;
374+ state. last_recycle_refresh = Instant :: now ( ) ;
375+ }
376+ }
377+
317378 fn load_processes ( plugins : & PluginManager ) -> ( Vec < Action > , Option < String > ) {
318379 let plugin = plugins. iter ( ) . find ( |p| p. name ( ) == "processes" ) ;
319380 if let Some ( plugin) = plugin {
@@ -360,12 +421,12 @@ fn get_system_volume() -> Option<u8> {
360421
361422#[ cfg( target_os = "windows" ) ]
362423fn get_main_display_brightness ( ) -> Option < u8 > {
363- use windows:: Win32 :: Foundation :: { BOOL , LPARAM , RECT } ;
364- use windows:: Win32 :: Graphics :: Gdi :: { EnumDisplayMonitors , HDC , HMONITOR } ;
365424 use windows:: Win32 :: Devices :: Display :: {
366425 DestroyPhysicalMonitors , GetMonitorBrightness , GetNumberOfPhysicalMonitorsFromHMONITOR ,
367426 GetPhysicalMonitorsFromHMONITOR , PHYSICAL_MONITOR ,
368427 } ;
428+ use windows:: Win32 :: Foundation :: { BOOL , LPARAM , RECT } ;
429+ use windows:: Win32 :: Graphics :: Gdi :: { EnumDisplayMonitors , HDC , HMONITOR } ;
369430
370431 unsafe extern "system" fn enum_monitors (
371432 hmonitor : HMONITOR ,
@@ -382,8 +443,7 @@ fn get_main_display_brightness() -> Option<u8> {
382443 let mut min = 0u32 ;
383444 let mut cur = 0u32 ;
384445 let mut max = 0u32 ;
385- if GetMonitorBrightness ( m. hPhysicalMonitor , & mut min, & mut cur, & mut max) != 0
386- {
446+ if GetMonitorBrightness ( m. hPhysicalMonitor , & mut min, & mut cur, & mut max) != 0 {
387447 if max > min {
388448 * percent_ptr = ( ( cur - min) * 100 / ( max - min) ) as u32 ;
389449 } else {
0 commit comments