@@ -48,39 +48,14 @@ void set_working_directory(){
4848 }
4949}
5050
51- int main (int argc, char *argv[]){
52- setup_crash_handler ();
53-
54- #if defined(__linux) || defined(__APPLE__)
55- // By default Qt uses native menubar but this only works on Windows.
56- // We use menubar in our ButtonDiagram window to choose which controller's button mapping image to show.
57- // So we fix it by don't using native menubar on non-Windows OS.
58- QCoreApplication::setAttribute (Qt::AA_DontUseNativeMenuBar);
59- #endif
6051
61- // #if QT_VERSION_MAJOR == 5 // AA_EnableHighDpiScaling is deprecated in Qt6
62- // QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
63- // #endif
52+ int run_qt (int argc, char *argv[]){
6453 QApplication application (argc, argv);
6554
66- Logger& logger = global_logger_tagged ();
67-
68- logger.log (" ================================================================================" );
69- logger.log (" Starting Program..." );
70-
71- qRegisterMetaType<size_t >(" size_t" );
72- qRegisterMetaType<uint8_t >(" uint8_t" );
73- qRegisterMetaType<std::string>(" std::string" );
74- qRegisterMetaType<Resolution>(" Resolution" );
75-
76- OutputRedirector redirect_stdout (std::cout, " stdout" , Color ());
77- OutputRedirector redirect_stderr (std::cerr, " stderr" , COLOR_RED);
78-
7955 // Preload all the cameras now so we don't hang the UI later on.
8056 get_all_cameras ();
8157
82- QDir ().mkpath (QString::fromStdString (SETTINGS_PATH ()));
83- QDir ().mkpath (QString::fromStdString (SCREENSHOTS_PATH ()));
58+ Logger& logger = global_logger_tagged ();
8459
8560 // Several novice developers struggled to build and run the program due to missing Resources folder.
8661 // Add this check to pop a message box when Resources folder is missing.
@@ -116,6 +91,51 @@ int main(int argc, char *argv[]){
11691
11792 check_new_version (logger);
11893
94+ set_working_directory ();
95+
96+ // Run this asynchronously to we don't block startup.
97+ std::unique_ptr<AsyncTask> task = send_all_unsent_reports (logger, true );
98+
99+
100+ MainWindow w;
101+ w.show ();
102+ w.raise (); // bring the window to front on macOS
103+ set_permissions (w);
104+
105+ return application.exec ();
106+ }
107+
108+
109+ int main (int argc, char *argv[]){
110+ setup_crash_handler ();
111+
112+ #if defined(__linux) || defined(__APPLE__)
113+ // By default Qt uses native menubar but this only works on Windows.
114+ // We use menubar in our ButtonDiagram window to choose which controller's button mapping image to show.
115+ // So we fix it by don't using native menubar on non-Windows OS.
116+ QCoreApplication::setAttribute (Qt::AA_DontUseNativeMenuBar);
117+ #endif
118+
119+ // #if QT_VERSION_MAJOR == 5 // AA_EnableHighDpiScaling is deprecated in Qt6
120+ // QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
121+ // #endif
122+
123+ Logger& logger = global_logger_tagged ();
124+
125+ logger.log (" ================================================================================" );
126+ logger.log (" Starting Program..." );
127+
128+ qRegisterMetaType<size_t >(" size_t" );
129+ qRegisterMetaType<uint8_t >(" uint8_t" );
130+ qRegisterMetaType<std::string>(" std::string" );
131+ qRegisterMetaType<Resolution>(" Resolution" );
132+
133+ OutputRedirector redirect_stdout (std::cout, " stdout" , Color ());
134+ OutputRedirector redirect_stderr (std::cerr, " stderr" , COLOR_RED);
135+
136+ QDir ().mkpath (QString::fromStdString (SETTINGS_PATH ()));
137+ QDir ().mkpath (QString::fromStdString (SCREENSHOTS_PATH ()));
138+
119139 Integration::DiscordIntegrationSettingsOption& discord_settings = GlobalSettings::instance ().DISCORD ->integration ;
120140 if (discord_settings.run_on_start ){
121141#ifdef PA_DPP
@@ -130,23 +150,18 @@ int main(int argc, char *argv[]){
130150 }
131151#endif
132152
133- set_working_directory ();
134153
135- // Run this asynchronously to we don't block startup.
136- std::unique_ptr<AsyncTask> task = send_all_unsent_reports (logger, true );
154+ int ret = run_qt (argc, argv);
137155
138- int ret = 0 ;
139- {
140- MainWindow w;
141- w.show ();
142- w.raise (); // bring the window to front on macOS
143- set_permissions (w);
144- ret = application.exec ();
145- }
146156
147157 // Write program settings back to the json file.
148158 PERSISTENT_SETTINGS ().write ();
149159
160+
161+ #ifdef PA_SOCIAL_SDK
162+ Integration::DiscordSocialSDK::DiscordSocial::instance ().stop ();
163+ #endif
164+
150165#ifdef PA_DPP
151166 Integration::DppClient::Client::instance ().disconnect ();
152167#endif
0 commit comments