Skip to content

Commit

Permalink
Added command line parameter to hide tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Jul 25, 2022
1 parent a9b6273 commit 0be7d1e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/client/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ bool interpret_commandline(Settings& settings, int argc, char* argv[]) {
else if (argument == T("--check")) {
settings.check_config = true;
}
#if defined(_WIN32)
else if (argument == T("--no-tray")) {
settings.no_tray_icon = true;
}
#endif
else {
return false;
}
Expand All @@ -57,6 +62,9 @@ void print_help_message() {
" -c, --config <path> configuration file.\n"
" -u, --update reload configuration file when it changes.\n"
" -v, --verbose enable verbose output.\n"
#if defined(_WIN32)
" --no-tray do not show tray icon.\n"
#endif
" --check check the config for errors.\n"
" -h, --help print this help.\n"
"\n"
Expand Down
1 change: 1 addition & 0 deletions src/client/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct Settings {
bool auto_update_config;
bool verbose;
bool check_config;
bool no_tray_icon;
};

#if defined(_WIN32)
Expand Down
30 changes: 18 additions & 12 deletions src/client/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ namespace {
} // namespace

void show_notification(const char* message_) {
if (g_settings.no_tray_icon)
return;
auto& icon = g_tray_icon;
const auto message = utf8_to_wide(message_);
icon.uFlags = NIF_INFO;
Expand Down Expand Up @@ -366,16 +368,20 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) {
if (!connect())
return 1;

auto& icon = g_tray_icon;
icon.cbSize = sizeof(icon);
icon.hWnd = g_window;
icon.uID = static_cast<UINT>(
reinterpret_cast<uintptr_t>(g_window));
icon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
lstrcpyW(icon.szTip, window_class_name);
icon.uCallbackMessage = WM_APP_TRAY_NOTIFY;
icon.hIcon = LoadIconW(instance, L"IDI_ICON1");
Shell_NotifyIconW(NIM_ADD, &icon);
if (!g_settings.no_tray_icon) {
auto& icon = g_tray_icon;
icon.cbSize = sizeof(icon);
icon.hWnd = g_window;
icon.uID = static_cast<UINT>(
reinterpret_cast<uintptr_t>(g_window));
icon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
lstrcpyW(icon.szTip, window_class_name);
icon.uCallbackMessage = WM_APP_TRAY_NOTIFY;
icon.hIcon = LoadIconW(instance, L"IDI_ICON1");
Shell_NotifyIconW(NIM_ADD, &icon);

SetTimer(g_window, TIMER_CREATE_TRAY_ICON, recreate_tray_icon_interval_ms, NULL);
}

verbose("Loading configuration file '%ws'", g_settings.config_file_path.c_str());
g_config_file.load(g_settings.config_file_path);
Expand All @@ -390,7 +396,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) {
if (g_settings.auto_update_config)
SetTimer(g_window, TIMER_UPDATE_CONFIG, update_config_interval_ms, NULL);
SetTimer(g_window, TIMER_UPDATE_CONTEXT, update_context_inverval_ms, NULL);
SetTimer(g_window, TIMER_CREATE_TRAY_ICON, recreate_tray_icon_interval_ms, NULL);

verbose("Entering update loop");
auto message = MSG{ };
Expand All @@ -400,7 +405,8 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) {
}
verbose("Exiting");

Shell_NotifyIconW(NIM_DELETE, &g_tray_icon);
if (!g_settings.no_tray_icon)
Shell_NotifyIconW(NIM_DELETE, &g_tray_icon);

return 0;
}

0 comments on commit 0be7d1e

Please sign in to comment.