@@ -32,11 +32,13 @@ function makeHarness(options?: {
3232 getMode ?: ( ) => Promise < QuitConfirmationMode > ;
3333} ) {
3434 const notifications : Array < QuitShortcutHintEvent > = [ ] ;
35+ const concealWindow = vi . fn ( ) ;
3536 const quit = vi . fn ( ) ;
3637 const handler = makeQuitShortcutHandler ( {
3738 platform : options ?. platform ?? "darwin" ,
3839 getMode : options ?. getMode ?? ( ( ) => Promise . resolve ( options ?. mode ?? "hold" ) ) ,
3940 notify : ( event ) => notifications . push ( event ) ,
41+ concealWindow,
4042 quit,
4143 } ) ;
4244 const preventDefault = vi . fn ( ) ;
@@ -57,7 +59,7 @@ function makeHarness(options?: {
5759 await send ( makeInput ( { isAutoRepeat : true , ...repeatOverrides } ) ) ;
5860 }
5961 } ;
60- return { notifications, quit, preventDefault, send, holdFor } ;
62+ return { notifications, concealWindow , quit, preventDefault, send, holdFor } ;
6163}
6264
6365describe ( "makeQuitShortcutHandler" , ( ) => {
@@ -82,10 +84,11 @@ describe("makeQuitShortcutHandler", () => {
8284 expect ( harness . notifications ) . toEqual ( [ HOLD_DOWN , UP ] ) ;
8385 } ) ;
8486
85- it ( "quits after a completed hold is released " , async ( ) => {
87+ it ( "conceals a completed hold, then quits after release " , async ( ) => {
8688 const harness = makeHarness ( ) ;
8789 await harness . send ( makeInput ( { } ) ) ;
8890 await harness . holdFor ( QUIT_HOLD_DURATION_MS + 200 ) ;
91+ expect ( harness . concealWindow ) . toHaveBeenCalledTimes ( 1 ) ;
8992 expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
9093 await harness . send ( makeInput ( { type : "keyUp" , key : "Meta" , meta : false } ) ) ;
9194 expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
@@ -94,6 +97,81 @@ describe("makeQuitShortcutHandler", () => {
9497 expect ( harness . notifications ) . toEqual ( [ HOLD_DOWN , UP ] ) ;
9598 } ) ;
9699
100+ it ( "keeps a concealed hold committed when another key is pressed" , async ( ) => {
101+ const harness = makeHarness ( ) ;
102+ await harness . send ( makeInput ( { } ) ) ;
103+ await harness . holdFor ( QUIT_HOLD_DURATION_MS ) ;
104+
105+ await harness . send ( makeInput ( { key : "Shift" , shift : true } ) ) ;
106+ expect ( harness . concealWindow ) . toHaveBeenCalledTimes ( 1 ) ;
107+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
108+
109+ vi . advanceTimersByTime ( QUIT_HOLD_RELEASE_GRACE_MS ) ;
110+ expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
111+ } ) ;
112+
113+ it ( "keeps a concealed hold committed through a fresh Cmd+Q press" , async ( ) => {
114+ const harness = makeHarness ( ) ;
115+ await harness . send ( makeInput ( { } ) ) ;
116+ await harness . holdFor ( QUIT_HOLD_DURATION_MS ) ;
117+
118+ await harness . send ( makeInput ( { } ) ) ;
119+ expect ( harness . concealWindow ) . toHaveBeenCalledTimes ( 1 ) ;
120+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
121+
122+ await harness . send ( makeInput ( { type : "keyUp" } ) ) ;
123+ expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
124+ } ) ;
125+
126+ it ( "quits when a completed hold goes quiet without release events" , async ( ) => {
127+ const harness = makeHarness ( ) ;
128+ await harness . send ( makeInput ( { } ) ) ;
129+ await harness . holdFor ( QUIT_HOLD_DURATION_MS + QUIT_HOLD_RELEASE_GRACE_MS * 2 ) ;
130+
131+ // If neither keyUp reaches the handler, continued repeats must keep the
132+ // app alive. Once they stop, the quiet period is the release signal.
133+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
134+ vi . advanceTimersByTime ( QUIT_HOLD_RELEASE_GRACE_MS ) ;
135+
136+ expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
137+ expect ( harness . notifications ) . toEqual ( [ HOLD_DOWN , UP ] ) ;
138+ } ) ;
139+
140+ it ( "waits for slow repeats to stop before quitting" , async ( ) => {
141+ const harness = makeHarness ( ) ;
142+ await harness . send ( makeInput ( { } ) ) ;
143+
144+ vi . advanceTimersByTime ( 300 ) ;
145+ await harness . send ( makeInput ( { isAutoRepeat : true } ) ) ;
146+ vi . advanceTimersByTime ( 900 ) ;
147+ await harness . send ( makeInput ( { isAutoRepeat : true } ) ) ;
148+
149+ vi . advanceTimersByTime ( QUIT_HOLD_RELEASE_GRACE_MS ) ;
150+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
151+
152+ vi . advanceTimersByTime ( 300 ) ;
153+ await harness . send ( makeInput ( { isAutoRepeat : true } ) ) ;
154+ vi . advanceTimersByTime ( 1_799 ) ;
155+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
156+ vi . advanceTimersByTime ( 1 ) ;
157+ expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
158+ } ) ;
159+
160+ it ( "uses the initial repeat delay when the first repeat completes the hold" , async ( ) => {
161+ const harness = makeHarness ( ) ;
162+ await harness . send ( makeInput ( { } ) ) ;
163+
164+ vi . advanceTimersByTime ( QUIT_HOLD_DURATION_MS + 100 ) ;
165+ await harness . send ( makeInput ( { isAutoRepeat : true } ) ) ;
166+
167+ vi . advanceTimersByTime ( QUIT_HOLD_RELEASE_GRACE_MS ) ;
168+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
169+ vi . advanceTimersByTime ( 1_999 ) ;
170+ expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
171+ vi . advanceTimersByTime ( 1 ) ;
172+ expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
173+ } ) ;
174+
97175 it ( "waits for Q release when Cmd is released first" , async ( ) => {
98176 const harness = makeHarness ( ) ;
99177 await harness . send ( makeInput ( { } ) ) ;
@@ -115,6 +193,7 @@ describe("makeQuitShortcutHandler", () => {
115193 await harness . send ( makeInput ( { type : "keyUp" } ) ) ;
116194 expect ( harness . notifications ) . toEqual ( [ HOLD_DOWN , UP ] ) ;
117195 vi . advanceTimersByTime ( ( QUIT_HOLD_DURATION_MS + QUIT_HOLD_RELEASE_GRACE_MS ) * 2 ) ;
196+ expect ( harness . concealWindow ) . not . toHaveBeenCalled ( ) ;
118197 expect ( harness . quit ) . not . toHaveBeenCalled ( ) ;
119198 } ) ;
120199
@@ -130,6 +209,7 @@ describe("makeQuitShortcutHandler", () => {
130209 it ( "quits without showing a hint in direct mode" , async ( ) => {
131210 const harness = makeHarness ( { mode : "direct" } ) ;
132211 await harness . send ( makeInput ( { } ) ) ;
212+ expect ( harness . concealWindow ) . not . toHaveBeenCalled ( ) ;
133213 expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
134214 expect ( harness . notifications ) . toEqual ( [ ] ) ;
135215 } ) ;
@@ -223,6 +303,7 @@ describe("makeQuitShortcutHandler", () => {
223303 await harness . send ( makeInput ( { } ) ) ;
224304 vi . advanceTimersByTime ( QUIT_DOUBLE_PRESS_MS - 100 ) ;
225305 await harness . send ( makeInput ( { } ) ) ;
306+ expect ( harness . concealWindow ) . not . toHaveBeenCalled ( ) ;
226307 expect ( harness . quit ) . toHaveBeenCalledTimes ( 1 ) ;
227308 expect ( harness . notifications ) . toEqual ( [ DOUBLE_CLICK_DOWN , UP ] ) ;
228309 } ) ;
0 commit comments