diff --git a/Common/System/System.h b/Common/System/System.h index deebbac2d5..dbb10375d4 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -250,6 +250,7 @@ enum SystemProperty { SYSPROP_INSTALLER_NAME, // Useful on Android to check if we were installed from the play store. }; +// NOTE: Unlike requests or UIMessage, these are synchronous! enum class SystemNotification { UI, MEM_VIEW, @@ -273,6 +274,8 @@ enum class SystemNotification { AUDIO_MODE_CHANGED, APP_SWITCH_MODE_CHANGED, PAD_STATE_CHANGED, + CONFIG_LOADED, + BEFORE_CONFIG_SAVE_ON_EXIT, }; // I guess it's not super great architecturally to centralize this, since it's not general - but same with a lot of diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 81857bfae1..eafea2dfe7 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -575,6 +575,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch // Note that if we don't have storage permission here, loading the config will // fail and it will be set to the default. Later, we load again when we get permission. g_Config.Load(); + System_Notify(SystemNotification::CONFIG_LOADED); #endif const char *fileToLog = nullptr; @@ -1708,6 +1709,8 @@ void NativeShutdown() { g_screenManager = nullptr; } + System_Notify(SystemNotification::BEFORE_CONFIG_SAVE_ON_EXIT); + g_Config.Save("NativeShutdown"); g_i18nrepo.LogMissingKeys(); diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index fbd86c37a5..5e6fe75e77 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -54,9 +54,6 @@ static GraphicsContext *g_graphicsContext; void MainThreadFunc(); -// On most other platforms, we let the "main" thread become the render thread and -// start a separate emu thread from that, if needed. Should probably switch to that -// to make it the same on all platforms. void MainThread_Start(bool separateEmuThread) { useEmuThread = separateEmuThread; mainThread = std::thread(&MainThreadFunc); @@ -152,11 +149,6 @@ void MainThreadFunc() { // We'll start up a separate thread we'll call Emu SetCurrentThreadName(useEmuThread ? "RenderThread" : "EmuThread"); - const HWND console = GetConsoleWindow(); - if (console && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1) { - SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER); - } - System_SetWindowTitle(""); // We convert command line arguments to UTF-8 immediately. @@ -319,12 +311,6 @@ void MainThreadFunc() { delete g_graphicsContext; g_graphicsContext = nullptr; - RECT rc; - if (console && GetWindowRect(console, &rc) && !IsIconic(console)) { - g_Config.iConsoleWindowX = rc.left; - g_Config.iConsoleWindowY = rc.top; - } - NativeShutdown(); PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_UPDATE_UI, 0, 0); diff --git a/Windows/main.cpp b/Windows/main.cpp index 5d7ea4bf0d..e0ddc78c50 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -594,6 +594,21 @@ void System_Notify(SystemNotification notification) { case SystemNotification::APP_SWITCH_MODE_CHANGED: case SystemNotification::UI_STATE_CHANGED: break; + case SystemNotification::CONFIG_LOADED: + { + // This is too early to move the console into position - hasn't been allocated yet. + break; + } + case SystemNotification::BEFORE_CONFIG_SAVE_ON_EXIT: + { + RECT rc{}; + const HWND console = GetConsoleWindow(); + if (console && GetWindowRect(console, &rc) && !IsIconic(console)) { + g_Config.iConsoleWindowX = rc.left; + g_Config.iConsoleWindowY = rc.top; + } + break; + } } } @@ -1088,6 +1103,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin // if it's not loaded here first. g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM)); g_Config.Load(configFilename.c_str(), controlsConfigFilename.c_str()); + System_Notify(SystemNotification::CONFIG_LOADED); bool debugLogLevel = false; @@ -1170,6 +1186,12 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin // - It should be possible to log to a file without showing the console. g_logManager.GetConsoleListener()->Init(showLog, 150, 120); + // Move the console into position. + const HWND console = GetConsoleWindow(); + if (console && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1) { + SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + } + if (debugLogLevel) { g_logManager.SetAllLogLevels(LogLevel::LDEBUG); }