mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-24 05:33:08 +08:00
[fix] show system tray icon on application startup
This commit is contained in:
@@ -392,7 +392,10 @@ struct LinuxTrayImpl {
|
|||||||
exit_menu_label(GetExitMenuLabel(language_index_value)),
|
exit_menu_label(GetExitMenuLabel(language_index_value)),
|
||||||
exit_menu_ascii_label(IsAsciiPrintable(exit_menu_label)
|
exit_menu_ascii_label(IsAsciiPrintable(exit_menu_label)
|
||||||
? exit_menu_label
|
? exit_menu_label
|
||||||
: "Exit") {}
|
: "Exit") {
|
||||||
|
|
||||||
|
EnsureTrayIcon();
|
||||||
|
}
|
||||||
|
|
||||||
explicit LinuxTrayImpl(std::function<void()> show_window_callback,
|
explicit LinuxTrayImpl(std::function<void()> show_window_callback,
|
||||||
std::function<void()> hide_window_callback,
|
std::function<void()> hide_window_callback,
|
||||||
@@ -416,7 +419,9 @@ struct LinuxTrayImpl {
|
|||||||
exit_menu_label(GetExitMenuLabel(language_index_value)),
|
exit_menu_label(GetExitMenuLabel(language_index_value)),
|
||||||
exit_menu_ascii_label(IsAsciiPrintable(exit_menu_label)
|
exit_menu_ascii_label(IsAsciiPrintable(exit_menu_label)
|
||||||
? exit_menu_label
|
? exit_menu_label
|
||||||
: "Exit") {}
|
: "Exit") {
|
||||||
|
EnsureTrayIcon();
|
||||||
|
}
|
||||||
|
|
||||||
~LinuxTrayImpl() { RemoveTrayIcon(); }
|
~LinuxTrayImpl() { RemoveTrayIcon(); }
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ WinTray::WinTray(HWND app_hwnd, HICON icon, const std::wstring& tooltip,
|
|||||||
nid_.uCallbackMessage = WM_TRAY_CALLBACK;
|
nid_.uCallbackMessage = WM_TRAY_CALLBACK;
|
||||||
nid_.hIcon = icon_;
|
nid_.hIcon = icon_;
|
||||||
wcsncpy_s(nid_.szTip, tip_.c_str(), _TRUNCATE);
|
wcsncpy_s(nid_.szTip, tip_.c_str(), _TRUNCATE);
|
||||||
|
|
||||||
|
EnsureTrayIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
WinTray::WinTray(std::function<void()> show_window,
|
WinTray::WinTray(std::function<void()> show_window,
|
||||||
@@ -80,7 +82,7 @@ WinTray::~WinTray() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WinTray::MinimizeToTray() {
|
void WinTray::MinimizeToTray() {
|
||||||
Shell_NotifyIcon(NIM_ADD, &nid_);
|
EnsureTrayIcon();
|
||||||
if (hide_window_) {
|
if (hide_window_) {
|
||||||
hide_window_();
|
hide_window_();
|
||||||
} else if (app_hwnd_) {
|
} else if (app_hwnd_) {
|
||||||
@@ -88,7 +90,25 @@ void WinTray::MinimizeToTray() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinTray::RemoveTrayIcon() { Shell_NotifyIcon(NIM_DELETE, &nid_); }
|
bool WinTray::EnsureTrayIcon() {
|
||||||
|
if (tray_icon_added_) {
|
||||||
|
// NIM_MODIFY also detects an icon lost when Explorer was restarted.
|
||||||
|
if (Shell_NotifyIcon(NIM_MODIFY, &nid_)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
tray_icon_added_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
tray_icon_added_ = Shell_NotifyIcon(NIM_ADD, &nid_) != FALSE;
|
||||||
|
return tray_icon_added_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WinTray::RemoveTrayIcon() {
|
||||||
|
if (tray_icon_added_) {
|
||||||
|
Shell_NotifyIcon(NIM_DELETE, &nid_);
|
||||||
|
tray_icon_added_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WinTray::ShowApplicationWindow() {
|
void WinTray::ShowApplicationWindow() {
|
||||||
if (show_window_) {
|
if (show_window_) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class WinTray {
|
|||||||
bool HandleTrayMessage(MSG* msg);
|
bool HandleTrayMessage(MSG* msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool EnsureTrayIcon();
|
||||||
void ShowApplicationWindow();
|
void ShowApplicationWindow();
|
||||||
void OpenSettings();
|
void OpenSettings();
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ class WinTray {
|
|||||||
std::wstring tip_;
|
std::wstring tip_;
|
||||||
int language_index_;
|
int language_index_;
|
||||||
NOTIFYICONDATA nid_;
|
NOTIFYICONDATA nid_;
|
||||||
|
bool tray_icon_added_ = false;
|
||||||
std::function<void()> show_window_;
|
std::function<void()> show_window_;
|
||||||
std::function<void()> hide_window_;
|
std::function<void()> hide_window_;
|
||||||
std::function<void()> open_settings_;
|
std::function<void()> open_settings_;
|
||||||
|
|||||||
Reference in New Issue
Block a user