MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / askTerminateOBS

Function askTerminateOBS

plugins/base/macro-action-plugin-state.cpp:72–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72static 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}

Callers

nothing calls this directly

Calls 4

nowClass · 0.85
closeOBSWindowFunction · 0.85
obs_module_textFunction · 0.85
DisplayMessageFunction · 0.50

Tested by

no test coverage detected