| 70 | } |
| 71 | |
| 72 | static void askTerminateOBS(void *) |
| 73 | { |
| 74 | static std::mutex mtx; |
| 75 | static std::mutex waitMutex; |
| 76 | static std::condition_variable cv; |
| 77 | static bool abortTerminate; |
| 78 | static bool stopWaiting; |
| 79 | static std::chrono::high_resolution_clock::time_point |
| 80 | lastShutdownAttempt{}; |
| 81 | |
| 82 | // Don't allow multiple simultaneous instances of the shutdown dialog |
| 83 | std::unique_lock<std::mutex> lock(mtx, std::try_to_lock); |
| 84 | if (!lock.owns_lock()) { |
| 85 | blog(LOG_INFO, |
| 86 | "OBS shutdown dialog already triggered - ignoring additional request"); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Prevent the user from locking himself out of controlling OBS by |
| 91 | // continuously opening the shutdown dialog |
| 92 | auto now = std::chrono::high_resolution_clock::now(); |
| 93 | if (lastShutdownAttempt + 5s > now) { |
| 94 | blog(LOG_INFO, |
| 95 | "OBS shutdown dialog already triggered recently - ignoring request"); |
| 96 | return; |
| 97 | } |
| 98 | lastShutdownAttempt = now; |
| 99 | |
| 100 | abortTerminate = false; |
| 101 | stopWaiting = false; |
| 102 | |
| 103 | // Give the user a 10s grace period during which the shutdown can be aborted |
| 104 | std::thread thread([]() { |
| 105 | std::unique_lock<std::mutex> lock(waitMutex); |
| 106 | if (cv.wait_for(lock, 10s, [] { return stopWaiting; })) { |
| 107 | if (abortTerminate) { |
| 108 | blog(LOG_INFO, "OBS shutdown was aborted"); |
| 109 | } else { |
| 110 | closeOBSWindow(nullptr); |
| 111 | } |
| 112 | } else { |
| 113 | closeOBSWindow(nullptr); |
| 114 | } |
| 115 | }); |
| 116 | thread.detach(); |
| 117 | |
| 118 | // Ask the user how to proceed |
| 119 | abortTerminate = !DisplayMessage( |
| 120 | obs_module_text( |
| 121 | "AdvSceneSwitcher.action.pluginState.terminateConfirm"), |
| 122 | true, false); |
| 123 | stopWaiting = true; |
| 124 | |
| 125 | // This closes OBS immediately if shutdown was confirmed |
| 126 | cv.notify_all(); |
| 127 | |
| 128 | lock.unlock(); |
| 129 | } |
nothing calls this directly
no test coverage detected