feat: Allow users to pick mono color (based on isDarkMode) or colorful icon

This commit is contained in:
sithlord48 2025-01-07 02:07:55 -05:00 committed by Nick Bolton
parent fc6d39ae6c
commit 42a17726d9
5 changed files with 76 additions and 10 deletions

View file

@ -32,6 +32,7 @@
#include "gui/diagnostic.h" #include "gui/diagnostic.h"
#include "gui/messages.h" #include "gui/messages.h"
#include "gui/string_utils.h" #include "gui/string_utils.h"
#include "gui/style_utils.h"
#include "gui/styles.h" #include "gui/styles.h"
#include "gui/tls/TlsFingerprint.h" #include "gui/tls/TlsFingerprint.h"
#include "platform/wayland.h" #include "platform/wayland.h"
@ -66,12 +67,9 @@ using CoreMode = CoreProcess::Mode;
using CoreConnectionState = CoreProcess::ConnectionState; using CoreConnectionState = CoreProcess::ConnectionState;
using CoreProcessState = CoreProcess::ProcessState; using CoreProcessState = CoreProcess::ProcessState;
const auto kIconFile = ":/icons/128x128/tray.png"; const auto kColorfulIconFile = ":/icons/128x128/tray.png";
#ifdef Q_OS_MAC
const auto kLightIconFile = ":/icons/128x128/tray-light.png"; const auto kLightIconFile = ":/icons/128x128/tray-light.png";
const auto kDarkIconFile = ":/icons/128x128/tray-dark.png"; const auto kDarkIconFile = ":/icons/128x128/tray-dark.png";
#endif // Q_OS_MAC
MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
: ui{std::make_unique<Ui::MainWindow>()}, : ui{std::make_unique<Ui::MainWindow>()},
@ -673,6 +671,7 @@ void MainWindow::applyConfig()
ui->lineHostname->setText(m_AppConfig.serverHostname()); ui->lineHostname->setText(m_AppConfig.serverHostname());
ui->lineClientIp->setText(m_ServerConfig.getClientAddress()); ui->lineClientIp->setText(m_ServerConfig.getClientAddress());
updateLocalFingerprint(); updateLocalFingerprint();
setIcon();
} }
void MainWindow::saveSettings() void MainWindow::saveSettings()
@ -687,12 +686,16 @@ void MainWindow::saveSettings()
void MainWindow::setIcon() void MainWindow::setIcon()
{ {
QIcon icon;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
icon.addFile(kDarkIconFile); QIcon icon;
icon.setIsMask(true); if (appConfig().colorfulTrayIcon())
icon.addFile(kColorfulIconFile);
else {
icon.addFile(kDarkIconFile);
icon.setIsMask(true);
}
#else #else
QIcon icon(kIconFile); QIcon icon(appConfig().colorfulTrayIcon() ? kColorfulIconFile : isDarkMode() ? kDarkIconFile : kLightIconFile);
#endif #endif
m_trayIcon->setIcon(icon); m_trayIcon->setIcon(icon);
} }

View file

