OBSApp.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "OBSApp.hpp"
  15. #include <components/Multiview.hpp>
  16. #include <dialogs/LogUploadDialog.hpp>
  17. #include <plugin-manager/PluginManager.hpp>
  18. #include <utility/CrashHandler.hpp>
  19. #include <utility/OBSEventFilter.hpp>
  20. #include <utility/OBSProxyStyle.hpp>
  21. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  22. #include <utility/models/branches.hpp>
  23. #endif
  24. #include <widgets/OBSBasic.hpp>
  25. #if !defined(_WIN32) && !defined(__APPLE__)
  26. #include <obs-nix-platform.h>
  27. #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
  28. #include <qpa/qplatformnativeinterface.h>
  29. #endif
  30. #endif
  31. #include <qt-wrappers.hpp>
  32. #include <QCheckBox>
  33. #include <QDesktopServices>
  34. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  35. #include <QFile>
  36. #endif
  37. #include <QSessionManager>
  38. #ifndef _WIN32
  39. #include <QSocketNotifier>
  40. #endif
  41. #include <chrono>
  42. #ifdef _WIN32
  43. #include <sstream>
  44. #define WIN32_LEAN_AND_MEAN
  45. #include <windows.h>
  46. #else
  47. #include <unistd.h>
  48. #include <sys/socket.h>
  49. #endif
  50. #include "moc_OBSApp.cpp"
  51. using namespace std;
  52. string currentLogFile;
  53. string lastLogFile;
  54. string lastCrashLogFile;
  55. extern bool portable_mode;
  56. extern bool safe_mode;
  57. extern bool multi;
  58. extern bool disable_3p_plugins;
  59. extern bool opt_disable_updater;
  60. extern bool opt_disable_missing_files_check;
  61. extern string opt_starting_collection;
  62. extern string opt_starting_profile;
  63. #ifndef _WIN32
  64. int OBSApp::sigintFd[2];
  65. int OBSApp::sigtermFd[2];
  66. #endif
  67. // GPU hint exports for AMD/NVIDIA laptops
  68. #ifdef _MSC_VER
  69. extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 1;
  70. extern "C" __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
  71. #endif
  72. namespace {
  73. typedef struct UncleanLaunchAction {
  74. bool useSafeMode = false;
  75. bool sendCrashReport = false;
  76. } UncleanLaunchAction;
  77. UncleanLaunchAction handleUncleanShutdown(bool enableCrashUpload)
  78. {
  79. UncleanLaunchAction launchAction;
  80. blog(LOG_WARNING, "Crash or unclean shutdown detected");
  81. QMessageBox crashWarning;
  82. crashWarning.setIcon(QMessageBox::Warning);
  83. #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
  84. crashWarning.setOption(QMessageBox::Option::DontUseNativeDialog);
  85. #endif
  86. crashWarning.setWindowTitle(QTStr("CrashHandling.Dialog.Title"));
  87. crashWarning.setText(QTStr("CrashHandling.Labels.Text"));
  88. if (enableCrashUpload) {
  89. crashWarning.setInformativeText(QTStr("CrashHandling.Labels.PrivacyNotice"));
  90. QCheckBox *sendCrashReportCheckbox = new QCheckBox(QTStr("CrashHandling.Checkbox.SendReport"));
  91. crashWarning.setCheckBox(sendCrashReportCheckbox);
  92. }
  93. QPushButton *launchSafeButton =
  94. crashWarning.addButton(QTStr("CrashHandling.Buttons.LaunchSafe"), QMessageBox::AcceptRole);
  95. QPushButton *launchNormalButton =
  96. crashWarning.addButton(QTStr("CrashHandling.Buttons.LaunchNormal"), QMessageBox::RejectRole);
  97. crashWarning.setDefaultButton(launchNormalButton);
  98. crashWarning.exec();
  99. bool useSafeMode = crashWarning.clickedButton() == launchSafeButton;
  100. if (useSafeMode) {
  101. launchAction.useSafeMode = true;
  102. blog(LOG_INFO, "[Safe Mode] Safe mode launch selected, loading third-party plugins is disabled");
  103. } else {
  104. blog(LOG_WARNING, "[Safe Mode] Normal launch selected, loading third-party plugins is enabled");
  105. }
  106. bool sendCrashReport = (enableCrashUpload) ? crashWarning.checkBox()->isChecked() : false;
  107. if (sendCrashReport) {
  108. launchAction.sendCrashReport = true;
  109. blog(LOG_INFO, "User selected to send crash report");
  110. }
  111. return launchAction;
  112. }
  113. QAccessibleInterface *alignmentSelectorFactory(const QString &classname, QObject *object)
  114. {
  115. if (classname == QLatin1String("AlignmentSelector")) {
  116. if (auto *w = qobject_cast<AlignmentSelector *>(object))
  117. return new AccessibleAlignmentSelector(w);
  118. }
  119. return nullptr;
  120. }
  121. } // namespace
  122. QObject *CreateShortcutFilter()
  123. {
  124. return new OBSEventFilter([](QObject *obj, QEvent *event) {
  125. auto mouse_event = [](QMouseEvent &event) {
  126. if (!App()->HotkeysEnabledInFocus() && event.button() != Qt::LeftButton)
  127. return true;
  128. obs_key_combination_t hotkey = {0, OBS_KEY_NONE};
  129. bool pressed = event.type() == QEvent::MouseButtonPress;
  130. switch (event.button()) {
  131. case Qt::NoButton:
  132. case Qt::LeftButton:
  133. case Qt::RightButton:
  134. case Qt::AllButtons:
  135. case Qt::MouseButtonMask:
  136. return false;
  137. case Qt::MiddleButton:
  138. hotkey.key = OBS_KEY_MOUSE3;
  139. break;
  140. #define MAP_BUTTON(i, j) \
  141. case Qt::ExtraButton##i: \
  142. hotkey.key = OBS_KEY_MOUSE##j; \
  143. break;
  144. MAP_BUTTON(1, 4);
  145. MAP_BUTTON(2, 5);
  146. MAP_BUTTON(3, 6);
  147. MAP_BUTTON(4, 7);
  148. MAP_BUTTON(5, 8);
  149. MAP_BUTTON(6, 9);
  150. MAP_BUTTON(7, 10);
  151. MAP_BUTTON(8, 11);
  152. MAP_BUTTON(9, 12);
  153. MAP_BUTTON(10, 13);
  154. MAP_BUTTON(11, 14);
  155. MAP_BUTTON(12, 15);
  156. MAP_BUTTON(13, 16);
  157. MAP_BUTTON(14, 17);
  158. MAP_BUTTON(15, 18);
  159. MAP_BUTTON(16, 19);
  160. MAP_BUTTON(17, 20);
  161. MAP_BUTTON(18, 21);
  162. MAP_BUTTON(19, 22);
  163. MAP_BUTTON(20, 23);
  164. MAP_BUTTON(21, 24);
  165. MAP_BUTTON(22, 25);
  166. MAP_BUTTON(23, 26);
  167. MAP_BUTTON(24, 27);
  168. #undef MAP_BUTTON
  169. }
  170. hotkey.modifiers = TranslateQtKeyboardEventModifiers(event.modifiers());
  171. obs_hotkey_inject_event(hotkey, pressed);
  172. return true;
  173. };
  174. auto key_event = [&](QKeyEvent *event) {
  175. int key = event->key();
  176. bool enabledInFocus = App()->HotkeysEnabledInFocus();
  177. if (key != Qt::Key_Enter && key != Qt::Key_Escape && key != Qt::Key_Return && !enabledInFocus)
  178. return true;
  179. QDialog *dialog = qobject_cast<QDialog *>(obj);
  180. obs_key_combination_t hotkey = {0, OBS_KEY_NONE};
  181. bool pressed = event->type() == QEvent::KeyPress;
  182. switch (key) {
  183. case Qt::Key_Shift:
  184. case Qt::Key_Control:
  185. case Qt::Key_Alt:
  186. case Qt::Key_Meta:
  187. break;
  188. #ifdef __APPLE__
  189. case Qt::Key_CapsLock:
  190. // kVK_CapsLock == 57
  191. hotkey.key = obs_key_from_virtual_key(57);
  192. pressed = true;
  193. break;
  194. #endif
  195. case Qt::Key_Enter:
  196. case Qt::Key_Escape:
  197. case Qt::Key_Return:
  198. if (dialog && pressed)
  199. return false;
  200. if (!enabledInFocus)
  201. return true;
  202. /* Falls through. */
  203. default:
  204. hotkey.key = obs_key_from_virtual_key(event->nativeVirtualKey());
  205. }
  206. if (event->isAutoRepeat())
  207. return true;
  208. hotkey.modifiers = TranslateQtKeyboardEventModifiers(event->modifiers());
  209. obs_hotkey_inject_event(hotkey, pressed);
  210. return true;
  211. };
  212. switch (event->type()) {
  213. case QEvent::MouseButtonPress:
  214. case QEvent::MouseButtonRelease:
  215. return mouse_event(*static_cast<QMouseEvent *>(event));
  216. /*case QEvent::MouseButtonDblClick:
  217. case QEvent::Wheel:*/
  218. case QEvent::KeyPress:
  219. case QEvent::KeyRelease:
  220. return key_event(static_cast<QKeyEvent *>(event));
  221. default:
  222. return false;
  223. }
  224. });
  225. }
  226. string CurrentDateTimeString()
  227. {
  228. time_t now = time(0);
  229. struct tm tstruct;
  230. char buf[80];
  231. tstruct = *localtime(&now);
  232. strftime(buf, sizeof(buf), "%Y-%m-%d, %X", &tstruct);
  233. return buf;
  234. }
  235. #define DEFAULT_LANG "en-US"
  236. bool OBSApp::InitGlobalConfigDefaults()
  237. {
  238. config_set_default_uint(appConfig, "General", "MaxLogs", 10);
  239. config_set_default_int(appConfig, "General", "InfoIncrement", -1);
  240. config_set_default_string(appConfig, "General", "ProcessPriority", "Normal");
  241. config_set_default_bool(appConfig, "General", "EnableAutoUpdates", true);
  242. #if _WIN32
  243. config_set_default_string(appConfig, "Video", "Renderer", "Direct3D 11");
  244. #else
  245. #if defined(__APPLE__) && defined(__aarch64__)
  246. // TODO: Change this value to "Metal" once the renderer has reached production quality
  247. config_set_default_string(appConfig, "Video", "Renderer", "OpenGL");
  248. #else
  249. config_set_default_string(appConfig, "Video", "Renderer", "OpenGL");
  250. #endif
  251. #endif
  252. #ifdef _WIN32
  253. config_set_default_bool(appConfig, "Audio", "DisableAudioDucking", true);
  254. #endif
  255. #if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
  256. config_set_default_bool(appConfig, "General", "BrowserHWAccel", true);
  257. #endif
  258. #ifdef __APPLE__
  259. config_set_default_bool(appConfig, "Video", "DisableOSXVSync", true);
  260. config_set_default_bool(appConfig, "Video", "ResetOSXVSyncOnExit", true);
  261. #endif
  262. return true;
  263. }
  264. bool OBSApp::InitGlobalLocationDefaults()
  265. {
  266. char path[512];
  267. int len = GetAppConfigPath(path, sizeof(path), nullptr);
  268. if (len <= 0) {
  269. OBSErrorBox(NULL, "Unable to get global configuration path.");
  270. return false;
  271. }
  272. config_set_default_string(appConfig, "Locations", "Configuration", path);
  273. config_set_default_string(appConfig, "Locations", "SceneCollections", path);
  274. config_set_default_string(appConfig, "Locations", "Profiles", path);
  275. config_set_default_string(appConfig, "Locations", "PluginManagerSettings", path);
  276. return true;
  277. }
  278. void OBSApp::InitUserConfigDefaults()
  279. {
  280. config_set_default_bool(userConfig, "General", "ConfirmOnExit", true);
  281. config_set_default_string(userConfig, "General", "HotkeyFocusType", "NeverDisableHotkeys");
  282. config_set_default_bool(userConfig, "BasicWindow", "PreviewEnabled", true);
  283. config_set_default_bool(userConfig, "BasicWindow", "PreviewProgramMode", false);
  284. config_set_default_bool(userConfig, "BasicWindow", "SceneDuplicationMode", true);
  285. config_set_default_bool(userConfig, "BasicWindow", "SwapScenesMode", true);
  286. config_set_default_bool(userConfig, "BasicWindow", "SnappingEnabled", true);
  287. config_set_default_bool(userConfig, "BasicWindow", "ScreenSnapping", true);
  288. config_set_default_bool(userConfig, "BasicWindow", "SourceSnapping", true);
  289. config_set_default_bool(userConfig, "BasicWindow", "CenterSnapping", false);
  290. config_set_default_double(userConfig, "BasicWindow", "SnapDistance", 10.0);
  291. config_set_default_bool(userConfig, "BasicWindow", "SpacingHelpersEnabled", true);
  292. config_set_default_bool(userConfig, "BasicWindow", "RecordWhenStreaming", false);
  293. config_set_default_bool(userConfig, "BasicWindow", "KeepRecordingWhenStreamStops", false);
  294. config_set_default_bool(userConfig, "BasicWindow", "SysTrayEnabled", true);
  295. config_set_default_bool(userConfig, "BasicWindow", "SysTrayWhenStarted", false);
  296. config_set_default_bool(userConfig, "BasicWindow", "SaveProjectors", false);
  297. config_set_default_bool(userConfig, "BasicWindow", "ShowTransitions", true);
  298. config_set_default_bool(userConfig, "BasicWindow", "ShowListboxToolbars", true);
  299. config_set_default_bool(userConfig, "BasicWindow", "ShowStatusBar", true);
  300. config_set_default_bool(userConfig, "BasicWindow", "ShowSourceIcons", true);
  301. config_set_default_bool(userConfig, "BasicWindow", "ShowContextToolbars", true);
  302. config_set_default_bool(userConfig, "BasicWindow", "StudioModeLabels", true);
  303. config_set_default_bool(userConfig, "BasicWindow", "SideDocks", true);
  304. config_set_default_bool(userConfig, "BasicWindow", "VerticalVolumeControl", true);
  305. config_set_default_bool(userConfig, "BasicWindow", "MultiviewMouseSwitch", true);
  306. config_set_default_bool(userConfig, "BasicWindow", "MultiviewDrawNames", true);
  307. config_set_default_bool(userConfig, "BasicWindow", "MultiviewDrawAreas", true);
  308. config_set_default_bool(userConfig, "BasicWindow", "MediaControlsCountdownTimer", true);
  309. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerShowInactive", false);
  310. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerKeepInactiveLast", false);
  311. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerShowHidden", false);
  312. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerKeepHiddenLast", false);
  313. config_set_default_int(userConfig, "Appearance", "FontScale", 10);
  314. config_set_default_int(userConfig, "Appearance", "Density", 1);
  315. }
  316. static bool do_mkdir(const char *path)
  317. {
  318. if (os_mkdirs(path) == MKDIR_ERROR) {
  319. OBSErrorBox(NULL, "Failed to create directory %s", path);
  320. return false;
  321. }
  322. return true;
  323. }
  324. static bool MakeUserDirs()
  325. {
  326. char path[512];
  327. if (GetAppConfigPath(path, sizeof(path), "obs-studio/basic") <= 0)
  328. return false;
  329. if (!do_mkdir(path))
  330. return false;
  331. if (GetAppConfigPath(path, sizeof(path), "obs-studio/logs") <= 0)
  332. return false;
  333. if (!do_mkdir(path))
  334. return false;
  335. if (GetAppConfigPath(path, sizeof(path), "obs-studio/profiler_data") <= 0)
  336. return false;
  337. if (!do_mkdir(path))
  338. return false;
  339. #ifdef _WIN32
  340. if (GetAppConfigPath(path, sizeof(path), "obs-studio/crashes") <= 0)
  341. return false;
  342. if (!do_mkdir(path))
  343. return false;
  344. #endif
  345. #ifdef WHATSNEW_ENABLED
  346. if (GetAppConfigPath(path, sizeof(path), "obs-studio/updates") <= 0)
  347. return false;
  348. if (!do_mkdir(path))
  349. return false;
  350. #endif
  351. if (GetAppConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
  352. return false;
  353. if (!do_mkdir(path))
  354. return false;
  355. return true;
  356. }
  357. constexpr std::string_view OBSProfileSubDirectory = "obs-studio/basic/profiles";
  358. constexpr std::string_view OBSScenesSubDirectory = "obs-studio/basic/scenes";
  359. constexpr std::string_view OBSPluginManagerSubDirectory = "obs-studio/plugin_manager";
  360. static bool MakeUserProfileDirs()
  361. {
  362. const std::filesystem::path userProfilePath =
  363. App()->userProfilesLocation / std::filesystem::u8path(OBSProfileSubDirectory);
  364. const std::filesystem::path userScenesPath =
  365. App()->userScenesLocation / std::filesystem::u8path(OBSScenesSubDirectory);
  366. const std::filesystem::path userPluginManagerPath =
  367. App()->userPluginManagerSettingsLocation / std::filesystem::u8path(OBSPluginManagerSubDirectory);
  368. if (!std::filesystem::exists(userProfilePath)) {
  369. try {
  370. std::filesystem::create_directories(userProfilePath);
  371. } catch (const std::filesystem::filesystem_error &error) {
  372. blog(LOG_ERROR, "Failed to create user profile directory '%s'\n%s",
  373. userProfilePath.u8string().c_str(), error.what());
  374. return false;
  375. }
  376. }
  377. if (!std::filesystem::exists(userScenesPath)) {
  378. try {
  379. std::filesystem::create_directories(userScenesPath);
  380. } catch (const std::filesystem::filesystem_error &error) {
  381. blog(LOG_ERROR, "Failed to create user scene collection directory '%s'\n%s",
  382. userScenesPath.u8string().c_str(), error.what());
  383. return false;
  384. }
  385. }
  386. if (!std::filesystem::exists(userPluginManagerPath)) {
  387. try {
  388. std::filesystem::create_directories(userPluginManagerPath);
  389. } catch (const std::filesystem::filesystem_error &error) {
  390. blog(LOG_ERROR, "Failed to create user plugin manager directory '%s'\n%s",
  391. userPluginManagerPath.u8string().c_str(), error.what());
  392. return false;
  393. }
  394. }
  395. return true;
  396. }
  397. bool OBSApp::UpdatePre22MultiviewLayout(const char *layout)
  398. {
  399. if (!layout)
  400. return false;
  401. if (astrcmpi(layout, "horizontaltop") == 0) {
  402. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  403. static_cast<int>(MultiviewLayout::HORIZONTAL_TOP_8_SCENES));
  404. return true;
  405. }
  406. if (astrcmpi(layout, "horizontalbottom") == 0) {
  407. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  408. static_cast<int>(MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES));
  409. return true;
  410. }
  411. if (astrcmpi(layout, "verticalleft") == 0) {
  412. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  413. static_cast<int>(MultiviewLayout::VERTICAL_LEFT_8_SCENES));
  414. return true;
  415. }
  416. if (astrcmpi(layout, "verticalright") == 0) {
  417. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  418. static_cast<int>(MultiviewLayout::VERTICAL_RIGHT_8_SCENES));
  419. return true;
  420. }
  421. return false;
  422. }
  423. bool OBSApp::InitGlobalConfig()
  424. {
  425. char path[512];
  426. int len = GetAppConfigPath(path, sizeof(path), "obs-studio/global.ini");
  427. if (len <= 0) {
  428. return false;
  429. }
  430. int errorcode = appConfig.Open(path, CONFIG_OPEN_ALWAYS);
  431. if (errorcode != CONFIG_SUCCESS) {
  432. OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
  433. return false;
  434. }
  435. uint32_t lastVersion = config_get_int(appConfig, "General", "LastVersion");
  436. if (lastVersion && lastVersion < MAKE_SEMANTIC_VERSION(31, 0, 0)) {
  437. bool migratedUserSettings = config_get_bool(appConfig, "General", "Pre31Migrated");
  438. if (!migratedUserSettings) {
  439. bool migrated = MigrateGlobalSettings();
  440. config_set_bool(appConfig, "General", "Pre31Migrated", migrated);
  441. config_save_safe(appConfig, "tmp", nullptr);
  442. }
  443. }
  444. InitGlobalConfigDefaults();
  445. InitGlobalLocationDefaults();
  446. std::filesystem::path defaultUserConfigLocation =
  447. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "Configuration"));
  448. std::filesystem::path defaultUserScenesLocation =
  449. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "SceneCollections"));
  450. std::filesystem::path defaultUserProfilesLocation =
  451. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "Profiles"));
  452. std::filesystem::path defaultPluginManagerLocation =
  453. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "PluginManagerSettings"));
  454. if (IsPortableMode()) {
  455. userConfigLocation = std::move(defaultUserConfigLocation);
  456. userScenesLocation = std::move(defaultUserScenesLocation);
  457. userProfilesLocation = std::move(defaultUserProfilesLocation);
  458. userPluginManagerSettingsLocation = std::move(defaultPluginManagerLocation);
  459. } else {
  460. std::filesystem::path currentUserConfigLocation =
  461. std::filesystem::u8path(config_get_string(appConfig, "Locations", "Configuration"));
  462. std::filesystem::path currentUserScenesLocation =
  463. std::filesystem::u8path(config_get_string(appConfig, "Locations", "SceneCollections"));
  464. std::filesystem::path currentUserProfilesLocation =
  465. std::filesystem::u8path(config_get_string(appConfig, "Locations", "Profiles"));
  466. std::filesystem::path currentUserPluginManagerLocation =
  467. std::filesystem::u8path(config_get_string(appConfig, "Locations", "PluginManagerSettings"));
  468. userConfigLocation = (std::filesystem::exists(currentUserConfigLocation))
  469. ? std::move(currentUserConfigLocation)
  470. : std::move(defaultUserConfigLocation);
  471. userScenesLocation = (std::filesystem::exists(currentUserScenesLocation))
  472. ? std::move(currentUserScenesLocation)
  473. : std::move(defaultUserScenesLocation);
  474. userProfilesLocation = (std::filesystem::exists(currentUserProfilesLocation))
  475. ? std::move(currentUserProfilesLocation)
  476. : std::move(defaultUserProfilesLocation);
  477. userPluginManagerSettingsLocation = (std::filesystem::exists(currentUserPluginManagerLocation))
  478. ? std::move(currentUserPluginManagerLocation)
  479. : std::move(defaultPluginManagerLocation);
  480. }
  481. bool userConfigResult = InitUserConfig(userConfigLocation, lastVersion);
  482. return userConfigResult;
  483. }
  484. bool OBSApp::InitUserConfig(std::filesystem::path &userConfigLocation, uint32_t lastVersion)
  485. {
  486. const std::string userConfigFile = userConfigLocation.u8string() + "/obs-studio/user.ini";
  487. int errorCode = userConfig.Open(userConfigFile.c_str(), CONFIG_OPEN_ALWAYS);
  488. if (errorCode != CONFIG_SUCCESS) {
  489. OBSErrorBox(nullptr, "Failed to open user.ini: %d", errorCode);
  490. return false;
  491. }
  492. MigrateLegacySettings(lastVersion);
  493. InitUserConfigDefaults();
  494. return true;
  495. }
  496. void OBSApp::MigrateLegacySettings(const uint32_t lastVersion)
  497. {
  498. bool hasChanges = false;
  499. const uint32_t v19 = MAKE_SEMANTIC_VERSION(19, 0, 0);
  500. const uint32_t v21 = MAKE_SEMANTIC_VERSION(21, 0, 0);
  501. const uint32_t v23 = MAKE_SEMANTIC_VERSION(23, 0, 0);
  502. const uint32_t v24 = MAKE_SEMANTIC_VERSION(24, 0, 0);
  503. const uint32_t v24_1 = MAKE_SEMANTIC_VERSION(24, 1, 0);
  504. const map<uint32_t, string> defaultsMap{
  505. {{v19, "Pre19Defaults"}, {v21, "Pre21Defaults"}, {v23, "Pre23Defaults"}, {v24_1, "Pre24.1Defaults"}}};
  506. for (auto &[version, configKey] : defaultsMap) {
  507. if (!config_has_user_value(userConfig, "General", configKey.c_str())) {
  508. bool useOldDefaults = lastVersion && lastVersion < version;
  509. config_set_bool(userConfig, "General", configKey.c_str(), useOldDefaults);
  510. hasChanges = true;
  511. }
  512. }
  513. if (config_has_user_value(userConfig, "BasicWindow", "MultiviewLayout")) {
  514. const char *layout = config_get_string(userConfig, "BasicWindow", "MultiviewLayout");
  515. bool layoutUpdated = UpdatePre22MultiviewLayout(layout);
  516. hasChanges = hasChanges | layoutUpdated;
  517. }
  518. if (lastVersion && lastVersion < v24) {
  519. bool disableHotkeysInFocus = config_get_bool(userConfig, "General", "DisableHotkeysInFocus");
  520. if (disableHotkeysInFocus) {
  521. config_set_string(userConfig, "General", "HotkeyFocusType", "DisableHotkeysInFocus");
  522. }
  523. hasChanges = true;
  524. }
  525. if (hasChanges) {
  526. userConfig.SaveSafe("tmp");
  527. }
  528. }
  529. static constexpr string_view OBSGlobalIniPath = "/obs-studio/global.ini";
  530. static constexpr string_view OBSUserIniPath = "/obs-studio/user.ini";
  531. bool OBSApp::MigrateGlobalSettings()
  532. {
  533. char path[512];
  534. int len = GetAppConfigPath(path, sizeof(path), nullptr);
  535. if (len <= 0) {
  536. OBSErrorBox(nullptr, "Unable to get global configuration path.");
  537. return false;
  538. }
  539. std::string legacyConfigFileString;
  540. legacyConfigFileString.reserve(strlen(path) + OBSGlobalIniPath.size());
  541. legacyConfigFileString.append(path).append(OBSGlobalIniPath);
  542. const std::filesystem::path legacyGlobalConfigFile = std::filesystem::u8path(legacyConfigFileString);
  543. std::string configFileString;
  544. configFileString.reserve(strlen(path) + OBSUserIniPath.size());
  545. configFileString.append(path).append(OBSUserIniPath);
  546. const std::filesystem::path userConfigFile = std::filesystem::u8path(configFileString);
  547. if (std::filesystem::exists(userConfigFile)) {
  548. OBSErrorBox(nullptr,
  549. "Unable to migrate global configuration - user configuration file already exists.");
  550. return false;
  551. }
  552. try {
  553. std::filesystem::copy(legacyGlobalConfigFile, userConfigFile);
  554. } catch (const std::filesystem::filesystem_error &) {
  555. OBSErrorBox(nullptr, "Unable to migrate global configuration - copy failed.");
  556. return false;
  557. }
  558. return true;
  559. }
  560. bool OBSApp::InitLocale()
  561. {
  562. ProfileScope("OBSApp::InitLocale");
  563. const char *lang = config_get_string(userConfig, "General", "Language");
  564. bool userLocale = config_has_user_value(userConfig, "General", "Language");
  565. if (!userLocale || !lang || lang[0] == '\0')
  566. lang = DEFAULT_LANG;
  567. locale = lang;
  568. // set basic default application locale
  569. if (!locale.empty())
  570. QLocale::setDefault(QLocale(QString::fromStdString(locale).replace('-', '_')));
  571. string englishPath;
  572. if (!GetDataFilePath("locale/" DEFAULT_LANG ".ini", englishPath)) {
  573. OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".ini");
  574. return false;
  575. }
  576. textLookup = text_lookup_create(englishPath.c_str());
  577. if (!textLookup) {
  578. OBSErrorBox(NULL, "Failed to create locale from file '%s'", englishPath.c_str());
  579. return false;
  580. }
  581. bool defaultLang = astrcmpi(lang, DEFAULT_LANG) == 0;
  582. if (userLocale && defaultLang)
  583. return true;
  584. if (!userLocale && defaultLang) {
  585. for (auto &locale_ : GetPreferredLocales()) {
  586. if (locale_ == lang)
  587. return true;
  588. stringstream file;
  589. file << "locale/" << locale_ << ".ini";
  590. string path;
  591. if (!GetDataFilePath(file.str().c_str(), path))
  592. continue;
  593. if (!text_lookup_add(textLookup, path.c_str()))
  594. continue;
  595. blog(LOG_INFO, "Using preferred locale '%s'", locale_.c_str());
  596. locale = locale_;
  597. // set application default locale to the new chosen one
  598. if (!locale.empty())
  599. QLocale::setDefault(QLocale(QString::fromStdString(locale).replace('-', '_')));
  600. return true;
  601. }
  602. return true;
  603. }
  604. stringstream file;
  605. file << "locale/" << lang << ".ini";
  606. string path;
  607. if (GetDataFilePath(file.str().c_str(), path)) {
  608. if (!text_lookup_add(textLookup, path.c_str()))
  609. blog(LOG_ERROR, "Failed to add locale file '%s'", path.c_str());
  610. } else {
  611. blog(LOG_ERROR, "Could not find locale file '%s'", file.str().c_str());
  612. }
  613. return true;
  614. }
  615. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  616. void ParseBranchesJson(const std::string &jsonString, vector<UpdateBranch> &out, std::string &error)
  617. {
  618. JsonBranches branches;
  619. try {
  620. nlohmann::json json = nlohmann::json::parse(jsonString);
  621. branches = json.get<JsonBranches>();
  622. } catch (nlohmann::json::exception &e) {
  623. error = e.what();
  624. return;
  625. }
  626. for (const JsonBranch &json_branch : branches) {
  627. #ifdef _WIN32
  628. if (!json_branch.windows)
  629. continue;
  630. #elif defined(__APPLE__)
  631. if (!json_branch.macos)
  632. continue;
  633. #endif
  634. UpdateBranch branch = {
  635. QString::fromStdString(json_branch.name),
  636. QString::fromStdString(json_branch.display_name),
  637. QString::fromStdString(json_branch.description),
  638. json_branch.enabled,
  639. json_branch.visible,
  640. };
  641. out.push_back(branch);
  642. }
  643. }
  644. bool LoadBranchesFile(vector<UpdateBranch> &out)
  645. {
  646. string error;
  647. string branchesText;
  648. BPtr<char> branchesFilePath = GetAppConfigPathPtr("obs-studio/updates/branches.json");
  649. QFile branchesFile(branchesFilePath.Get());
  650. if (!branchesFile.open(QIODevice::ReadOnly)) {
  651. error = "Opening file failed.";
  652. goto fail;
  653. }
  654. branchesText = branchesFile.readAll().toStdString();
  655. if (branchesText.empty()) {
  656. error = "File empty.";
  657. goto fail;
  658. }
  659. ParseBranchesJson(branchesText, out, error);
  660. if (error.empty())
  661. return !out.empty();
  662. fail:
  663. blog(LOG_WARNING, "Loading branches from file failed: %s", error.c_str());
  664. return false;
  665. }
  666. #endif
  667. void OBSApp::SetBranchData(const string &data)
  668. {
  669. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  670. string error;
  671. vector<UpdateBranch> result;
  672. ParseBranchesJson(data, result, error);
  673. if (!error.empty()) {
  674. blog(LOG_WARNING, "Reading branches JSON response failed: %s", error.c_str());
  675. return;
  676. }
  677. if (!result.empty())
  678. updateBranches = result;
  679. branches_loaded = true;
  680. #else
  681. UNUSED_PARAMETER(data);
  682. #endif
  683. }
  684. std::vector<UpdateBranch> OBSApp::GetBranches()
  685. {
  686. vector<UpdateBranch> out;
  687. /* Always ensure the default branch exists */
  688. out.push_back(UpdateBranch{"stable", "", "", true, true});
  689. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  690. if (!branches_loaded) {
  691. vector<UpdateBranch> result;
  692. if (LoadBranchesFile(result))
  693. updateBranches = result;
  694. branches_loaded = true;
  695. }
  696. #endif
  697. /* Copy additional branches to result (if any) */
  698. if (!updateBranches.empty())
  699. out.insert(out.end(), updateBranches.begin(), updateBranches.end());
  700. return out;
  701. }
  702. OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
  703. : QApplication(argc, argv),
  704. profilerNameStore(store),
  705. appLaunchUUID_(QUuid::createUuid())
  706. {
  707. installNativeEventFilter(new OBS::NativeEventFilter);
  708. /* fix float handling */
  709. #if defined(Q_OS_UNIX)
  710. if (!setlocale(LC_NUMERIC, "C"))
  711. blog(LOG_WARNING, "Failed to set LC_NUMERIC to C locale");
  712. #endif
  713. #ifndef _WIN32
  714. /* Handle SIGINT properly */
  715. socketpair(AF_UNIX, SOCK_STREAM, 0, sigintFd);
  716. snInt = new QSocketNotifier(sigintFd[1], QSocketNotifier::Read, this);
  717. connect(snInt, &QSocketNotifier::activated, this, &OBSApp::ProcessSigInt);
  718. /* Handle SIGTERM */
  719. socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd);
  720. snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this);
  721. connect(snTerm, &QSocketNotifier::activated, this, &OBSApp::ProcessSigTerm);
  722. #endif
  723. connect(qApp, &QGuiApplication::commitDataRequest, this, &OBSApp::commitData, Qt::DirectConnection);
  724. if (multi) {
  725. crashHandler_ = std::make_unique<OBS::CrashHandler>();
  726. } else {
  727. crashHandler_ = std::make_unique<OBS::CrashHandler>(appLaunchUUID_);
  728. }
  729. sleepInhibitor = os_inhibit_sleep_create("OBS Video/audio");
  730. #ifndef __APPLE__
  731. setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png")));
  732. #endif
  733. setDesktopFileName("com.obsproject.Studio");
  734. pluginManager_ = std::make_unique<OBS::PluginManager>();
  735. }
  736. OBSApp::~OBSApp()
  737. {
  738. if (libobs_initialized) {
  739. applicationShutdown();
  740. }
  741. };
  742. static void move_basic_to_profiles(void)
  743. {
  744. char path[512];
  745. if (GetAppConfigPath(path, 512, "obs-studio/basic") <= 0) {
  746. return;
  747. }
  748. const std::filesystem::path basicPath = std::filesystem::u8path(path);
  749. if (!std::filesystem::exists(basicPath)) {
  750. return;
  751. }
  752. const std::filesystem::path profilesPath =
  753. App()->userProfilesLocation / std::filesystem::u8path("obs-studio/basic/profiles");
  754. if (std::filesystem::exists(profilesPath)) {
  755. return;
  756. }
  757. try {
  758. std::filesystem::create_directories(profilesPath);
  759. } catch (const std::filesystem::filesystem_error &error) {
  760. blog(LOG_ERROR, "Failed to create profiles directory for migration from basic profile\n%s",
  761. error.what());
  762. return;
  763. }
  764. const std::filesystem::path newProfilePath = profilesPath / std::filesystem::u8path(Str("Untitled"));
  765. for (auto &entry : std::filesystem::directory_iterator(basicPath)) {
  766. if (entry.is_directory()) {
  767. continue;
  768. }
  769. if (entry.path().filename().u8string() == "scenes.json") {
  770. continue;
  771. }
  772. if (!std::filesystem::exists(newProfilePath)) {
  773. try {
  774. std::filesystem::create_directory(newProfilePath);
  775. } catch (const std::filesystem::filesystem_error &error) {
  776. blog(LOG_ERROR, "Failed to create profile directory for 'Untitled'\n%s", error.what());
  777. return;
  778. }
  779. }
  780. const filesystem::path destinationFile = newProfilePath / entry.path().filename();
  781. const auto copyOptions = std::filesystem::copy_options::overwrite_existing;
  782. try {
  783. std::filesystem::copy(entry.path(), destinationFile, copyOptions);
  784. } catch (const std::filesystem::filesystem_error &error) {
  785. blog(LOG_ERROR, "Failed to copy basic profile file '%s' to new profile 'Untitled'\n%s",
  786. entry.path().filename().u8string().c_str(), error.what());
  787. return;
  788. }
  789. }
  790. }
  791. static void move_basic_to_scene_collections(void)
  792. {
  793. char path[512];
  794. if (GetAppConfigPath(path, 512, "obs-studio/basic") <= 0) {
  795. return;
  796. }
  797. const std::filesystem::path basicPath = std::filesystem::u8path(path);
  798. if (!std::filesystem::exists(basicPath)) {
  799. return;
  800. }
  801. const std::filesystem::path sceneCollectionPath =
  802. App()->userScenesLocation / std::filesystem::u8path("obs-studio/basic/scenes");
  803. if (std::filesystem::exists(sceneCollectionPath)) {
  804. return;
  805. }
  806. try {
  807. std::filesystem::create_directories(sceneCollectionPath);
  808. } catch (const std::filesystem::filesystem_error &error) {
  809. blog(LOG_ERROR,
  810. "Failed to create scene collection directory for migration from basic scene collection\n%s",
  811. error.what());
  812. return;
  813. }
  814. const std::filesystem::path sourceFile = basicPath / std::filesystem::u8path("scenes.json");
  815. const std::filesystem::path destinationFile =
  816. (sceneCollectionPath / std::filesystem::u8path(Str("Untitled"))).replace_extension(".json");
  817. try {
  818. std::filesystem::rename(sourceFile, destinationFile);
  819. } catch (const std::filesystem::filesystem_error &error) {
  820. blog(LOG_ERROR, "Failed to rename basic scene collection file:\n%s", error.what());
  821. return;
  822. }
  823. }
  824. void OBSApp::AppInit()
  825. {
  826. ProfileScope("OBSApp::AppInit");
  827. QAccessible::installFactory(alignmentSelectorFactory);
  828. if (!MakeUserDirs())
  829. throw "Failed to create required user directories";
  830. if (!InitGlobalConfig())
  831. throw "Failed to initialize global config";
  832. if (!InitLocale())
  833. throw "Failed to load locale";
  834. if (!InitTheme())
  835. throw "Failed to load theme";
  836. config_set_default_string(userConfig, "Basic", "Profile", Str("Untitled"));
  837. config_set_default_string(userConfig, "Basic", "ProfileDir", Str("Untitled"));
  838. config_set_default_string(userConfig, "Basic", "SceneCollection", Str("Untitled"));
  839. config_set_default_string(userConfig, "Basic", "SceneCollectionFile", Str("Untitled"));
  840. config_set_default_bool(userConfig, "Basic", "ConfigOnNewProfile", true);
  841. const std::string_view profileName{config_get_string(userConfig, "Basic", "Profile")};
  842. if (profileName.empty()) {
  843. config_set_string(userConfig, "Basic", "Profile", Str("Untitled"));
  844. config_set_string(userConfig, "Basic", "ProfileDir", Str("Untitled"));
  845. }
  846. const std::string_view sceneCollectionName{config_get_string(userConfig, "Basic", "SceneCollection")};
  847. if (sceneCollectionName.empty()) {
  848. config_set_string(userConfig, "Basic", "SceneCollection", Str("Untitled"));
  849. config_set_string(userConfig, "Basic", "SceneCollectionFile", Str("Untitled"));
  850. }
  851. #ifdef _WIN32
  852. bool disableAudioDucking = config_get_bool(appConfig, "Audio", "DisableAudioDucking");
  853. if (disableAudioDucking)
  854. DisableAudioDucking(true);
  855. #endif
  856. #ifdef __APPLE__
  857. if (config_get_bool(appConfig, "Video", "DisableOSXVSync"))
  858. EnableOSXVSync(false);
  859. #endif
  860. UpdateHotkeyFocusSetting(false);
  861. move_basic_to_profiles();
  862. move_basic_to_scene_collections();
  863. if (!MakeUserProfileDirs())
  864. throw "Failed to create profile directories";
  865. }
  866. void OBSApp::checkForUncleanShutdown()
  867. {
  868. bool hasUncleanShutdown = crashHandler_->hasUncleanShutdown();
  869. bool hasNewCrashLog = crashHandler_->hasNewCrashLog();
  870. if (hasUncleanShutdown) {
  871. UncleanLaunchAction launchAction = handleUncleanShutdown(hasNewCrashLog);
  872. safe_mode = launchAction.useSafeMode;
  873. if (launchAction.sendCrashReport) {
  874. crashHandler_->uploadLastCrashLog();
  875. }
  876. }
  877. }
  878. const char *OBSApp::GetRenderModule() const
  879. {
  880. #if defined(_WIN32)
  881. const char *renderer = config_get_string(appConfig, "Video", "Renderer");
  882. return (astrcmpi(renderer, "Direct3D 11") == 0) ? DL_D3D11 : DL_OPENGL;
  883. #elif defined(__APPLE__) && defined(__aarch64__)
  884. const char *renderer = config_get_string(appConfig, "Video", "Renderer");
  885. return (astrcmpi(renderer, "Metal") == 0) ? DL_METAL : DL_OPENGL;
  886. #else
  887. return DL_OPENGL;
  888. #endif
  889. }
  890. static bool StartupOBS(const char *locale, profiler_name_store_t *store)
  891. {
  892. char path[512];
  893. if (GetAppConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
  894. return false;
  895. return obs_startup(locale, path, store);
  896. }
  897. inline void OBSApp::ResetHotkeyState(bool inFocus)
  898. {
  899. obs_hotkey_enable_background_press((inFocus && enableHotkeysInFocus) || (!inFocus && enableHotkeysOutOfFocus));
  900. }
  901. void OBSApp::UpdateHotkeyFocusSetting(bool resetState)
  902. {
  903. enableHotkeysInFocus = true;
  904. enableHotkeysOutOfFocus = true;
  905. const char *hotkeyFocusType = config_get_string(userConfig, "General", "HotkeyFocusType");
  906. if (astrcmpi(hotkeyFocusType, "DisableHotkeysInFocus") == 0) {
  907. enableHotkeysInFocus = false;
  908. } else if (astrcmpi(hotkeyFocusType, "DisableHotkeysOutOfFocus") == 0) {
  909. enableHotkeysOutOfFocus = false;
  910. }
  911. if (resetState)
  912. ResetHotkeyState(applicationState() == Qt::ApplicationActive);
  913. }
  914. void OBSApp::DisableHotkeys()
  915. {
  916. enableHotkeysInFocus = false;
  917. enableHotkeysOutOfFocus = false;
  918. ResetHotkeyState(applicationState() == Qt::ApplicationActive);
  919. }
  920. void OBSApp::Exec(VoidFunc func)
  921. {
  922. func();
  923. }
  924. static void ui_task_handler(obs_task_t task, void *param, bool wait)
  925. {
  926. auto doTask = [=]() {
  927. /* to get clang-format to behave */
  928. task(param);
  929. };
  930. QMetaObject::invokeMethod(App(), "Exec", wait ? WaitConnection() : Qt::AutoConnection, Q_ARG(VoidFunc, doTask));
  931. }
  932. bool OBSApp::OBSInit()
  933. {
  934. ProfileScope("OBSApp::OBSInit");
  935. qRegisterMetaType<VoidFunc>("VoidFunc");
  936. #if !defined(_WIN32) && !defined(__APPLE__)
  937. if (QApplication::platformName() == "xcb") {
  938. #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
  939. auto native = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();
  940. obs_set_nix_platform_display(native->display());
  941. #endif
  942. obs_set_nix_platform(OBS_NIX_PLATFORM_X11_EGL);
  943. blog(LOG_INFO, "Using EGL/X11");
  944. }
  945. #ifdef ENABLE_WAYLAND
  946. if (QApplication::platformName().contains("wayland")) {
  947. #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
  948. auto native = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
  949. obs_set_nix_platform_display(native->display());
  950. #endif
  951. obs_set_nix_platform(OBS_NIX_PLATFORM_WAYLAND);
  952. setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
  953. blog(LOG_INFO, "Platform: Wayland");
  954. }
  955. #endif
  956. #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
  957. QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
  958. obs_set_nix_platform_display(native->nativeResourceForIntegration("display"));
  959. #endif
  960. #endif
  961. #ifdef __APPLE__
  962. setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
  963. #endif
  964. if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
  965. return false;
  966. libobs_initialized = true;
  967. obs_set_ui_task_handler(ui_task_handler);
  968. #if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
  969. bool browserHWAccel = config_get_bool(appConfig, "General", "BrowserHWAccel");
  970. OBSDataAutoRelease settings = obs_data_create();
  971. obs_data_set_bool(settings, "BrowserHWAccel", browserHWAccel);
  972. obs_apply_private_data(settings);
  973. blog(LOG_INFO, "Current Date/Time: %s", CurrentDateTimeString().c_str());
  974. blog(LOG_INFO, "Browser Hardware Acceleration: %s", browserHWAccel ? "true" : "false");
  975. #endif
  976. #ifdef _WIN32
  977. bool hideFromCapture = config_get_bool(userConfig, "BasicWindow", "HideOBSWindowsFromCapture");
  978. blog(LOG_INFO, "Hide OBS windows from screen capture: %s", hideFromCapture ? "true" : "false");
  979. #endif
  980. blog(LOG_INFO, "Qt Version: %s (runtime), %s (compiled)", qVersion(), QT_VERSION_STR);
  981. blog(LOG_INFO, "Portable mode: %s", portable_mode ? "true" : "false");
  982. if (safe_mode) {
  983. blog(LOG_WARNING, "Safe Mode enabled.");
  984. } else if (disable_3p_plugins) {
  985. blog(LOG_WARNING, "Third-party plugins disabled.");
  986. }
  987. setQuitOnLastWindowClosed(false);
  988. mainWindow = new OBSBasic();
  989. mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  990. connect(QApplication::instance(), &QApplication::aboutToQuit, this, [this]() {
  991. /* Ensure OBSMainWindow gets closed */
  992. if (mainWindow) {
  993. mainWindow->close();
  994. delete mainWindow;
  995. }
  996. if (libobs_initialized) {
  997. applicationShutdown();
  998. }
  999. });
  1000. mainWindow->OBSInit();
  1001. connect(OBSBasic::Get(), &OBSBasic::mainWindowClosed, crashHandler_.get(),
  1002. &OBS::CrashHandler::applicationShutdownHandler);
  1003. connect(this, &QGuiApplication::applicationStateChanged, this,
  1004. [this](Qt::ApplicationState state) { ResetHotkeyState(state == Qt::ApplicationActive); });
  1005. ResetHotkeyState(applicationState() == Qt::ApplicationActive);
  1006. connect(crashHandler_.get(), &OBS::CrashHandler::crashLogUploadFailed, this,
  1007. [this](const QString &errorMessage) {
  1008. emit this->logUploadFailed(OBS::LogFileType::CrashLog, errorMessage);
  1009. });
  1010. connect(crashHandler_.get(), &OBS::CrashHandler::crashLogUploadFinished, this,
  1011. [this](const QString &fileUrl) { emit this->logUploadFinished(OBS::LogFileType::CrashLog, fileUrl); });
  1012. return true;
  1013. }
  1014. string OBSApp::GetVersionString(bool platform) const
  1015. {
  1016. stringstream ver;
  1017. ver << obs_get_version_string();
  1018. if (platform) {
  1019. ver << " (";
  1020. #ifdef _WIN32
  1021. if (sizeof(void *) == 8)
  1022. ver << "64-bit, ";
  1023. else
  1024. ver << "32-bit, ";
  1025. ver << "windows)";
  1026. #elif __APPLE__
  1027. ver << "mac)";
  1028. #elif __OpenBSD__
  1029. ver << "openbsd)";
  1030. #elif __FreeBSD__
  1031. ver << "freebsd)";
  1032. #else /* assume linux for the time being */
  1033. ver << "linux)";
  1034. #endif
  1035. }
  1036. return ver.str();
  1037. }
  1038. bool OBSApp::IsPortableMode()
  1039. {
  1040. return portable_mode;
  1041. }
  1042. bool OBSApp::IsUpdaterDisabled()
  1043. {
  1044. return opt_disable_updater;
  1045. }
  1046. bool OBSApp::IsMissingFilesCheckDisabled()
  1047. {
  1048. return opt_disable_missing_files_check;
  1049. }
  1050. #ifdef __APPLE__
  1051. #define INPUT_AUDIO_SOURCE "coreaudio_input_capture"
  1052. #define OUTPUT_AUDIO_SOURCE "coreaudio_output_capture"
  1053. #elif _WIN32
  1054. #define INPUT_AUDIO_SOURCE "wasapi_input_capture"
  1055. #define OUTPUT_AUDIO_SOURCE "wasapi_output_capture"
  1056. #else
  1057. #define INPUT_AUDIO_SOURCE "pulse_input_capture"
  1058. #define OUTPUT_AUDIO_SOURCE "pulse_output_capture"
  1059. #endif
  1060. const char *OBSApp::InputAudioSource() const
  1061. {
  1062. return INPUT_AUDIO_SOURCE;
  1063. }
  1064. const char *OBSApp::OutputAudioSource() const
  1065. {
  1066. return OUTPUT_AUDIO_SOURCE;
  1067. }
  1068. const char *OBSApp::GetLastLog() const
  1069. {
  1070. return lastLogFile.c_str();
  1071. }
  1072. const char *OBSApp::GetCurrentLog() const
  1073. {
  1074. return currentLogFile.c_str();
  1075. }
  1076. void OBSApp::openCrashLogDirectory() const
  1077. {
  1078. std::filesystem::path crashLogDirectory = crashHandler_->getCrashLogDirectory();
  1079. if (crashLogDirectory.empty()) {
  1080. return;
  1081. }
  1082. QString crashLogDirectoryString = QString::fromStdString(crashLogDirectory.u8string());
  1083. QUrl crashLogDirectoryURL = QUrl::fromLocalFile(crashLogDirectoryString);
  1084. QDesktopServices::openUrl(crashLogDirectoryURL);
  1085. }
  1086. void OBSApp::uploadLastAppLog() const
  1087. {
  1088. OBSBasic *basicWindow = static_cast<OBSBasic *>(GetMainWindow());
  1089. basicWindow->UploadLog("obs-studio/logs", GetLastLog(), OBS::LogFileType::LastAppLog);
  1090. }
  1091. void OBSApp::uploadCurrentAppLog() const
  1092. {
  1093. OBSBasic *basicWindow = static_cast<OBSBasic *>(GetMainWindow());
  1094. basicWindow->UploadLog("obs-studio/logs", GetCurrentLog(), OBS::LogFileType::CurrentAppLog);
  1095. }
  1096. void OBSApp::uploadLastCrashLog()
  1097. {
  1098. crashHandler_->uploadLastCrashLog();
  1099. }
  1100. OBS::LogFileState OBSApp::getLogFileState(OBS::LogFileType type) const
  1101. {
  1102. switch (type) {
  1103. case OBS::LogFileType::CrashLog: {
  1104. bool hasNewCrashLog = crashHandler_->hasNewCrashLog();
  1105. return (hasNewCrashLog) ? OBS::LogFileState::New : OBS::LogFileState::Uploaded;
  1106. }
  1107. case OBS::LogFileType::CurrentAppLog:
  1108. case OBS::LogFileType::LastAppLog:
  1109. return OBS::LogFileState::New;
  1110. default:
  1111. return OBS::LogFileState::NoState;
  1112. }
  1113. }
  1114. bool OBSApp::TranslateString(const char *lookupVal, const char **out) const
  1115. {
  1116. for (obs_frontend_translate_ui_cb cb : translatorHooks) {
  1117. if (cb(lookupVal, out))
  1118. return true;
  1119. }
  1120. return text_lookup_getstr(App()->GetTextLookup(), lookupVal, out);
  1121. }
  1122. QStyle *OBSApp::GetInvisibleCursorStyle()
  1123. {
  1124. if (!invisibleCursorStyle) {
  1125. invisibleCursorStyle = std::make_unique<OBSInvisibleCursorProxyStyle>();
  1126. }
  1127. return invisibleCursorStyle.get();
  1128. }
  1129. // Global handler to receive all QEvent::Show events so we can apply
  1130. // display affinity on any newly created windows and dialogs without
  1131. // caring where they are coming from (e.g. plugins).
  1132. bool OBSApp::notify(QObject *receiver, QEvent *e)
  1133. {
  1134. QWidget *w;
  1135. QWindow *window;
  1136. int windowType;
  1137. if (!receiver->isWidgetType())
  1138. goto skip;
  1139. if (e->type() != QEvent::Show)
  1140. goto skip;
  1141. w = qobject_cast<QWidget *>(receiver);
  1142. if (!w->isWindow())
  1143. goto skip;
  1144. window = w->windowHandle();
  1145. if (!window)
  1146. goto skip;
  1147. windowType = window->flags() & Qt::WindowType::WindowType_Mask;
  1148. if (windowType == Qt::WindowType::Dialog || windowType == Qt::WindowType::Window ||
  1149. windowType == Qt::WindowType::Tool) {
  1150. OBSBasic *main = OBSBasic::Get();
  1151. if (main)
  1152. main->SetDisplayAffinity(window);
  1153. }
  1154. skip:
  1155. return QApplication::notify(receiver, e);
  1156. }
  1157. string GenerateTimeDateFilename(const char *extension, bool noSpace)
  1158. {
  1159. time_t now = time(0);
  1160. char file[256] = {};
  1161. struct tm *cur_time;
  1162. cur_time = localtime(&now);
  1163. snprintf(file, sizeof(file), "%d-%02d-%02d%c%02d-%02d-%02d.%s", cur_time->tm_year + 1900, cur_time->tm_mon + 1,
  1164. cur_time->tm_mday, noSpace ? '_' : ' ', cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec,
  1165. extension);
  1166. return string(file);
  1167. }
  1168. string GenerateSpecifiedFilename(const char *extension, bool noSpace, const char *format)
  1169. {
  1170. BPtr<char> filename = os_generate_formatted_filename(extension, !noSpace, format);
  1171. return string(filename);
  1172. }
  1173. static void FindBestFilename(string &strPath, bool noSpace)
  1174. {
  1175. int num = 2;
  1176. if (!os_file_exists(strPath.c_str()))
  1177. return;
  1178. const char *ext = strrchr(strPath.c_str(), '.');
  1179. if (!ext)
  1180. return;
  1181. int extStart = int(ext - strPath.c_str());
  1182. for (;;) {
  1183. string testPath = strPath;
  1184. string numStr;
  1185. numStr = noSpace ? "_" : " (";
  1186. numStr += to_string(num++);
  1187. if (!noSpace)
  1188. numStr += ")";
  1189. testPath.insert(extStart, numStr);
  1190. if (!os_file_exists(testPath.c_str())) {
  1191. strPath = testPath;
  1192. break;
  1193. }
  1194. }
  1195. }
  1196. static void ensure_directory_exists(string &path)
  1197. {
  1198. replace(path.begin(), path.end(), '\\', '/');
  1199. size_t last = path.rfind('/');
  1200. if (last == string::npos)
  1201. return;
  1202. string directory = path.substr(0, last);
  1203. os_mkdirs(directory.c_str());
  1204. }
  1205. static void remove_reserved_file_characters(string &s)
  1206. {
  1207. replace(s.begin(), s.end(), '\\', '/');
  1208. replace(s.begin(), s.end(), '*', '_');
  1209. replace(s.begin(), s.end(), '?', '_');
  1210. replace(s.begin(), s.end(), '"', '_');
  1211. replace(s.begin(), s.end(), '|', '_');
  1212. replace(s.begin(), s.end(), ':', '_');
  1213. replace(s.begin(), s.end(), '>', '_');
  1214. replace(s.begin(), s.end(), '<', '_');
  1215. }
  1216. string GetFormatString(const char *format, const char *prefix, const char *suffix)
  1217. {
  1218. string f;
  1219. f = format;
  1220. if (prefix && *prefix) {
  1221. string str_prefix = prefix;
  1222. if (str_prefix.back() != ' ')
  1223. str_prefix += " ";
  1224. size_t insert_pos = 0;
  1225. size_t tmp;
  1226. tmp = f.find_last_of('/');
  1227. if (tmp != string::npos && tmp > insert_pos)
  1228. insert_pos = tmp + 1;
  1229. tmp = f.find_last_of('\\');
  1230. if (tmp != string::npos && tmp > insert_pos)
  1231. insert_pos = tmp + 1;
  1232. f.insert(insert_pos, str_prefix);
  1233. }
  1234. if (suffix && *suffix) {
  1235. if (*suffix != ' ')
  1236. f += " ";
  1237. f += suffix;
  1238. }
  1239. remove_reserved_file_characters(f);
  1240. return f;
  1241. }
  1242. string GetFormatExt(const char *container)
  1243. {
  1244. string ext = container;
  1245. if (ext == "fragmented_mp4" || ext == "hybrid_mp4")
  1246. ext = "mp4";
  1247. else if (ext == "fragmented_mov" || ext == "hybrid_mov")
  1248. ext = "mov";
  1249. else if (ext == "hls")
  1250. ext = "m3u8";
  1251. else if (ext == "mpegts")
  1252. ext = "ts";
  1253. return ext;
  1254. }
  1255. string GetOutputFilename(const char *path, const char *container, bool noSpace, bool overwrite, const char *format)
  1256. {
  1257. OBSBasic *main = OBSBasic::Get();
  1258. os_dir_t *dir = path && path[0] ? os_opendir(path) : nullptr;
  1259. if (!dir) {
  1260. if (main->isVisible())
  1261. OBSMessageBox::warning(main, QTStr("Output.BadPath.Title"), QTStr("Output.BadPath.Text"));
  1262. else
  1263. main->SysTrayNotify(QTStr("Output.BadPath.Text"), QSystemTrayIcon::Warning);
  1264. return "";
  1265. }
  1266. os_closedir(dir);
  1267. string strPath;
  1268. strPath += path;
  1269. char lastChar = strPath.back();
  1270. if (lastChar != '/' && lastChar != '\\')
  1271. strPath += "/";
  1272. string ext = GetFormatExt(container);
  1273. strPath += GenerateSpecifiedFilename(ext.c_str(), noSpace, format);
  1274. ensure_directory_exists(strPath);
  1275. if (!overwrite)
  1276. FindBestFilename(strPath, noSpace);
  1277. return strPath;
  1278. }
  1279. vector<pair<string, string>> GetLocaleNames()
  1280. {
  1281. string path;
  1282. if (!GetDataFilePath("locale.ini", path))
  1283. throw "Could not find locale.ini path";
  1284. ConfigFile ini;
  1285. if (ini.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
  1286. throw "Could not open locale.ini";
  1287. size_t sections = config_num_sections(ini);
  1288. vector<pair<string, string>> names;
  1289. names.reserve(sections);
  1290. for (size_t i = 0; i < sections; i++) {
  1291. const char *tag = config_get_section(ini, i);
  1292. const char *name = config_get_string(ini, tag, "Name");
  1293. names.emplace_back(tag, name);
  1294. }
  1295. return names;
  1296. }
  1297. #if defined(__APPLE__) || defined(__linux__)
  1298. #define BASE_PATH ".."
  1299. #else
  1300. #define BASE_PATH "../.."
  1301. #endif
  1302. #define CONFIG_PATH BASE_PATH "/config"
  1303. #if defined(ENABLE_PORTABLE_CONFIG) || defined(_WIN32)
  1304. #define ALLOW_PORTABLE_MODE 1
  1305. #else
  1306. #define ALLOW_PORTABLE_MODE 0
  1307. #endif
  1308. int GetAppConfigPath(char *path, size_t size, const char *name)
  1309. {
  1310. #if ALLOW_PORTABLE_MODE
  1311. if (portable_mode) {
  1312. if (name && *name) {
  1313. return snprintf(path, size, CONFIG_PATH "/%s", name);
  1314. } else {
  1315. return snprintf(path, size, CONFIG_PATH);
  1316. }
  1317. } else {
  1318. return os_get_config_path(path, size, name);
  1319. }
  1320. #else
  1321. return os_get_config_path(path, size, name);
  1322. #endif
  1323. }
  1324. char *GetAppConfigPathPtr(const char *name)
  1325. {
  1326. #if ALLOW_PORTABLE_MODE
  1327. if (portable_mode) {
  1328. char path[512];
  1329. if (snprintf(path, sizeof(path), CONFIG_PATH "/%s", name) > 0) {
  1330. return bstrdup(path);
  1331. } else {
  1332. return NULL;
  1333. }
  1334. } else {
  1335. return os_get_config_path_ptr(name);
  1336. }
  1337. #else
  1338. return os_get_config_path_ptr(name);
  1339. #endif
  1340. }
  1341. int GetProgramDataPath(char *path, size_t size, const char *name)
  1342. {
  1343. return os_get_program_data_path(path, size, name);
  1344. }
  1345. char *GetProgramDataPathPtr(const char *name)
  1346. {
  1347. return os_get_program_data_path_ptr(name);
  1348. }
  1349. bool GetFileSafeName(const char *name, std::string &file)
  1350. {
  1351. size_t base_len = strlen(name);
  1352. size_t len = os_utf8_to_wcs(name, base_len, nullptr, 0);
  1353. std::wstring wfile;
  1354. if (!len)
  1355. return false;
  1356. wfile.resize(len);
  1357. os_utf8_to_wcs(name, base_len, &wfile[0], len + 1);
  1358. for (size_t i = wfile.size(); i > 0; i--) {
  1359. size_t im1 = i - 1;
  1360. if (iswspace(wfile[im1])) {
  1361. wfile[im1] = '_';
  1362. } else if (wfile[im1] != '_' && !iswalnum(wfile[im1])) {
  1363. wfile.erase(im1, 1);
  1364. }
  1365. }
  1366. if (wfile.size() == 0)
  1367. wfile = L"characters_only";
  1368. len = os_wcs_to_utf8(wfile.c_str(), wfile.size(), nullptr, 0);
  1369. if (!len)
  1370. return false;
  1371. file.resize(len);
  1372. os_wcs_to_utf8(wfile.c_str(), wfile.size(), &file[0], len + 1);
  1373. return true;
  1374. }
  1375. bool GetClosestUnusedFileName(std::string &path, const char *extension)
  1376. {
  1377. size_t len = path.size();
  1378. if (extension) {
  1379. path += ".";
  1380. path += extension;
  1381. }
  1382. if (!os_file_exists(path.c_str()))
  1383. return true;
  1384. int index = 1;
  1385. do {
  1386. path.resize(len);
  1387. path += std::to_string(++index);
  1388. if (extension) {
  1389. path += ".";
  1390. path += extension;
  1391. }
  1392. } while (os_file_exists(path.c_str()));
  1393. return true;
  1394. }
  1395. bool WindowPositionValid(QRect rect)
  1396. {
  1397. for (QScreen *screen : QGuiApplication::screens()) {
  1398. if (screen->availableGeometry().intersects(rect))
  1399. return true;
  1400. }
  1401. return false;
  1402. }
  1403. #ifndef _WIN32
  1404. void OBSApp::SigIntSignalHandler(int s)
  1405. {
  1406. /* Handles SIGINT and writes to a socket. Qt will read
  1407. * from the socket in the main thread event loop and trigger
  1408. * a call to the ProcessSigInt slot, where we can safely run
  1409. * shutdown code without signal safety issues. */
  1410. UNUSED_PARAMETER(s);
  1411. char a = 1;
  1412. send(sigintFd[0], &a, sizeof(a), 0);
  1413. }
  1414. void OBSApp::SigTermSignalHandler(int s)
  1415. {
  1416. UNUSED_PARAMETER(s);
  1417. char a = 1;
  1418. send(sigtermFd[0], &a, sizeof(a), 0);
  1419. }
  1420. #endif
  1421. void OBSApp::ProcessSigInt(void)
  1422. {
  1423. /* This looks weird, but we can't ifdef a Qt slot function so
  1424. * the SIGINT handler simply does nothing on Windows. */
  1425. #ifndef _WIN32
  1426. char tmp;
  1427. recv(sigintFd[1], &tmp, sizeof(tmp), 0);
  1428. OBSBasic *main = OBSBasic::Get();
  1429. if (main) {
  1430. main->saveAll();
  1431. main->close();
  1432. }
  1433. #endif
  1434. }
  1435. void OBSApp::ProcessSigTerm(void)
  1436. {
  1437. #ifndef _WIN32
  1438. char tmp;
  1439. recv(sigtermFd[1], &tmp, sizeof(tmp), 0);
  1440. OBSBasic *main = OBSBasic::Get();
  1441. if (main) {
  1442. main->saveAll();
  1443. }
  1444. quit();
  1445. #endif
  1446. }
  1447. void OBSApp::commitData(QSessionManager &manager)
  1448. {
  1449. OBSBasic *main = OBSBasic::Get();
  1450. if (main) {
  1451. main->saveAll();
  1452. if (manager.allowsInteraction() && main->shouldPromptForClose()) {
  1453. manager.cancel();
  1454. }
  1455. }
  1456. }
  1457. void OBSApp::applicationShutdown() noexcept
  1458. {
  1459. #ifdef _WIN32
  1460. bool disableAudioDucking = config_get_bool(appConfig, "Audio", "DisableAudioDucking");
  1461. if (disableAudioDucking)
  1462. DisableAudioDucking(false);
  1463. #else
  1464. delete snInt;
  1465. close(sigintFd[0]);
  1466. close(sigintFd[1]);
  1467. delete snTerm;
  1468. close(sigtermFd[0]);
  1469. close(sigtermFd[1]);
  1470. #endif
  1471. #ifdef __APPLE__
  1472. bool vsyncDisabled = config_get_bool(appConfig, "Video", "DisableOSXVSync");
  1473. bool resetVSync = config_get_bool(appConfig, "Video", "ResetOSXVSyncOnExit");
  1474. if (vsyncDisabled && resetVSync)
  1475. EnableOSXVSync(true);
  1476. #endif
  1477. os_inhibit_sleep_set_active(sleepInhibitor, false);
  1478. os_inhibit_sleep_destroy(sleepInhibitor);
  1479. if (libobs_initialized) {
  1480. obs_shutdown();
  1481. libobs_initialized = false;
  1482. }
  1483. }
  1484. void OBSApp::addLogLine(int logLevel, const QString &message)
  1485. {
  1486. emit logLineAdded(logLevel, message);
  1487. }
  1488. void OBSApp::loadAppModules(struct obs_module_failure_info &mfi)
  1489. {
  1490. pluginManager_->preLoad();
  1491. blog(LOG_INFO, "---------------------------------");
  1492. obs_load_all_modules2(&mfi);
  1493. blog(LOG_INFO, "---------------------------------");
  1494. obs_log_loaded_modules();
  1495. blog(LOG_INFO, "---------------------------------");
  1496. obs_post_load_modules();
  1497. pluginManager_->postLoad();
  1498. }
  1499. void OBSApp::pluginManagerOpenDialog()
  1500. {
  1501. pluginManager_->open();
  1502. }