@@ -16,7 +16,17 @@ const platform =
1616 */
1717function findAnkiWindows ( ) : string {
1818 const candidates = [
19- path . join ( os . homedir ( ) , 'scoop' , 'apps' , 'anki' , 'current' , 'programfiles' , '.venv' , 'Scripts' , 'anki.exe' ) ,
19+ path . join (
20+ os . homedir ( ) ,
21+ 'scoop' ,
22+ 'apps' ,
23+ 'anki' ,
24+ 'current' ,
25+ 'programfiles' ,
26+ '.venv' ,
27+ 'Scripts' ,
28+ 'anki.exe' ,
29+ ) ,
2030 path . join ( 'C:' , 'Program Files' , 'Anki' , 'anki.exe' ) ,
2131 ]
2232
@@ -157,42 +167,50 @@ export async function closeAnki(): Promise<void> {
157167 ankiPid = undefined
158168 }
159169
160- await execa ( 'pkill' , [ '-x' , 'anki' ] ) . catch ( ( ) => { } )
170+ await execa ( 'pkill' , [ '-x' , 'anki' ] ) . catch ( ( ) => {
171+ // Ignore
172+ } )
161173 break
162174 }
163175
164176 case 'mac' : {
165- if ( ankiPid !== undefined ) {
177+ if ( ankiPid === undefined ) {
178+ await execa ( 'osascript' , [ '-e' , 'tell application "Anki" to quit' ] ) . catch ( async ( ) => {
179+ await execa ( 'sh' , [
180+ '-c' ,
181+ "launchctl stop $(launchctl list | grep ankiweb | awk '{print $3}')" ,
182+ ] ) . catch ( ( ) => {
183+ // Ignore
184+ } )
185+ } )
186+ } else {
166187 try {
167188 process . kill ( - ankiPid , 'SIGKILL' )
168189 } catch {
169190 // Ignore if process group already exited
170191 }
171192
172193 ankiPid = undefined
173- } else {
174- await execa ( 'osascript' , [ '-e' , 'tell application "Anki" to quit' ] ) . catch (
175- async ( ) => {
176- await execa ( 'sh' , [
177- '-c' ,
178- "launchctl stop $(launchctl list | grep ankiweb | awk '{print $3}')" ,
179- ] ) . catch ( ( ) => { } )
180- } ,
181- )
182194 }
183195
184196 // Fallback for pip-installed Anki in worker processes where ankiPid is lost
185- await execa ( 'pkill' , [ '-9' , '-f' , 'bin/anki' ] ) . catch ( ( ) => { } )
197+ await execa ( 'pkill' , [ '-9' , '-f' , 'bin/anki' ] ) . catch ( ( ) => {
198+ // Ignore
199+ } )
186200 break
187201 }
188202
189203 case 'windows' : {
190204 if ( ankiPid !== undefined ) {
191- await execa ( 'taskkill' , [ '/PID' , String ( ankiPid ) , '/T' , '/F' ] ) . catch ( ( ) => { } )
205+ await execa ( 'taskkill' , [ '/PID' , String ( ankiPid ) , '/T' , '/F' ] ) . catch ( ( ) => {
206+ // Ignore
207+ } )
192208 ankiPid = undefined
193209 }
194210
195- await execa ( 'taskkill' , [ '/IM' , 'anki.exe' , '/T' , '/F' ] ) . catch ( ( ) => { } )
211+ await execa ( 'taskkill' , [ '/IM' , 'anki.exe' , '/T' , '/F' ] ) . catch ( ( ) => {
212+ // Ignore
213+ } )
196214 break
197215 }
198216 }
0 commit comments