Skip to content

Commit

Permalink
Merge pull request barry-ran#770 from FrzMtrsprt/kill_tray_message
Browse files Browse the repository at this point in the history
fix: don't show tray message twice
  • Loading branch information
barry-ran authored Mar 20, 2023
2 parents e981a17 + 7118faa commit cec31a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 7 additions & 4 deletions QtScrcpy/ui/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ void Dialog::slotActivated(QSystemTrayIcon::ActivationReason reason)
void Dialog::closeEvent(QCloseEvent *event)
{
this->hide();
m_hideIcon->showMessage(tr("Notice"),
tr("Hidden here!"),
QSystemTrayIcon::Information,
3000);
if (!Config::getInstance().getTrayMessageShown()) {
Config::getInstance().setTrayMessageShown(true);
m_hideIcon->showMessage(tr("Notice"),
tr("Hidden here!"),
QSystemTrayIcon::Information,
3000);
}
event->ignore();
}

Expand Down
20 changes: 20 additions & 0 deletions QtScrcpy/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
#define COMMON_AUTO_UPDATE_DEVICE_KEY "AutoUpdateDevice"
#define COMMON_AUTO_UPDATE_DEVICE_DEF true

#define COMMON_TRAY_MESSAGE_SHOWN_KEY "TrayMessageShown"
#define COMMON_TRAY_MESSAGE_SHOWN_DEF false

// device config
#define SERIAL_WINDOW_RECT_KEY_X "WindowRectX"
#define SERIAL_WINDOW_RECT_KEY_Y "WindowRectY"
Expand Down Expand Up @@ -187,6 +190,23 @@ UserBootConfig Config::getUserBootConfig()
return config;
}

void Config::setTrayMessageShown(bool shown)
{
m_userData->beginGroup(GROUP_COMMON);
m_userData->setValue(COMMON_TRAY_MESSAGE_SHOWN_KEY, shown);
m_userData->endGroup();
m_userData->sync();
}

bool Config::getTrayMessageShown()
{
bool shown;
m_userData->beginGroup(GROUP_COMMON);
shown = m_userData->value(COMMON_TRAY_MESSAGE_SHOWN_KEY, COMMON_TRAY_MESSAGE_SHOWN_DEF).toBool();
m_userData->endGroup();
return shown;
}

void Config::setRect(const QString &serial, const QRect &rc)
{
m_userData->beginGroup(serial);
Expand Down
2 changes: 2 additions & 0 deletions QtScrcpy/util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Config : public QObject
// user data:common
void setUserBootConfig(const UserBootConfig &config);
UserBootConfig getUserBootConfig();
void setTrayMessageShown(bool shown);
bool getTrayMessageShown();

// user data:device
void setNickName(const QString &serial, const QString &name);
Expand Down

0 comments on commit cec31a6

Please sign in to comment.