OBSApp.cpp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  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", "VerticalVolumeControl", true);
  304. config_set_default_bool(userConfig, "BasicWindow", "MultiviewMouseSwitch", true);
  305. config_set_default_bool(userConfig, "BasicWindow", "MultiviewDrawNames", true);
  306. config_set_default_bool(userConfig, "BasicWindow", "MultiviewDrawAreas", true);
  307. config_set_default_bool(userConfig, "BasicWindow", "MediaControlsCountdownTimer", true);
  308. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerShowInactive", false);
  309. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerKeepInactiveLast", false);
  310. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerShowHidden", false);
  311. config_set_default_bool(App()->GetUserConfig(), "BasicWindow", "MixerKeepHiddenLast", false);
  312. config_set_default_int(userConfig, "Appearance", "FontScale", 10);
  313. config_set_default_int(userConfig, "Appearance", "Density", 1);
  314. }
  315. static bool do_mkdir(const char *path)
  316. {
  317. if (os_mkdirs(path) == MKDIR_ERROR) {
  318. OBSErrorBox(NULL, "Failed to create directory %s", path);
  319. return false;
  320. }
  321. return true;
  322. }
  323. static bool MakeUserDirs()
  324. {
  325. char path[512];
  326. if (GetAppConfigPath(path, sizeof(path), "obs-studio/basic") <= 0)
  327. return false;
  328. if (!do_mkdir(path))
  329. return false;
  330. if (GetAppConfigPath(path, sizeof(path), "obs-studio/logs") <= 0)
  331. return false;
  332. if (!do_mkdir(path))
  333. return false;
  334. if (GetAppConfigPath(path, sizeof(path), "obs-studio/profiler_data") <= 0)
  335. return false;
  336. if (!do_mkdir(path))
  337. return false;
  338. #ifdef _WIN32
  339. if (GetAppConfigPath(path, sizeof(path), "obs-studio/crashes") <= 0)
  340. return false;
  341. if (!do_mkdir(path))
  342. return false;
  343. #endif
  344. #ifdef WHATSNEW_ENABLED
  345. if (GetAppConfigPath(path, sizeof(path), "obs-studio/updates") <= 0)
  346. return false;
  347. if (!do_mkdir(path))
  348. return false;
  349. #endif
  350. if (GetAppConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
  351. return false;
  352. if (!do_mkdir(path))
  353. return false;
  354. return true;
  355. }
  356. constexpr std::string_view OBSProfileSubDirectory = "obs-studio/basic/profiles";
  357. constexpr std::string_view OBSScenesSubDirectory = "obs-studio/basic/scenes";
  358. constexpr std::string_view OBSPluginManagerSubDirectory = "obs-studio/plugin_manager";
  359. static bool MakeUserProfileDirs()
  360. {
  361. const std::filesystem::path userProfilePath =
  362. App()->userProfilesLocation / std::filesystem::u8path(OBSProfileSubDirectory);
  363. const std::filesystem::path userScenesPath =
  364. App()->userScenesLocation / std::filesystem::u8path(OBSScenesSubDirectory);
  365. const std::filesystem::path userPluginManagerPath =
  366. App()->userPluginManagerSettingsLocation / std::filesystem::u8path(OBSPluginManagerSubDirectory);
  367. if (!std::filesystem::exists(userProfilePath)) {
  368. try {
  369. std::filesystem::create_directories(userProfilePath);
  370. } catch (const std::filesystem::filesystem_error &error) {
  371. blog(LOG_ERROR, "Failed to create user profile directory '%s'\n%s",
  372. userProfilePath.u8string().c_str(), error.what());
  373. return false;
  374. }
  375. }
  376. if (!std::filesystem::exists(userScenesPath)) {
  377. try {
  378. std::filesystem::create_directories(userScenesPath);
  379. } catch (const std::filesystem::filesystem_error &error) {
  380. blog(LOG_ERROR, "Failed to create user scene collection directory '%s'\n%s",
  381. userScenesPath.u8string().c_str(), error.what());
  382. return false;
  383. }
  384. }
  385. if (!std::filesystem::exists(userPluginManagerPath)) {
  386. try {
  387. std::filesystem::create_directories(userPluginManagerPath);
  388. } catch (const std::filesystem::filesystem_error &error) {
  389. blog(LOG_ERROR, "Failed to create user plugin manager directory '%s'\n%s",
  390. userPluginManagerPath.u8string().c_str(), error.what());
  391. return false;
  392. }
  393. }
  394. return true;
  395. }
  396. bool OBSApp::UpdatePre22MultiviewLayout(const char *layout)
  397. {
  398. if (!layout)
  399. return false;
  400. if (astrcmpi(layout, "horizontaltop") == 0) {
  401. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  402. static_cast<int>(MultiviewLayout::HORIZONTAL_TOP_8_SCENES));
  403. return true;
  404. }
  405. if (astrcmpi(layout, "horizontalbottom") == 0) {
  406. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  407. static_cast<int>(MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES));
  408. return true;
  409. }
  410. if (astrcmpi(layout, "verticalleft") == 0) {
  411. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  412. static_cast<int>(MultiviewLayout::VERTICAL_LEFT_8_SCENES));
  413. return true;
  414. }
  415. if (astrcmpi(layout, "verticalright") == 0) {
  416. config_set_int(userConfig, "BasicWindow", "MultiviewLayout",
  417. static_cast<int>(MultiviewLayout::VERTICAL_RIGHT_8_SCENES));
  418. return true;
  419. }
  420. return false;
  421. }
  422. bool OBSApp::InitGlobalConfig()
  423. {
  424. char path[512];
  425. int len = GetAppConfigPath(path, sizeof(path), "obs-studio/global.ini");
  426. if (len <= 0) {
  427. return false;
  428. }
  429. int errorcode = appConfig.Open(path, CONFIG_OPEN_ALWAYS);
  430. if (errorcode != CONFIG_SUCCESS) {
  431. OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
  432. return false;
  433. }
  434. uint32_t lastVersion = config_get_int(appConfig, "General", "LastVersion");
  435. if (lastVersion && lastVersion < MAKE_SEMANTIC_VERSION(31, 0, 0)) {
  436. bool migratedUserSettings = config_get_bool(appConfig, "General", "Pre31Migrated");
  437. if (!migratedUserSettings) {
  438. bool migrated = MigrateGlobalSettings();
  439. config_set_bool(appConfig, "General", "Pre31Migrated", migrated);
  440. config_save_safe(appConfig, "tmp", nullptr);
  441. }
  442. }
  443. InitGlobalConfigDefaults();
  444. InitGlobalLocationDefaults();
  445. std::filesystem::path defaultUserConfigLocation =
  446. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "Configuration"));
  447. std::filesystem::path defaultUserScenesLocation =
  448. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "SceneCollections"));
  449. std::filesystem::path defaultUserProfilesLocation =
  450. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "Profiles"));
  451. std::filesystem::path defaultPluginManagerLocation =
  452. std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "PluginManagerSettings"));
  453. if (IsPortableMode()) {
  454. userConfigLocation = std::move(defaultUserConfigLocation);
  455. userScenesLocation = std::move(defaultUserScenesLocation);
  456. userProfilesLocation = std::move(defaultUserProfilesLocation);
  457. userPluginManagerSettingsLocation = std::move(defaultPluginManagerLocation);
  458. } else {
  459. std::filesystem::path currentUserConfigLocation =
  460. std::filesystem::u8path(config_get_string(appConfig, "Locations", "Configuration"));
  461. std::filesystem::path currentUserScenesLocation =
  462. std::filesystem::u8path(config_get_string(appConfig, "Locations", "SceneCollections"));
  463. std::filesystem::path currentUserProfilesLocation =
  464. std::filesystem::u8path(config_get_string(appConfig, "Locations", "Profiles"));
  465. std::filesystem::path currentUserPluginManagerLocation =
  466. std::filesystem::u8path(config_get_string(appConfig, "Locations", "PluginManagerSettings"));
  467. userConfigLocation = (std::filesystem::exists(currentUserConfigLocation))
  468. ? std::move(currentUserConfigLocation)
  469. : std::move(defaultUserConfigLocation);
  470. userScenesLocation = (std::filesystem::exists(currentUserScenesLocation))
  471. ? std::move(currentUserScenesLocation)
  472. : std::move(defaultUserScenesLocation);
  473. userProfilesLocation = (std::filesystem::exists(currentUserProfilesLocation))
  474. ? std::move(currentUserProfilesLocation)
  475. : std::move(defaultUserProfilesLocation);
  476. userPluginManagerSettingsLocation = (std::filesystem::exists(currentUserPluginManagerLocation))
  477. ? std::move(currentUserPluginManagerLocation)
  478. : std::move(defaultPluginManagerLocation);
  479. }
  480. bool userConfigResult = InitUserConfig(userConfigLocation, lastVersion);
  481. return userConfigResult;
  482. }
  483. bool OBSApp::InitUserConfig(std::filesystem::path &userConfigLocation, uint32_t lastVersion)
  484. {
  485. const std::string userConfigFile = userConfigLocation.u8string() + "/obs-studio/user.ini";
  486. int errorCode = userConfig.Open(userConfigFile.c_str(), CONFIG_OPEN_ALWAYS);
  487. if (errorCode != CONFIG_SUCCESS) {
  488. OBSErrorBox(nullptr, "Failed to open user.ini: %d", errorCode);
  489. return false;
  490. }
  491. MigrateLegacySettings(lastVersion);
  492. InitUserConfigDefaults();
  493. return true;
  494. }
  495. void OBSApp::MigrateLegacySettings(const uint32_t lastVersion)
  496. {
  497. bool hasChanges = false;
  498. const uint32_t v19 = MAKE_SEMANTIC_VERSION(19, 0, 0);
  499. const uint32_t v21 = MAKE_SEMANTIC_VERSION(21, 0, 0);
  500. const uint32_t v23 = MAKE_SEMANTIC_VERSION(23, 0, 0);
  501. const uint32_t v24 = MAKE_SEMANTIC_VERSION(24, 0, 0);
  502. const uint32_t v24_1 = MAKE_SEMANTIC_VERSION(24, 1, 0);
  503. const map<uint32_t, string> defaultsMap{
  504. {{v19, "Pre19Defaults"}, {v21, "Pre21Defaults"}, {v23, "Pre23Defaults"}, {v24_1, "Pre24.1Defaults"}}};
  505. for (auto &[version, configKey] : defaultsMap) {
  506. if (!config_has_user_value(userConfig, "General", configKey.c_str())) {
  507. bool useOldDefaults = lastVersion && lastVersion < version;
  508. config_set_bool(userConfig, "General", configKey.c_str(), useOldDefaults);
  509. hasChanges = true;
  510. }
  511. }
  512. if (config_has_user_value(userConfig, "BasicWindow", "MultiviewLayout")) {
  513. const char *layout = config_get_string(userConfig, "BasicWindow", "MultiviewLayout");
  514. bool layoutUpdated = UpdatePre22MultiviewLayout(layout);
  515. hasChanges = hasChanges | layoutUpdated;
  516. }
  517. if (lastVersion && lastVersion < v24) {
  518. bool disableHotkeysInFocus = config_get_bool(userConfig, "General", "DisableHotkeysInFocus");
  519. if (disableHotkeysInFocus) {
  520. config_set_string(userConfig, "General", "HotkeyFocusType", "DisableHotkeysInFocus");
  521. }
  522. hasChanges = true;
  523. }
  524. if (hasChanges) {
  525. userConfig.SaveSafe("tmp");
  526. }
  527. }
  528. static constexpr string_view OBSGlobalIniPath = "/obs-studio/global.ini";
  529. static constexpr string_view OBSUserIniPath = "/obs-studio/user.ini";
  530. bool OBSApp::MigrateGlobalSettings()
  531. {
  532. char path[512];
  533. int len = GetAppConfigPath(path, sizeof(path), nullptr);
  534. if (len <= 0) {
  535. OBSErrorBox(nullptr, "Unable to get global configuration path.");
  536. return false;
  537. }
  538. std::string legacyConfigFileString;
  539. legacyConfigFileString.reserve(strlen(path) + OBSGlobalIniPath.size());
  540. legacyConfigFileString.append(path).append(OBSGlobalIniPath);
  541. const std::filesystem::path legacyGlobalConfigFile = std::filesystem::u8path(legacyConfigFileString);
  542. std::string configFileString;
  543. configFileString.reserve(strlen(path) + OBSUserIniPath.size());
  544. configFileString.append(path).append(OBSUserIniPath);
  545. const std::filesystem::path userConfigFile = std::filesystem::u8path(configFileString);
  546. if (std::filesystem::exists(userConfigFile)) {
  547. OBSErrorBox(nullptr,
  548. "Unable to migrate global configuration - user configuration file already exists.");
  549. return false;
  550. }
  551. try {
  552. std::filesystem::copy(legacyGlobalConfigFile, userConfigFile);
  553. } catch (const std::filesystem::filesystem_error &) {
  554. OBSErrorBox(nullptr, "Unable to migrate global configuration - copy failed.");
  555. return false;
  556. }
  557. return true;
  558. }
  559. bool OBSApp::InitLocale()
  560. {
  561. ProfileScope("OBSApp::InitLocale");
  562. const char *lang = config_get_string(userConfig, "General", "Language");
  563. bool userLocale = config_has_user_value(userConfig, "General", "Language");
  564. if (!userLocale || !lang || lang[0] == '\0')
  565. lang = DEFAULT_LANG;
  566. locale = lang;
  567. // set basic default application locale
  568. if (!locale.empty())
  569. QLocale::setDefault(QLocale(QString::fromStdString(locale).replace('-', '_')));
  570. string englishPath;
  571. if (!GetDataFilePath("locale/" DEFAULT_LANG ".ini", englishPath)) {
  572. OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".ini");
  573. return false;
  574. }
  575. textLookup = text_lookup_create(englishPath.c_str());
  576. if (!textLookup) {
  577. OBSErrorBox(NULL, "Failed to create locale from file '%s'", englishPath.c_str());
  578. return false;
  579. }
  580. bool defaultLang = astrcmpi(lang, DEFAULT_LANG) == 0;
  581. if (userLocale && defaultLang)
  582. return true;
  583. if (!userLocale && defaultLang) {
  584. for (auto &locale_ : GetPreferredLocales()) {
  585. if (locale_ == lang)
  586. return true;
  587. stringstream file;
  588. file << "locale/" << locale_ << ".ini";
  589. string path;
  590. if (!GetDataFilePath(file.str().c_str(), path))
  591. continue;
  592. if (!text_lookup_add(textLookup, path.c_str()))
  593. continue;
  594. blog(LOG_INFO, "Using preferred locale '%s'", locale_.c_str());
  595. locale = locale_;
  596. // set application default locale to the new chosen one
  597. if (!locale.empty())
  598. QLocale::setDefault(QLocale(QString::fromStdString(locale).replace('-', '_')));
  599. return true;
  600. }
  601. return true;
  602. }
  603. stringstream file;
  604. file << "locale/" << lang << ".ini";
  605. string path;
  606. if (GetDataFilePath(file.str().c_str(), path)) {
  607. if (!text_lookup_add(textLookup, path.c_str()))
  608. blog(LOG_ERROR, "Failed to add locale file '%s'", path.c_str());
  609. } else {
  610. blog(LOG_ERROR, "Could not find locale file '%s'", file.str().c_str());
  611. }
  612. return true;
  613. }
  614. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  615. void ParseBranchesJson(const std::string &jsonString, vector<UpdateBranch> &out, std::string &error)
  616. {
  617. JsonBranches branches;
  618. try {
  619. nlohmann::json json = nlohmann::json::parse(jsonString);
  620. branches = json.get<JsonBranches>();
  621. } catch (nlohmann::json::exception &e) {
  622. error = e.what();
  623. return;
  624. }
  625. for (const JsonBranch &json_branch : branches) {
  626. #ifdef _WIN32
  627. if (!json_branch.windows)
  628. continue;
  629. #elif defined(__APPLE__)
  630. if (!json_branch.macos)
  631. continue;
  632. #endif
  633. UpdateBranch branch = {
  634. QString::fromStdString(json_branch.name),
  635. QString::fromStdString(json_branch.display_name),
  636. QString::fromStdString(json_branch.description),
  637. json_branch.enabled,
  638. json_branch.visible,
  639. };
  640. out.push_back(branch);
  641. }
  642. }
  643. bool LoadBranchesFile(vector<UpdateBranch> &out)
  644. {
  645. string error;
  646. string branchesText;
  647. BPtr<char> branchesFilePath = GetAppConfigPathPtr("obs-studio/updates/branches.json");
  648. QFile branchesFile(branchesFilePath.Get());
  649. if (!branchesFile.open(QIODevice::ReadOnly)) {
  650. error = "Opening file failed.";
  651. goto fail;
  652. }
  653. branchesText = branchesFile.readAll().toStdString();
  654. if (branchesText.empty()) {
  655. error = "File empty.";
  656. goto fail;
  657. }
  658. ParseBranchesJson(branchesText, out, error);
  659. if (error.empty())
  660. return !out.empty();
  661. fail:
  662. blog(LOG_WARNING, "Loading branches from file failed: %s", error.c_str());
  663. return false;
  664. }
  665. #endif
  666. void OBSApp::SetBranchData(const string &data)
  667. {
  668. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  669. string error;
  670. vector<UpdateBranch> result;
  671. ParseBranchesJson(data, result, error);
  672. if (!error.empty()) {
  673. blog(LOG_WARNING, "Reading branches JSON response failed: %s", error.c_str());
  674. return;
  675. }
  676. if (!result.empty())
  677. updateBranches = result;
  678. branches_loaded = true;
  679. #else
  680. UNUSED_PARAMETER(data);
  681. #endif
  682. }
  683. std::vector<UpdateBranch> OBSApp::GetBranches()
  684. {
  685. vector<UpdateBranch> out;
  686. /* Always ensure the default branch exists */
  687. out.push_back(UpdateBranch{"stable", "", "", true, true});
  688. #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
  689. if (!branches_loaded) {
  690. vector<UpdateBranch> result;
  691. if (LoadBranchesFile(result))
  692. updateBranches = result;
  693. branches_loaded = true;
  694. }
  695. #endif
  696. /* Copy additional branches to result (if any) */
  697. if (!updateBranches.empty())
  698. out.insert(out.end(), updateBranches.begin(), updateBranches.end());
  699. return out;
  700. }
  701. OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
  702. : QApplication(argc, argv),
  703. profilerNameStore(store),
  704. appLaunchUUID_(QUuid::createUuid())
  705. {
  706. installNativeEventFilter(new OBS::NativeEventFilter);
  707. /* fix float handling */
  708. #if defined(Q_OS_UNIX)
  709. if (!setlocale(LC_NUMERIC, "C"))
  710. blog(LOG_WARNING, "Failed to set LC_NUMERIC to C locale");
  711. #endif
  712. #ifndef _WIN32
  713. /* Handle SIGINT properly */
  714. socketpair(AF_UNIX, SOCK_STREAM, 0, sigintFd);
  715. snInt = new QSocketNotifier(sigintFd[1], QSocketNotifier::Read, this);
  716. connect(snInt, &QSocketNotifier::activated, this, &OBSApp::ProcessSigInt);
  717. /* Handle SIGTERM */
  718. socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd);
  719. snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this);
  720. connect(snTerm, &QSocketNotifier::activated, this, &OBSApp::ProcessSigTerm);
  721. #endif
  722. connect(qApp, &QGuiApplication::commitDataRequest, this, &OBSApp::commitData, Qt::DirectConnection);
  723. if (multi) {
  724. crashHandler_ = std::make_unique<OBS::CrashHandler>();
  725. } else {
  726. crashHandler_ = std::make_unique<OBS::CrashHandler>(appLaunchUUID_);
  727. }
  728. sleepInhibitor = os_inhibit_sleep_create("OBS Video/audio");
  729. #ifndef __APPLE__
  730. setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png")));
  731. #endif
  732. setDesktopFileName("com.obsproject.Studio");
  733. pluginManager_ = std::make_unique<OBS::PluginManager>();
  734. }
  735. OBSApp::~OBSApp()
  736. {
  737. if (libobs_initialized) {
  738. applicationShutdown();
  739. }
  740. };
  741. static void move_basic_to_profiles(void)
  742. {
  743. char path[512];
  744. if (GetAppConfigPath(path, 512, "obs-studio/basic") <= 0) {
  745. return;
  746. }
  747. const std::filesystem::path basicPath = std::filesystem::u8path(path);
  748. if (!std::filesystem::exists(basicPath)) {
  749. return;
  750. }
  751. const std::filesystem::path profilesPath =
  752. App()->userProfilesLocation / std::filesystem::u8path("obs-studio/basic/profiles");
  753. if (std::filesystem::exists(profilesPath)) {
  754. return;
  755. }
  756. try {
  757. std::filesystem::create_directories(profilesPath);
  758. } catch (const std::filesystem::filesystem_error &error) {
  759. blog(LOG_ERROR, "Failed to create profiles directory for migration from basic profile\n%s",
  760. error.what());
  761. return;
  762. }
  763. const std::filesystem::path newProfilePath = profilesPath / std::filesystem::u8path(Str("Untitled"));
  764. for (auto &entry : std::filesystem::directory_iterator(basicPath)) {
  765. if (entry.is_directory()) {
  766. continue;
  767. }
  768. if (entry.path().filename().u8string() == "scenes.json") {
  769. continue;
  770. }
  771. if (!std::filesystem::exists(newProfilePath)) {
  772. try {
  773. std::filesystem::create_directory(newProfilePath);
  774. } catch (const std::filesystem::filesystem_error &error) {
  775. blog(LOG_ERROR, "Failed to create profile directory for 'Untitled'\n%s", error.what());
  776. return;
  777. }
  778. }
  779. const filesystem::path destinationFile = newProfilePath / entry.path().filename();
  780. const auto copyOptions = std::filesystem::copy_options::overwrite_existing;
  781. try {
  782. std::filesystem::copy(entry.path(), destinationFile, copyOptions);
  783. } catch (const std::filesystem::filesystem_error &error) {
  784. blog(LOG_ERROR, "Failed to copy basic profile file '%s' to new profile 'Untitled'\n%s",
  785. entry.path().filename().u8string().c_str(), error.what());
  786. return;
  787. }
  788. }
  789. }
  790. static void move_basic_to_scene_collections(void)
  791. {
  792. char path[512];
  793. if (GetAppConfigPath(path, 512, "obs-studio/basic") <= 0) {
  794. return;
  795. }
  796. const std::filesystem::path basicPath = std::filesystem::u8path(path);
  797. if (!std::filesystem::exists(basicPath)) {
  798. return;
  799. }
  800. const std::filesystem::path sceneCollectionPath =
  801. App()->userScenesLocation / std::filesystem::u8path("obs-studio/basic/scenes");
  802. if (std::filesystem::exists(sceneCollectionPath)) {
  803. return;
  804. }
  805. try {
  806. std::filesystem::create_directories(sceneCollectionPath);
  807. } catch (const std::filesystem::filesystem_error &error) {
  808. blog(LOG_ERROR,
  809. "Failed to create scene collection directory for migration from basic scene collection\n%s",
  810. error.what());
  811. return;
  812. }
  813. const std::filesystem::path sourceFile = basicPath / std::filesystem::u8path("scenes.json");
  814. const std::filesystem::path destinationFile =
  815. (sceneCollectionPath / std::filesystem::u8path(Str("Untitled"))).replace_extension(".json");
  816. try {
  817. std::filesystem::rename(sourceFile, destinationFile);
  818. } catch (const std::filesystem::filesystem_error &error) {
  819. blog(LOG_ERROR, "Failed to rename basic scene collection file:\n%s", error.what());
  820. return;
  821. }
  822. }
  823. void OBSApp::AppInit()
  824. {
  825. ProfileScope("OBSApp::AppInit");
  826. QAccessible::installFactory(alignmentSelectorFactory);
  827. if (!MakeUserDirs())
  828. throw "Failed to create required user directories";
  829. if (!InitGlobalConfig())
  830. throw "Failed to initialize global config";
  831. if (!InitLocale())
  832. throw "Failed to load locale";
  833. if (!InitTheme())
  834. throw "Failed to load theme";
  835. config_set_default_string(userConfig, "Basic", "Profile", Str("Untitled"));
  836. config_set_default_string(userConfig, "Basic", "ProfileDir", Str("Untitled"));
  837. config_set_default_string(userConfig, "Basic", "SceneCollection", Str("Untitled"));
  838. config_set_default_string(userConfig, "Basic", "SceneCollectionFile", Str("Untitled"));
  839. config_set_default_bool(userConfig, "Basic", "ConfigOnNewProfile", true);
  840. const std::string_view profileName{config_get_string(userConfig, "Basic", "Profile")};
  841. if (profileName.empty()) {
  842. config_set_string(userConfig, "Basic", "Profile", Str("Untitled"));
  843. config_set_string(userConfig, "Basic", "ProfileDir", Str("Untitled"));
  844. }
  845. const std::string_view sceneCollectionName{config_get_string(userConfig, "Basic", "SceneCollection")};
  846. if (sceneCollectionName.empty()) {
  847. config_set_string(userConfig, "Basic", "SceneCollection", Str("Untitled"));
  848. config_set_string(userConfig, "Basic", "SceneCollectionFile", Str("Untitled"));
  849. }
  850. #ifdef _WIN32
  851. bool disableAudioDucking = config_get_bool(appConfig, "Audio", "DisableAudioDucking");
  852. if (disableAudioDucking)
  853. DisableAudioDucking(true);
  854. #endif
  855. #ifdef __APPLE__
  856. if (config_get_bool(appConfig, "Video", "DisableOSXVSync"))
  857. EnableOSXVSync(false);
  858. #endif
  859. UpdateHotkeyFocusSetting(false);
  860. move_basic_to_profiles();
  861. move_basic_to_scene_collections();
  862. if (!MakeUserProfileDirs())
  863. throw "Failed to create profile directories";
  864. }
  865. void OBSApp::checkForUncleanShutdown()
  866. {
  867. bool hasUncleanShutdown = crashHandler_->hasUncleanShutdown();
  868. bool hasNewCrashLog = crashHandler_->hasNewCrashLog();
  869. if (hasUncleanShutdown) {
  870. UncleanLaunchAction launchAction = handleUncleanShutdown(hasNewCrashLog);
  871. safe_mode = launchAction.useSafeMode;
  872. if (launchAction.sendCrashReport) {
  873. crashHandler_->uploadLastCrashLog();
  874. }
  875. }
  876. }
  877. const char *OBSApp::GetRenderModule() const
  878. {
  879. #if defined(_WIN32)
  880. const char *renderer = config_get_string(appConfig, "Video", "Renderer");
  881. return (astrcmpi(renderer, "Direct3D 11") == 0) ? DL_D3D11 : DL_OPENGL;
  882. #elif defined(__APPLE__) && defined(__aarch64__)
  883. const char *renderer = config_get_string(appConfig, "Video", "Renderer");
  884. return (astrcmpi(renderer, "Metal") == 0) ? DL_METAL : DL_OPENGL;
  885. #else
  886. return DL_OPENGL;
  887. #endif
  888. }
  889. static bool StartupOBS(const char *locale, profiler_name_store_t *store)
  890. {
  891. char path[512];
  892. if (GetAppConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
  893. return false;
  894. return obs_startup(locale, path, store);
  895. }
  896. inline void OBSApp::ResetHotkeyState(bool inFocus)
  897. {
  898. obs_hotkey_enable_background_press((inFocus && enableHotkeysInFocus) || (!inFocus && enableHotkeysOutOfFocus));
  899. }
  900. void OBSApp::UpdateHotkeyFocusSetting(bool resetState)
  901. {
  902. enableHotkeysInFocus = true;
  903. enableHotkeysOutOfFocus = true;
  904. const char *hotkeyFocusType = config_get_string(userConfig, "General", "HotkeyFocusType");
  905. if (astrcmpi(hotkeyFocusType, "DisableHotkeysInFocus") == 0) {
  906. enableHotkeysInFocus = false;
  907. } else if (astrcmpi(hotkeyFocusType, "DisableHotkeysOutOfFocus") == 0) {
  908. enableHotkeysOutOfFocus = false;
  909. }
  910. if (resetState)
  911. ResetHotkeyState(applicationState() == Qt::ApplicationActive);
  912. }
  913. void OBSApp::DisableHotkeys()
  914. {
  915. enableHotkeysInFocus = false;
  916. enableHotkeysOutOfFocus = false;
  917. ResetHotkeyState(applicationState() == Qt::ApplicationActive);
  918. }
  919. void OBSApp::Exec(VoidFunc func)
  920. {
  921. func();
  922. }
  923. static void ui_task_handler(obs_task_t task, void *param, bool wait)
  924. {
  925. auto doTask = [=]() {
  926. /* to get clang-format to behave */
  927. task(param);
  928. };
  929. QMetaObject::invokeMethod(App(), "Exec", wait ? WaitConnection() : Qt::AutoConnection, Q_ARG(VoidFunc, doTask));
  930. }
  931. bool OBSApp::OBSInit()
  932. {
  933. ProfileScope("OBSApp::OBSInit");
  934. qRegisterMetaType<VoidFunc>("VoidFunc");
  935. #if !defined(_WIN32) && !defined(__APPLE__)
  936. if (QApplication::platformName() == "xcb") {
  937. #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
  938. auto native = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();
  939. obs_set_nix_platform_display(native->display());
  940. #endif
  941. obs_set_nix_platform(OBS_NIX_PLATFORM_X11_EGL);
  942. blog(LOG_INFO, "Using EGL/X11");
  943. }
  944. #ifdef ENABLE_WAYLAND
  945. if (QApplication::platformName().contains("wayland")) {
  946. #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
  947. auto native = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
  948. obs_set_nix_platform_display(native->display());
  949. #endif
  950. obs_set_nix_platform(OBS_NIX_PLATFORM_WAYLAND);
  951. setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
  952. blog(LOG_INFO, "Platform: Wayland");
  953. }
  954. #endif
  955. #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
  956. QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
  957. obs_set_nix_platform_display(native->nativeResourceForIntegration("display"));
  958. #endif
  959. #endif
  960. #ifdef __APPLE__
  961. setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
  962. #endif
  963. if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
  964. return false;
  965. libobs_initialized = true;
  966. obs_set_ui_task_handler(ui_task_handler);
  967. #if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
  968. bool browserHWAccel = config_get_bool(appConfig, "General", "BrowserHWAccel");
  969. OBSDataAutoRelease settings = obs_data_create();
  970. obs_data_set_bool(settings, "BrowserHWAccel", browserHWAccel);
  971. obs_apply_private_data(settings);
  972. blog(LOG_INFO, "Current Date/Time: %s", CurrentDateTimeString().c_str());
  973. blog(LOG_INFO, "Browser Hardware Acceleration: %s", browserHWAccel ? "true" : "false");
  974. #endif
  975. #ifdef _WIN32
  976. bool hideFromCapture = config_get_bool(userConfig, "BasicWindow", "HideOBSWindowsFromCapture");
  977. blog(LOG_INFO, "Hide OBS windows from screen capture: %s", hideFromCapture ? "true" : "false");
  978. #endif
  979. blog(LOG_INFO, "Qt Version: %s (runtime), %s (compiled)", qVersion(), QT_VERSION_STR);
  980. blog(LOG_INFO, "Portable mode: %s", portable_mode ? "true" : "false");
  981. if (safe_mode) {
  982. blog(LOG_WARNING, "Safe Mode enabled.");
  983. } else if (disable_3p_plugins) {
  984. blog(LOG_WARNING, "Third-party plugins disabled.");
  985. }
  986. setQuitOnLastWindowClosed(false);
  987. mainWindow = new OBSBasic();
  988. mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  989. connect(QApplication::instance(), &QApplication::aboutToQuit, this, [this]() {
  990. /* Ensure OBSMainWindow gets closed */
  991. if (mainWindow) {
  992. mainWindow->close();
  993. delete mainWindow;
  994. }
  995. if (libobs_initialized) {
  996. applicationShutdown();
  997. }
  998. });
  999. mainWindow->OBSInit();
  1000. connect(OBSBasic::Get(), &OBSBasic::mainWindowClosed, crashHandler_.get(),
  1001. &OBS::CrashHandler::applicationShutdownHandler);
  1002. connect(this, &QGuiApplication::applicationStateChanged, this,
  1003. [this](Qt::ApplicationState state) { ResetHotkeyState(state == Qt::ApplicationActive); });
  1004. ResetHotkeyState(applicationState() == Qt::ApplicationActive);
  1005. connect(crashHandler_.get(), &OBS::CrashHandler::crashLogUploadFailed, this,
  1006. [this](const QString &errorMessage) {
  1007. emit this->logUploadFailed(OBS::LogFileType::CrashLog, errorMessage);
  1008. });
  1009. connect(crashHandler_.get(), &OBS::CrashHandler::crashLogUploadFinished, this,
  1010. [this](const QString &fileUrl) { emit this->logUploadFinished(OBS::LogFileType::CrashLog, fileUrl); });
  1011. return true;
  1012. }
  1013. string OBSApp::GetVersionString(bool platform) const
  1014. {
  1015. stringstream ver;
  1016. ver << obs_get_version_string();
  1017. if (platform) {
  1018. ver << " (";
  1019. #ifdef _WIN32
  1020. if (sizeof(void *) == 8)
  1021. ver << "64-bit, ";
  1022. else
  1023. ver << "32-bit, ";
  1024. ver << "windows)";
  1025. #elif __APPLE__
  1026. ver << "mac)";
  1027. #elif __OpenBSD__
  1028. ver << "openbsd)";
  1029. #elif __FreeBSD__
  1030. ver << "freebsd)";
  1031. #else /* assume linux for the time being */
  1032. ver << "linux)";
  1033. #endif
  1034. }
  1035. return ver.str();
  1036. }
  1037. bool OBSApp::IsPortableMode()
  1038. {
  1039. return portable_mode;
  1040. }
  1041. bool OBSApp::IsUpdaterDisabled()
  1042. {
  1043. return opt_disable_updater;
  1044. }
  1045. bool OBSApp::IsMissingFilesCheckDisabled()
  1046. {
  1047. return opt_disable_missing_files_check;
  1048. }
  1049. #ifdef __APPLE__
  1050. #define INPUT_AUDIO_SOURCE "coreaudio_input_capture"
  1051. #define OUTPUT_AUDIO_SOURCE "coreaudio_output_capture"
  1052. #elif _WIN32
  1053. #define INPUT_AUDIO_SOURCE "wasapi_input_capture"
  1054. #define OUTPUT_AUDIO_SOURCE "wasapi_output_capture"
  1055. #else
  1056. #define INPUT_AUDIO_SOURCE "pulse_input_capture"
  1057. #define OUTPUT_AUDIO_SOURCE "pulse_output_capture"
  1058. #endif
  1059. const char *OBSApp::InputAudioSource() const
  1060. {
  1061. return INPUT_AUDIO_SOURCE;
  1062. }
  1063. const char *OBSApp::OutputAudioSource() const
  1064. {
  1065. return OUTPUT_AUDIO_SOURCE;
  1066. }
  1067. const char *OBSApp::GetLastLog() const
  1068. {
  1069. return lastLogFile.c_str();
  1070. }
  1071. const char *OBSApp::GetCurrentLog() const
  1072. {
  1073. return currentLogFile.c_str();
  1074. }
  1075. void OBSApp::openCrashLogDirectory() const
  1076. {
  1077. std::filesystem::path crashLogDirectory = crashHandler_->getCrashLogDirectory();
  1078. if (crashLogDirectory.empty()) {
  1079. return;
  1080. }
  1081. QString crashLogDirectoryString = QString::fromStdString(crashLogDirectory.u8string());
  1082. QUrl crashLogDirectoryURL = QUrl::fromLocalFile(crashLogDirectoryString);
  1083. QDesktopServices::openUrl(crashLogDirectoryURL);
  1084. }
  1085. void OBSApp::uploadLastAppLog() const
  1086. {
  1087. OBSBasic *basicWindow = static_cast<OBSBasic *>(GetMainWindow());
  1088. basicWindow->UploadLog("obs-studio/logs", GetLastLog(), OBS::LogFileType::LastAppLog);
  1089. }
  1090. void OBSApp::uploadCurrentAppLog() const
  1091. {
  1092. OBSBasic *basicWindow = static_cast<OBSBasic *>(GetMainWindow());
  1093. basicWindow->UploadLog("obs-studio/logs", GetCurrentLog(), OBS::LogFileType::CurrentAppLog);
  1094. }
  1095. void OBSApp::uploadLastCrashLog()
  1096. {
  1097. crashHandler_->uploadLastCrashLog();
  1098. }
  1099. OBS::LogFileState OBSApp::getLogFileState(OBS::LogFileType type) const
  1100. {
  1101. switch (type) {
  1102. case OBS::LogFileType::CrashLog: {
  1103. bool hasNewCrashLog = crashHandler_->hasNewCrashLog();
  1104. return (hasNewCrashLog) ? OBS::LogFileState::New : OBS::LogFileState::Uploaded;
  1105. }
  1106. case OBS::LogFileType::CurrentAppLog:
  1107. case OBS::LogFileType::LastAppLog:
  1108. return OBS::LogFileState::New;
  1109. default:
  1110. return OBS::LogFileState::NoState;
  1111. }
  1112. }
  1113. bool OBSApp::TranslateString(const char *lookupVal, const char **out) const
  1114. {
  1115. for (obs_frontend_translate_ui_cb cb : translatorHooks) {
  1116. if (cb(lookupVal, out))
  1117. return true;
  1118. }
  1119. return text_lookup_getstr(App()->GetTextLookup(), lookupVal, out);
  1120. }
  1121. QStyle *OBSApp::GetInvisibleCursorStyle()
  1122. {
  1123. if (!invisibleCursorStyle) {
  1124. invisibleCursorStyle = std::make_unique<OBSInvisibleCursorProxyStyle>();
  1125. }
  1126. return invisibleCursorStyle.get();
  1127. }
  1128. // Global handler to receive all QEvent::Show events so we can apply
  1129. // display affinity on any newly created windows and dialogs without
  1130. // caring where they are coming from (e.g. plugins).
  1131. bool OBSApp::notify(QObject *receiver, QEvent *e)
  1132. {
  1133. QWidget *w;
  1134. QWindow *window;
  1135. int windowType;
  1136. if (!receiver->isWidgetType())
  1137. goto skip;
  1138. if (e->type() != QEvent::Show)
  1139. goto skip;
  1140. w = qobject_cast<QWidget *>(receiver);
  1141. if (!w->isWindow())
  1142. goto skip;
  1143. window = w->windowHandle();
  1144. if (!window)
  1145. goto skip;
  1146. windowType = window->flags() & Qt::WindowType::WindowType_Mask;
  1147. if (windowType == Qt::WindowType::Dialog || windowType == Qt::WindowType::Window ||
  1148. windowType == Qt::WindowType::Tool) {
  1149. OBSBasic *main = OBSBasic::Get();
  1150. if (main)
  1151. main->SetDisplayAffinity(window);
  1152. }
  1153. skip:
  1154. return QApplication::notify(receiver, e);
  1155. }
  1156. string GenerateTimeDateFilename(const char *extension, bool noSpace)
  1157. {
  1158. time_t now = time(0);
  1159. char file[256] = {};
  1160. struct tm *cur_time;
  1161. cur_time = localtime(&now);
  1162. snprintf(file, sizeof(file), "%d-%02d-%02d%c%02d-%02d-%02d.%s", cur_time->tm_year + 1900, cur_time->tm_mon + 1,
  1163. cur_time->tm_mday, noSpace ? '_' : ' ', cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec,
  1164. extension);
  1165. return string(file);
  1166. }
  1167. string GenerateSpecifiedFilename(const char *extension, bool noSpace, const char *format)
  1168. {
  1169. BPtr<char> filename = os_generate_formatted_filename(extension, !noSpace, format);
  1170. return string(filename);
  1171. }
  1172. static void FindBestFilename(string &strPath, bool noSpace)
  1173. {
  1174. int num = 2;
  1175. if (!os_file_exists(strPath.c_str()))
  1176. return;
  1177. const char *ext = strrchr(strPath.c_str(), '.');
  1178. if (!ext)
  1179. return;
  1180. int extStart = int(ext - strPath.c_str());
  1181. for (;;) {
  1182. string testPath = strPath;
  1183. string numStr;
  1184. numStr = noSpace ? "_" : " (";
  1185. numStr += to_string(num++);
  1186. if (!noSpace)
  1187. numStr += ")";
  1188. testPath.insert(extStart, numStr);
  1189. if (!os_file_exists(testPath.c_str())) {
  1190. strPath = testPath;
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. static void ensure_directory_exists(string &path)
  1196. {
  1197. replace(path.begin(), path.end(), '\\', '/');
  1198. size_t last = path.rfind('/');
  1199. if (last == string::npos)
  1200. return;
  1201. string directory = path.substr(0, last);
  1202. os_mkdirs(directory.c_str());
  1203. }
  1204. static void remove_reserved_file_characters(string &s)
  1205. {
  1206. replace(s.begin(), s.end(), '\\', '/');
  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. }
  1215. string GetFormatString(const char *format, const char *prefix, const char *suffix)
  1216. {
  1217. string f;
  1218. f = format;
  1219. if (prefix && *prefix) {
  1220. string str_prefix = prefix;
  1221. if (str_prefix.back() != ' ')
  1222. str_prefix += " ";
  1223. size_t insert_pos = 0;
  1224. size_t tmp;
  1225. tmp = f.find_last_of('/');
  1226. if (tmp != string::npos && tmp > insert_pos)
  1227. insert_pos = tmp + 1;
  1228. tmp = f.find_last_of('\\');
  1229. if (tmp != string::npos && tmp > insert_pos)
  1230. insert_pos = tmp + 1;
  1231. f.insert(insert_pos, str_prefix);
  1232. }
  1233. if (suffix && *suffix) {
  1234. if (*suffix != ' ')
  1235. f += " ";
  1236. f += suffix;
  1237. }
  1238. remove_reserved_file_characters(f);
  1239. return f;
  1240. }
  1241. string GetFormatExt(const char *container)
  1242. {
  1243. string ext = container;
  1244. if (ext == "fragmented_mp4" || ext == "hybrid_mp4")
  1245. ext = "mp4";
  1246. else if (ext == "fragmented_mov" || ext == "hybrid_mov")
  1247. ext = "mov";
  1248. else if (ext == "hls")
  1249. ext = "m3u8";
  1250. else if (ext == "mpegts")
  1251. ext = "ts";
  1252. return ext;
  1253. }
  1254. string GetOutputFilename(const char *path, const char *container, bool noSpace, bool overwrite, const char *format)
  1255. {
  1256. OBSBasic *main = OBSBasic::Get();
  1257. os_dir_t *dir = path && path[0] ? os_opendir(path) : nullptr;
  1258. if (!dir) {
  1259. if (main->isVisible())
  1260. OBSMessageBox::warning(main, QTStr("Output.BadPath.Title"), QTStr("Output.BadPath.Text"));
  1261. else
  1262. main->SysTrayNotify(QTStr("Output.BadPath.Text"), QSystemTrayIcon::Warning);
  1263. return "";
  1264. }
  1265. os_closedir(dir);
  1266. string strPath;
  1267. strPath += path;
  1268. char lastChar = strPath.back();
  1269. if (lastChar != '/' && lastChar != '\\')
  1270. strPath += "/";
  1271. string ext = GetFormatExt(container);
  1272. strPath += GenerateSpecifiedFilename(ext.c_str(), noSpace, format);
  1273. ensure_directory_exists(strPath);
  1274. if (!overwrite)
  1275. FindBestFilename(strPath, noSpace);
  1276. return strPath;
  1277. }
  1278. vector<pair<string, string>> GetLocaleNames()
  1279. {
  1280. string path;
  1281. if (!GetDataFilePath("locale.ini", path))
  1282. throw "Could not find locale.ini path";
  1283. ConfigFile ini;
  1284. if (ini.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
  1285. throw "Could not open locale.ini";
  1286. size_t sections = config_num_sections(ini);
  1287. vector<pair<string, string>> names;
  1288. names.reserve(sections);
  1289. for (size_t i = 0; i < sections; i++) {
  1290. const char *tag = config_get_section(ini, i);
  1291. const char *name = config_get_string(ini, tag, "Name");
  1292. names.emplace_back(tag, name);
  1293. }
  1294. return names;
  1295. }
  1296. #if defined(__APPLE__) || defined(__linux__)
  1297. #define BASE_PATH ".."
  1298. #else
  1299. #define BASE_PATH "../.."
  1300. #endif
  1301. #define CONFIG_PATH BASE_PATH "/config"
  1302. #if defined(ENABLE_PORTABLE_CONFIG) || defined(_WIN32)
  1303. #define ALLOW_PORTABLE_MODE 1
  1304. #else
  1305. #define ALLOW_PORTABLE_MODE 0
  1306. #endif
  1307. int GetAppConfigPath(char *path, size_t size, const char *name)
  1308. {
  1309. #if ALLOW_PORTABLE_MODE
  1310. if (portable_mode) {
  1311. if (name && *name) {
  1312. return snprintf(path, size, CONFIG_PATH "/%s", name);
  1313. } else {
  1314. return snprintf(path, size, CONFIG_PATH);
  1315. }
  1316. } else {
  1317. return os_get_config_path(path, size, name);
  1318. }
  1319. #else
  1320. return os_get_config_path(path, size, name);
  1321. #endif
  1322. }
  1323. char *GetAppConfigPathPtr(const char *name)
  1324. {
  1325. #if ALLOW_PORTABLE_MODE
  1326. if (portable_mode) {
  1327. char path[512];
  1328. if (snprintf(path, sizeof(path), CONFIG_PATH "/%s", name) > 0) {
  1329. return bstrdup(path);
  1330. } else {
  1331. return NULL;
  1332. }
  1333. } else {
  1334. return os_get_config_path_ptr(name);
  1335. }
  1336. #else
  1337. return os_get_config_path_ptr(name);
  1338. #endif
  1339. }
  1340. int GetProgramDataPath(char *path, size_t size, const char *name)
  1341. {
  1342. return os_get_program_data_path(path, size, name);
  1343. }
  1344. char *GetProgramDataPathPtr(const char *name)
  1345. {
  1346. return os_get_program_data_path_ptr(name);
  1347. }
  1348. bool GetFileSafeName(const char *name, std::string &file)
  1349. {
  1350. size_t base_len = strlen(name);
  1351. size_t len = os_utf8_to_wcs(name, base_len, nullptr, 0);
  1352. std::wstring wfile;
  1353. if (!len)
  1354. return false;
  1355. wfile.resize(len);
  1356. os_utf8_to_wcs(name, base_len, &wfile[0], len + 1);
  1357. for (size_t i = wfile.size(); i > 0; i--) {
  1358. size_t im1 = i - 1;
  1359. if (iswspace(wfile[im1])) {
  1360. wfile[im1] = '_';
  1361. } else if (wfile[im1] != '_' && !iswalnum(wfile[im1])) {
  1362. wfile.erase(im1, 1);
  1363. }
  1364. }
  1365. if (wfile.size() == 0)
  1366. wfile = L"characters_only";
  1367. len = os_wcs_to_utf8(wfile.c_str(), wfile.size(), nullptr, 0);
  1368. if (!len)
  1369. return false;
  1370. file.resize(len);
  1371. os_wcs_to_utf8(wfile.c_str(), wfile.size(), &file[0], len + 1);
  1372. return true;
  1373. }
  1374. bool GetClosestUnusedFileName(std::string &path, const char *extension)
  1375. {
  1376. size_t len = path.size();
  1377. if (extension) {
  1378. path += ".";
  1379. path += extension;
  1380. }
  1381. if (!os_file_exists(path.c_str()))
  1382. return true;
  1383. int index = 1;
  1384. do {
  1385. path.resize(len);
  1386. path += std::to_string(++index);
  1387. if (extension) {
  1388. path += ".";
  1389. path += extension;
  1390. }
  1391. } while (os_file_exists(path.c_str()));
  1392. return true;
  1393. }
  1394. bool WindowPositionValid(QRect rect)
  1395. {
  1396. for (QScreen *screen : QGuiApplication::screens()) {
  1397. if (screen->availableGeometry().intersects(rect))
  1398. return true;
  1399. }
  1400. return false;
  1401. }
  1402. #ifndef _WIN32
  1403. void OBSApp::SigIntSignalHandler(int s)
  1404. {
  1405. /* Handles SIGINT and writes to a socket. Qt will read
  1406. * from the socket in the main thread event loop and trigger
  1407. * a call to the ProcessSigInt slot, where we can safely run
  1408. * shutdown code without signal safety issues. */
  1409. UNUSED_PARAMETER(s);
  1410. char a = 1;
  1411. send(sigintFd[0], &a, sizeof(a), 0);
  1412. }
  1413. void OBSApp::SigTermSignalHandler(int s)
  1414. {
  1415. UNUSED_PARAMETER(s);
  1416. char a = 1;
  1417. send(sigtermFd[0], &a, sizeof(a), 0);
  1418. }
  1419. #endif
  1420. void OBSApp::ProcessSigInt(void)
  1421. {
  1422. /* This looks weird, but we can't ifdef a Qt slot function so
  1423. * the SIGINT handler simply does nothing on Windows. */
  1424. #ifndef _WIN32
  1425. char tmp;
  1426. recv(sigintFd[1], &tmp, sizeof(tmp), 0);
  1427. OBSBasic *main = OBSBasic::Get();
  1428. if (main) {
  1429. main->saveAll();
  1430. main->close();
  1431. }
  1432. #endif
  1433. }
  1434. void OBSApp::ProcessSigTerm(void)
  1435. {
  1436. #ifndef _WIN32
  1437. char tmp;
  1438. recv(sigtermFd[1], &tmp, sizeof(tmp), 0);
  1439. OBSBasic *main = OBSBasic::Get();
  1440. if (main) {
  1441. main->saveAll();
  1442. }
  1443. quit();
  1444. #endif
  1445. }
  1446. void OBSApp::commitData(QSessionManager &manager)
  1447. {
  1448. OBSBasic *main = OBSBasic::Get();
  1449. if (main) {
  1450. main->saveAll();
  1451. if (manager.allowsInteraction() && main->shouldPromptForClose()) {
  1452. manager.cancel();
  1453. }
  1454. }
  1455. }
  1456. void OBSApp::applicationShutdown() noexcept
  1457. {
  1458. #ifdef _WIN32
  1459. bool disableAudioDucking = config_get_bool(appConfig, "Audio", "DisableAudioDucking");
  1460. if (disableAudioDucking)
  1461. DisableAudioDucking(false);
  1462. #else
  1463. delete snInt;
  1464. close(sigintFd[0]);
  1465. close(sigintFd[1]);
  1466. delete snTerm;
  1467. close(sigtermFd[0]);
  1468. close(sigtermFd[1]);
  1469. #endif
  1470. #ifdef __APPLE__
  1471. bool vsyncDisabled = config_get_bool(appConfig, "Video", "DisableOSXVSync");
  1472. bool resetVSync = config_get_bool(appConfig, "Video", "ResetOSXVSyncOnExit");
  1473. if (vsyncDisabled && resetVSync)
  1474. EnableOSXVSync(true);
  1475. #endif
  1476. os_inhibit_sleep_set_active(sleepInhibitor, false);
  1477. os_inhibit_sleep_destroy(sleepInhibitor);
  1478. if (libobs_initialized) {
  1479. obs_shutdown();
  1480. libobs_initialized = false;
  1481. }
  1482. }
  1483. void OBSApp::addLogLine(int logLevel, const QString &message)
  1484. {
  1485. emit logLineAdded(logLevel, message);
  1486. }
  1487. void OBSApp::loadAppModules(struct obs_module_failure_info &mfi)
  1488. {
  1489. pluginManager_->preLoad();
  1490. blog(LOG_INFO, "---------------------------------");
  1491. obs_load_all_modules2(&mfi);
  1492. blog(LOG_INFO, "---------------------------------");
  1493. obs_log_loaded_modules();
  1494. blog(LOG_INFO, "---------------------------------");
  1495. obs_post_load_modules();
  1496. pluginManager_->postLoad();
  1497. }
  1498. void OBSApp::pluginManagerOpenDialog()
  1499. {
  1500. pluginManager_->open();
  1501. }