@ -21,6 +21,7 @@
#include "gui/core/CoreProcess.h" #include "gui/core/CoreProcess.h"
#include "gui/messages.h" #include "gui/messages.h"
#include "gui/style_utils.h"
#include "gui/tls/TlsCertificate.h" #include "gui/tls/TlsCertificate.h"
#include "gui/tls/TlsUtility.h" #include "gui/tls/TlsUtility.h"
#include "gui/validators/ScreenNameValidator.h" #include "gui/validators/ScreenNameValidator.h"
@ -197,6 +198,7 @@ void SettingsDialog::accept()
m_appConfig.setEnableService(ui->m_pCheckBoxServiceEnabled->isChecked()); m_appConfig.setEnableService(ui->m_pCheckBoxServiceEnabled->isChecked());
m_appConfig.setCloseToTray(ui->m_pCheckBoxCloseToTray->isChecked()); m_appConfig.setCloseToTray(ui->m_pCheckBoxCloseToTray->isChecked());
m_appConfig.setInvertConnection(ui->m_pInvertConnection->isChecked()); m_appConfig.setInvertConnection(ui->m_pInvertConnection->isChecked());
m_appConfig.setColorfulTrayIcon(ui->rb_icon_colorful->isChecked());
QDialog::accept(); QDialog::accept();
} }
@ -242,6 +244,16 @@ void SettingsDialog::loadFromConfig()
ui->m_pInvertConnection->setChecked(m_appConfig.invertConnection()); ui->m_pInvertConnection->setChecked(m_appConfig.invertConnection());
if (m_appConfig.colorfulTrayIcon())
ui->rb_icon_colorful->setChecked(true);
else
ui->rb_icon_mono->setChecked(true);
ui->rb_icon_mono->setIcon(
isDarkMode() ? QIcon(QStringLiteral(":/icons/128x128/tray-dark.png"))
: QIcon(QStringLiteral(":/icons/128x128/tray-light.png"))
);
updateTlsControls(); updateTlsControls();
} }

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>550</width> <width>550</width>
<height>625</height> <height>652</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -160,6 +160,39 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Tray icon style</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rb_icon_colorful">
<property name="text">
<string>Colorful</string>
</property>
<property name="icon">
<iconset resource="../../res/deskflow.qrc">
<normaloff>:/icons/128x128/tray.png</normaloff>:/icons/128x128/tray.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rb_icon_mono">
<property name="text">
<string>Monocolor</string>
</property>
<property name="icon">
<iconset resource="../../res/deskflow.qrc">
<normaloff>:/icons/128x128/tray-dark.png</normaloff>:/icons/128x128/tray-dark.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -761,7 +794,9 @@
<tabstop>m_pRadioSystemScope</tabstop> <tabstop>m_pRadioSystemScope</tabstop>
<tabstop>m_pComboElevate</tabstop> <tabstop>m_pComboElevate</tabstop>
</tabstops> </tabstops>
<resources/> <resources>
<include location="../../res/deskflow.qrc"/>
</resources>
<connections> <connections>
<connection> <connection>
<sender>m_pButtonBox</sender> <sender>m_pButtonBox</sender>

View file

@ -592,6 +592,11 @@ bool AppConfig::logExpanded() const
return m_logExpanded; return m_logExpanded;
} }
bool AppConfig::colorfulTrayIcon() const
{
return m_colorfulTrayIcon;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// End getters // End getters
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -772,6 +777,13 @@ void AppConfig::setLogExpanded(bool expanded)
m_logExpanded = expanded; m_logExpanded = expanded;
} }
void AppConfig::setColorfulTrayIcon(bool colorful)
{
if (colorful == m_colorfulTrayIcon)
return;
m_colorfulTrayIcon = colorful;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// End setters // End setters
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View file

@ -110,6 +110,7 @@ private:
kShowCloseReminder = 42, kShowCloseReminder = 42,
kEnableUpdateCheck = 43, kEnableUpdateCheck = 43,
kLogExpanded = 44, kLogExpanded = 44,
kColorIcon = 45
}; };
public: public:
@ -185,6 +186,7 @@ public:
bool showCloseReminder() const; bool showCloseReminder() const;
std::optional<bool> enableUpdateCheck() const; std::optional<bool> enableUpdateCheck() const;
bool logExpanded() const; bool logExpanded() const;
bool colorfulTrayIcon() const;
// //
// Setters (overrides) // Setters (overrides)
@ -226,6 +228,7 @@ public:
void setShowCloseReminder(bool show); void setShowCloseReminder(bool show);
void setEnableUpdateCheck(bool value); void setEnableUpdateCheck(bool value);
void setLogExpanded(bool expanded); void setLogExpanded(bool expanded);
void setColorfulTrayIcon(bool color);
/// @brief Sets the user preference to load from SystemScope. /// @brief Sets the user preference to load from SystemScope.
/// @param [in] value /// @param [in] value
@ -332,6 +335,7 @@ private:
bool m_ShowCloseReminder = true; bool m_ShowCloseReminder = true;
std::optional<bool> m_EnableUpdateCheck; std::optional<bool> m_EnableUpdateCheck;
bool m_logExpanded = true; bool m_logExpanded = true;
bool m_colorfulTrayIcon = false;
/** /**
* @brief Flag is set when any TLS is setting is changed, and is reset * @brief Flag is set when any TLS is setting is changed, and is reset