feat: add tray icon

This commit is contained in:
2026-06-20 06:53:02 -03:00
parent 98be88b346
commit 385cfe147d
3 changed files with 248 additions and 3 deletions
+53 -3
View File
@@ -1,4 +1,5 @@
#include "win-platform.h"
#include "tray-icon.h"
#include "utils.h"
#include "spoofer.h"
#include "log-sink.h"
@@ -103,11 +104,36 @@ bool run()
return false;
}
mainLog.info("Proxy running, Ctrl+C to stop.");
mainLog.info("Setting up system tray icon");
TrayIcon tray;
tray.setExitCallback([&]() {
running = false;
mainLog.info("Exit requested from system tray.");
});
if (!tray.init())
{
mainLog.error("Failed to initialize system tray icon.");
return false;
}
HWND consoleWnd = GetConsoleWindow();
if (consoleWnd)
{
HMENU menuHandle = GetSystemMenu(consoleWnd, FALSE);
if (menuHandle) RemoveMenu(menuHandle, SC_CLOSE, MF_BYCOMMAND);
}
mainLog.info("Proxy running, Ctrl+C to stop. Check system tray for options.");
while (running)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
{
tray.processMessages();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
mainLog.info("Shutting down...");
tray.shutdown();
proxy->shutdown();
cleaner->shutdown();
@@ -116,11 +142,35 @@ bool run()
delete conf;
conf = nullptr;
ReleaseMutex(mtx);
CloseHandle(mtx);
return true;
}
int main()
int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
{
AllocConsole();
/*
ansi seequences
*/
HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if (outHandle == INVALID_HANDLE_VALUE) return 1;
DWORD conMode = 0;
if (!GetConsoleMode(outHandle, &conMode)) return 1;
conMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(outHandle, conMode);
/*
io
*/
FILE* dummy;
freopen_s(&dummy, "CONIN$", "r", stdin);
freopen_s(&dummy, "CONOUT$", "w", stdout);
freopen_s(&dummy, "CONOUT$", "w", stderr);
/*
handlers for cleaning proxy conf on exit / crash / taskkill / whatever