diff --git a/src/unlocker/cache-cleaner.cpp b/src/unlocker/cache-cleaner.cpp index f04cc1c..e6f1562 100644 --- a/src/unlocker/cache-cleaner.cpp +++ b/src/unlocker/cache-cleaner.cpp @@ -1,4 +1,5 @@ #include "cache-cleaner.h" + #include "win-platform.h" #include diff --git a/src/unlocker/main.cpp b/src/unlocker/main.cpp index 4ff889b..507cdca 100644 --- a/src/unlocker/main.cpp +++ b/src/unlocker/main.cpp @@ -120,7 +120,7 @@ bool run() } mainLog.info("Setting up system tray icon"); - + TrayIcon tray; tray.setExitCallback([&]() { running = false; diff --git a/src/unlocker/tray-icon.cpp b/src/unlocker/tray-icon.cpp index 677b985..a392093 100644 --- a/src/unlocker/tray-icon.cpp +++ b/src/unlocker/tray-icon.cpp @@ -109,10 +109,13 @@ void TrayIcon::shutdown() } } -void TrayIcon::processMessages() { +void TrayIcon::processMessages() +{ MSG msg; - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - if (msg.message == WM_QUIT) { + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_QUIT) + { break; } TranslateMessage(&msg); @@ -120,22 +123,27 @@ void TrayIcon::processMessages() { } HWND consoleWnd = GetConsoleWindow(); - if (consoleWnd && IsIconic(consoleWnd)) { + if (consoleWnd && IsIconic(consoleWnd)) + { ShowWindow(consoleWnd, SW_HIDE); _isConsoleVisible = false; } } -void TrayIcon::onToggleConsole() { +void TrayIcon::onToggleConsole() +{ HWND consoleWnd = GetConsoleWindow(); if (!consoleWnd) return; - - if (_isConsoleVisible) { + + if (_isConsoleVisible) + { ShowWindow(consoleWnd, SW_HIDE); _isConsoleVisible = false; - } else { + } + else + { ShowWindow(consoleWnd, SW_RESTORE); - + HWND hCurWnd = GetForegroundWindow(); DWORD dwMyID = GetCurrentThreadId(); DWORD dwCurID = GetWindowThreadProcessId(hCurWnd, NULL); @@ -146,7 +154,7 @@ void TrayIcon::onToggleConsole() { SetFocus(consoleWnd); SetActiveWindow(consoleWnd); AttachThreadInput(dwCurID, dwMyID, FALSE); - + _isConsoleVisible = true; } } @@ -158,8 +166,7 @@ void TrayIcon::onOpenControlPanel() void TrayIcon::onExit() { - if (_exitCallback) - _exitCallback(); + if (_exitCallback) _exitCallback(); } void TrayIcon::setExitCallback(std::function callback) diff --git a/src/unlocker/tray-icon.h b/src/unlocker/tray-icon.h index bdba707..e45cad8 100644 --- a/src/unlocker/tray-icon.h +++ b/src/unlocker/tray-icon.h @@ -2,26 +2,27 @@ #include -class TrayIcon { -public: - TrayIcon(); - ~TrayIcon(); +class TrayIcon +{ + public: + TrayIcon(); + ~TrayIcon(); - bool init(); - void shutdown(); - void processMessages(); + bool init(); + void shutdown(); + void processMessages(); - void onToggleConsole(); - void onOpenControlPanel(); - void onExit(); + void onToggleConsole(); + void onOpenControlPanel(); + void onExit(); - void setExitCallback(std::function callback); + void setExitCallback(std::function callback); -private: - static void* windowProc(void* hwnd, unsigned int msg, unsigned long long wParam, long long lParam); - static TrayIcon* instance; + private: + static void* windowProc(void* hwnd, unsigned int msg, unsigned long long wParam, long long lParam); + static TrayIcon* instance; - void* _hwnd; - bool _isConsoleVisible; - std::function _exitCallback; + void* _hwnd; + bool _isConsoleVisible; + std::function _exitCallback; }; diff --git a/src/unlocker/utils.h b/src/unlocker/utils.h index 427856b..563470a 100644 --- a/src/unlocker/utils.h +++ b/src/unlocker/utils.h @@ -6,4 +6,4 @@ namespace utils { std::string getExePath(); std::string randomizeString(size_t length); -} +} // namespace utils diff --git a/src/unlocker/win-platform.h b/src/unlocker/win-platform.h index f0a7024..ff08e9a 100644 --- a/src/unlocker/win-platform.h +++ b/src/unlocker/win-platform.h @@ -15,4 +15,4 @@ #ifdef ERROR #undef ERROR -#endif \ No newline at end of file +#endif