|
18 | 18 | ${EndIf} |
19 | 19 | !macroend |
20 | 20 |
|
| 21 | +!define /ifndef ERROR_MORE_DATA 234 |
| 22 | + |
21 | 23 | ; Checks whether app is running or not and prompts to kill it. |
22 | | -!macro CheckIfAppIsRunning executableName productName |
| 24 | +!macro CheckIfAppIsRunning executablePath productName |
23 | 25 | !define UniqueID ${__LINE__} |
24 | 26 |
|
25 | 27 | ; Replace {{product_name}} placeholder in the messages with the passed product name |
|
30 | 32 | nsis_tauri_utils::StrReplace "$(failedToKillApp)" "{{product_name}}" "${productName}" |
31 | 33 | Pop $R3 |
32 | 34 |
|
33 | | - !if "${INSTALLMODE}" == "currentUser" |
34 | | - nsis_tauri_utils::FindProcessCurrentUser "${executableName}" |
35 | | - !else |
36 | | - nsis_tauri_utils::FindProcess "${executableName}" |
37 | | - !endif |
38 | | - Pop $R0 |
39 | | - ${If} $R0 = 0 |
40 | | - IfSilent kill_${UniqueID} 0 |
41 | | - ${IfThen} $PassiveMode != 1 ${|} MessageBox MB_OKCANCEL $R2 IDOK kill_${UniqueID} IDCANCEL cancel_${UniqueID} ${|} |
42 | | - kill_${UniqueID}: |
43 | | - !if "${INSTALLMODE}" == "currentUser" |
44 | | - nsis_tauri_utils::KillProcessCurrentUser "${executableName}" |
45 | | - !else |
46 | | - nsis_tauri_utils::KillProcess "${executableName}" |
47 | | - !endif |
48 | | - Pop $R0 |
49 | | - Sleep 500 |
50 | | - ${If} $R0 = 0 |
51 | | - ${OrIf} $R0 = 2 |
52 | | - Goto app_check_done_${UniqueID} |
53 | | - ${Else} |
54 | | - IfSilent silent_${UniqueID} ui_${UniqueID} |
55 | | - silent_${UniqueID}: |
56 | | - System::Call 'kernel32::AttachConsole(i -1)i.r0' |
57 | | - ${If} $0 != 0 |
58 | | - System::Call 'kernel32::GetStdHandle(i -11)i.r0' |
59 | | - System::call 'kernel32::SetConsoleTextAttribute(i r0, i 0x0004)' ; set red color |
60 | | - FileWrite $0 "$R1$\n" |
61 | | - ${EndIf} |
62 | | - Abort |
63 | | - ui_${UniqueID}: |
64 | | - Abort $R3 |
65 | | - ${EndIf} |
66 | | - cancel_${UniqueID}: |
67 | | - Abort $R1 |
| 35 | + !insertmacro RestartManager_StartSession $R0 |
| 36 | + ${If} $R0 != "" |
| 37 | + !insertmacro RestartManager_RegisterFile $R0 "${executablePath}" |
| 38 | + ${If} $0 = 0 |
| 39 | + System::Call 'RSTRTMGR::RmGetList(p R0, *i .r1, *i .r2, p 0, *i .r3) i .r0' |
| 40 | + ; ERROR_SUCCESS means no running processes, ERROR_MORE_DATA means there're some |
| 41 | + ${If} $0 = ${ERROR_MORE_DATA} |
| 42 | + IfSilent kill_${UniqueID} 0 |
| 43 | + ${IfThen} $PassiveMode != 1 ${|} MessageBox MB_OKCANCEL $R2 IDOK kill_${UniqueID} IDCANCEL cancel_${UniqueID} ${|} |
| 44 | + kill_${UniqueID}: |
| 45 | + ; Call manually here to get the result |
| 46 | + ; !insertmacro RestartManager_Shutdown $R0 |
| 47 | + System::Call 'RSTRTMGR::RmShutdown(p R0, i ${RmForceShutdown}, p 0) i .r0' |
| 48 | + ${If} $0 = 0 |
| 49 | + Goto app_check_done_${UniqueID} |
| 50 | + ${Else} |
| 51 | + IfSilent silent_${UniqueID} ui_${UniqueID} |
| 52 | + silent_${UniqueID}: |
| 53 | + System::Call 'kernel32::AttachConsole(i -1)i.r0' |
| 54 | + ${If} $0 != 0 |
| 55 | + System::Call 'kernel32::GetStdHandle(i -11)i.r0' |
| 56 | + System::call 'kernel32::SetConsoleTextAttribute(i r0, i 0x0004)' ; set red color |
| 57 | + FileWrite $0 "$R1$\n" |
| 58 | + ${EndIf} |
| 59 | + !insertmacro RestartManager_EndSession $R0 |
| 60 | + Abort |
| 61 | + ui_${UniqueID}: |
| 62 | + !insertmacro RestartManager_EndSession $R0 |
| 63 | + Abort $R3 |
| 64 | + ${EndIf} |
| 65 | + cancel_${UniqueID}: |
| 66 | + !insertmacro RestartManager_EndSession $R0 |
| 67 | + Abort $R1 |
| 68 | + app_check_done_${UniqueID}: |
| 69 | + ${EndIf} |
| 70 | + ${EndIf} |
| 71 | + !insertmacro RestartManager_EndSession $R0 |
68 | 72 | ${EndIf} |
69 | | - app_check_done_${UniqueID}: |
70 | | - !undef UniqueID |
| 73 | + |
| 74 | + !undef UniqueID |
71 | 75 | !macroend |
72 | 76 |
|
73 | 77 | ; Sets AppUserModelId on a shortcut |
|
0 commit comments