11use cidre:: { arc, ns, sc} ;
2- use core_graphics:: { display:: CGDirectDisplayID , window:: CGWindowID } ;
3- use std:: sync:: Arc ;
4- use std:: {
5- collections:: HashMap ,
6- sync:: { OnceLock , RwLock } ,
7- time:: Instant ,
8- } ;
2+ use std:: sync:: { Arc , OnceLock , RwLock } ;
93use tokio:: sync:: { Mutex , Notify } ;
104use tracing:: trace;
115
@@ -62,8 +56,6 @@ pub async fn prewarm_shareable_content() -> Result<(), arc::R<ns::Error>> {
6256
6357pub async fn get_shareable_content ( )
6458-> Result < Option < arc:: R < sc:: ShareableContent > > , arc:: R < ns:: Error > > {
65- let lookup_start = Instant :: now ( ) ;
66-
6759 if let Some ( content) = state ( )
6860 . cache
6961 . read ( )
@@ -82,14 +74,10 @@ pub async fn get_shareable_content()
8274
8375async fn run_warmup ( task : WarmupTask ) {
8476 let result = async {
85- let warm_start = Instant :: now ( ) ;
86-
8777 let content = sc:: ShareableContent :: current ( ) . await ?;
8878 let cache = ShareableContentCache :: new ( content) ;
89- let elapsed_ms = warm_start. elapsed ( ) . as_micros ( ) as f64 / 1000.0 ;
9079
9180 let mut guard = state ( ) . cache . write ( ) . unwrap ( ) ;
92- let replaced = guard. is_some ( ) ;
9381 * guard = Some ( cache) ;
9482
9583 Ok :: < ( ) , arc:: R < ns:: Error > > ( ( ) )
@@ -115,40 +103,14 @@ async fn run_warmup(task: WarmupTask) {
115103struct ShareableContentCache {
116104 #[ allow( dead_code) ]
117105 content : arc:: R < sc:: ShareableContent > ,
118- displays : HashMap < CGDirectDisplayID , arc:: R < sc:: Display > > ,
119- windows : HashMap < CGWindowID , arc:: R < sc:: Window > > ,
120106}
121107
122108unsafe impl Send for ShareableContentCache { }
123109unsafe impl Sync for ShareableContentCache { }
124110
125111impl ShareableContentCache {
126112 fn new ( content : arc:: R < sc:: ShareableContent > ) -> Self {
127- let displays = content
128- . displays ( )
129- . iter ( )
130- . map ( |display| ( display. display_id ( ) . 0 , display. retained ( ) ) )
131- . collect ( ) ;
132-
133- let windows = content
134- . windows ( )
135- . iter ( )
136- . map ( |window| ( window. id ( ) , window. retained ( ) ) )
137- . collect ( ) ;
138-
139- Self {
140- content,
141- displays,
142- windows,
143- }
144- }
145-
146- fn display ( & self , id : CGDirectDisplayID ) -> Option < arc:: R < sc:: Display > > {
147- self . displays . get ( & id) . cloned ( )
148- }
149-
150- fn window ( & self , id : CGWindowID ) -> Option < arc:: R < sc:: Window > > {
151- self . windows . get ( & id) . cloned ( )
113+ Self { content }
152114 }
153115}
154116
0 commit comments