style: run format
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include "cache-cleaner.h"
|
#include "cache-cleaner.h"
|
||||||
|
|
||||||
#include "win-platform.h"
|
#include "win-platform.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ bool run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainLog.info("Setting up system tray icon");
|
mainLog.info("Setting up system tray icon");
|
||||||
|
|
||||||
TrayIcon tray;
|
TrayIcon tray;
|
||||||
tray.setExitCallback([&]() {
|
tray.setExitCallback([&]() {
|
||||||
running = false;
|
running = false;
|
||||||
|
|||||||
+19
-12
@@ -109,10 +109,13 @@ void TrayIcon::shutdown()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::processMessages() {
|
void TrayIcon::processMessages()
|
||||||
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
if (msg.message == WM_QUIT) {
|
{
|
||||||
|
if (msg.message == WM_QUIT)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
@@ -120,22 +123,27 @@ void TrayIcon::processMessages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HWND consoleWnd = GetConsoleWindow();
|
HWND consoleWnd = GetConsoleWindow();
|
||||||
if (consoleWnd && IsIconic(consoleWnd)) {
|
if (consoleWnd && IsIconic(consoleWnd))
|
||||||
|
{
|
||||||
ShowWindow(consoleWnd, SW_HIDE);
|
ShowWindow(consoleWnd, SW_HIDE);
|
||||||
_isConsoleVisible = false;
|
_isConsoleVisible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::onToggleConsole() {
|
void TrayIcon::onToggleConsole()
|
||||||
|
{
|
||||||
HWND consoleWnd = GetConsoleWindow();
|
HWND consoleWnd = GetConsoleWindow();
|
||||||
if (!consoleWnd) return;
|
if (!consoleWnd) return;
|
||||||
|
|
||||||
if (_isConsoleVisible) {
|
if (_isConsoleVisible)
|
||||||
|
{
|
||||||
ShowWindow(consoleWnd, SW_HIDE);
|
ShowWindow(consoleWnd, SW_HIDE);
|
||||||
_isConsoleVisible = false;
|
_isConsoleVisible = false;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ShowWindow(consoleWnd, SW_RESTORE);
|
ShowWindow(consoleWnd, SW_RESTORE);
|
||||||
|
|
||||||
HWND hCurWnd = GetForegroundWindow();
|
HWND hCurWnd = GetForegroundWindow();
|
||||||
DWORD dwMyID = GetCurrentThreadId();
|
DWORD dwMyID = GetCurrentThreadId();
|
||||||
DWORD dwCurID = GetWindowThreadProcessId(hCurWnd, NULL);
|
DWORD dwCurID = GetWindowThreadProcessId(hCurWnd, NULL);
|
||||||
@@ -146,7 +154,7 @@ void TrayIcon::onToggleConsole() {
|
|||||||
SetFocus(consoleWnd);
|
SetFocus(consoleWnd);
|
||||||
SetActiveWindow(consoleWnd);
|
SetActiveWindow(consoleWnd);
|
||||||
AttachThreadInput(dwCurID, dwMyID, FALSE);
|
AttachThreadInput(dwCurID, dwMyID, FALSE);
|
||||||
|
|
||||||
_isConsoleVisible = true;
|
_isConsoleVisible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,8 +166,7 @@ void TrayIcon::onOpenControlPanel()
|
|||||||
|
|
||||||
void TrayIcon::onExit()
|
void TrayIcon::onExit()
|
||||||
{
|
{
|
||||||
if (_exitCallback)
|
if (_exitCallback) _exitCallback();
|
||||||
_exitCallback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::setExitCallback(std::function<void()> callback)
|
void TrayIcon::setExitCallback(std::function<void()> callback)
|
||||||
|
|||||||
+18
-17
@@ -2,26 +2,27 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
class TrayIcon {
|
class TrayIcon
|
||||||
public:
|
{
|
||||||
TrayIcon();
|
public:
|
||||||
~TrayIcon();
|
TrayIcon();
|
||||||
|
~TrayIcon();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
void processMessages();
|
void processMessages();
|
||||||
|
|
||||||
void onToggleConsole();
|
void onToggleConsole();
|
||||||
void onOpenControlPanel();
|
void onOpenControlPanel();
|
||||||
void onExit();
|
void onExit();
|
||||||
|
|
||||||
void setExitCallback(std::function<void()> callback);
|
void setExitCallback(std::function<void()> callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void* windowProc(void* hwnd, unsigned int msg, unsigned long long wParam, long long lParam);
|
static void* windowProc(void* hwnd, unsigned int msg, unsigned long long wParam, long long lParam);
|
||||||
static TrayIcon* instance;
|
static TrayIcon* instance;
|
||||||
|
|
||||||
void* _hwnd;
|
void* _hwnd;
|
||||||
bool _isConsoleVisible;
|
bool _isConsoleVisible;
|
||||||
std::function<void()> _exitCallback;
|
std::function<void()> _exitCallback;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ namespace utils
|
|||||||
{
|
{
|
||||||
std::string getExePath();
|
std::string getExePath();
|
||||||
std::string randomizeString(size_t length);
|
std::string randomizeString(size_t length);
|
||||||
}
|
} // namespace utils
|
||||||
|
|||||||
@@ -15,4 +15,4 @@
|
|||||||
|
|
||||||
#ifdef ERROR
|
#ifdef ERROR
|
||||||
#undef ERROR
|
#undef ERROR
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user