1
1
use std:: {
2
2
self , collections:: VecDeque , fmt:: { self , Debug , Formatter } ,
3
- hint:: unreachable_unchecked, mem, sync:: { Mutex , MutexGuard } ,
3
+ hint:: unreachable_unchecked, mem, sync:: { Mutex , MutexGuard } , time :: Instant ,
4
4
} ;
5
5
6
6
use cocoa:: { appkit:: NSApp , base:: nil} ;
70
70
struct Handler {
71
71
control_flow : Mutex < ControlFlow > ,
72
72
control_flow_prev : Mutex < ControlFlow > ,
73
+ start_time : Mutex < Option < Instant > > ,
73
74
callback : Mutex < Option < Box < dyn EventHandler > > > ,
74
75
pending_events : Mutex < VecDeque < Event < Never > > > ,
75
76
waker : Mutex < EventLoopWaker > ,
@@ -99,6 +100,14 @@ impl Handler {
99
100
( old, new)
100
101
}
101
102
103
+ fn get_start_time ( & self ) -> Option < Instant > {
104
+ * self . start_time . lock ( ) . unwrap ( )
105
+ }
106
+
107
+ fn update_start_time ( & self ) {
108
+ * self . start_time . lock ( ) . unwrap ( ) = Some ( Instant :: now ( ) ) ;
109
+ }
110
+
102
111
fn take_events ( & self ) -> VecDeque < Event < Never > > {
103
112
mem:: replace ( & mut * self . events ( ) , Default :: default ( ) )
104
113
}
@@ -138,9 +147,10 @@ impl AppState {
138
147
}
139
148
140
149
pub fn wakeup ( ) {
150
+ let start = HANDLER . get_start_time ( ) . unwrap ( ) ;
141
151
let cause = match HANDLER . get_control_flow_and_update_prev ( ) {
142
152
ControlFlow :: Poll => StartCause :: Poll ,
143
- /* ControlFlow::Wait => StartCause::WaitCancelled {
153
+ ControlFlow :: Wait => StartCause :: WaitCancelled {
144
154
start,
145
155
requested_resume : None ,
146
156
} ,
@@ -156,9 +166,8 @@ impl AppState {
156
166
requested_resume : Some ( requested_resume) ,
157
167
}
158
168
}
159
- },*/
169
+ } ,
160
170
ControlFlow :: Exit => StartCause :: Poll , //panic!("unexpected `ControlFlow::Exit`"),
161
- _ => unimplemented ! ( ) ,
162
171
} ;
163
172
HANDLER . handle_nonuser_event ( Event :: NewEvents ( cause) ) ;
164
173
}
@@ -176,6 +185,7 @@ impl AppState {
176
185
for event in HANDLER . take_events ( ) {
177
186
HANDLER . handle_nonuser_event ( event) ;
178
187
}
188
+ HANDLER . update_start_time ( ) ;
179
189
match HANDLER . get_old_and_new_control_flow ( ) {
180
190
( ControlFlow :: Poll , ControlFlow :: Poll ) => ( ) ,
181
191
( ControlFlow :: Wait , ControlFlow :: Wait ) => ( ) ,
0 commit comments