diff --git a/indicator/CMakeLists.txt b/indicator/CMakeLists.txt index 29565e9d0..8741d09e9 100644 --- a/indicator/CMakeLists.txt +++ b/indicator/CMakeLists.txt @@ -46,7 +46,8 @@ target_include_directories(kdeconnect-indicator PUBLIC ${CMAKE_CURRENT_SOURCE_DI target_link_libraries(kdeconnect-indicator Qt::Widgets KF5::CoreAddons KF5::I18n KF5::Notifications KF5::DBusAddons KF5::KCMUtils kdeconnectinterfaces kdeconnectcore kdeconnectversion) if (WIN32) - add_compile_definitions(QSYSTRAY) + target_link_libraries(kdeconnect-indicator windowsapp) + target_compile_features(kdeconnect-indicator PUBLIC cxx_std_17) endif() if (APPLE) diff --git a/indicator/indicatorhelper.cpp b/indicator/indicatorhelper.cpp index b4818fe5f..b32639ede 100644 --- a/indicator/indicatorhelper.cpp +++ b/indicator/indicatorhelper.cpp @@ -35,14 +35,7 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd) return 0; } -#ifdef QSYSTRAY -void IndicatorHelper::systrayIconHook(QSystemTrayIcon &systray) -{ - systray.setIcon(QIcon::fromTheme(QStringLiteral("kdeconnectindicatordark"))); -} -#else void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) { systray.setIconByName(QStringLiteral("kdeconnectindicatordark")); } -#endif diff --git a/indicator/indicatorhelper.h b/indicator/indicatorhelper.h index ec77ec4d0..f2817959d 100644 --- a/indicator/indicatorhelper.h +++ b/indicator/indicatorhelper.h @@ -10,7 +10,7 @@ #include #include -#ifdef QSYSTRAY +#ifdef Q_OS_WIN #include #else #include @@ -46,7 +46,7 @@ public: int daemonHook(QProcess &kdeconnectd); -#ifdef QSYSTRAY +#ifdef Q_OS_WIN void systrayIconHook(QSystemTrayIcon &systray); #else void systrayIconHook(KStatusNotifierItem &systray); diff --git a/indicator/indicatorhelper_mac.cpp b/indicator/indicatorhelper_mac.cpp index bcda3d5c8..ba046840a 100644 --- a/indicator/indicatorhelper_mac.cpp +++ b/indicator/indicatorhelper_mac.cpp @@ -142,12 +142,6 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd) return 0; } -#ifdef QSYSTRAY -void IndicatorHelper::systrayIconHook(QSystemTrayIcon &systray) -{ - Q_UNUSED(systray); -} -#else void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) { const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdeconnect-icons"), QStandardPaths::LocateDirectory); @@ -160,4 +154,3 @@ void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) qWarning() << "Fail to find indicator icon, continue anyway"; } } -#endif diff --git a/indicator/indicatorhelper_win.cpp b/indicator/indicatorhelper_win.cpp index 8bb097aab..bdf832a15 100644 --- a/indicator/indicatorhelper_win.cpp +++ b/indicator/indicatorhelper_win.cpp @@ -8,18 +8,25 @@ #include #include #include +#include #include #include #include +#include +#include + #include "indicator_debug.h" #include "indicatorhelper.h" +winrt::Windows::UI::ViewManagement::UISettings uiSettings; + IndicatorHelper::IndicatorHelper(const QUrl &indicatorUrl) : m_indicatorUrl(indicatorUrl) { + uiSettings = winrt::Windows::UI::ViewManagement::UISettings(); } IndicatorHelper::~IndicatorHelper() @@ -42,6 +49,13 @@ void IndicatorHelper::postInit() void IndicatorHelper::iconPathHook() { + // FIXME: This doesn't seem to be enough for QIcon::fromTheme to find the icons, so we still have to use the full path when setting the icon + const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("icons"), QStandardPaths::LocateDirectory); + if (!iconPath.isNull()) { + QStringList themeSearchPaths = QIcon::themeSearchPaths(); + themeSearchPaths << iconPath; + QIcon::setThemeSearchPaths(themeSearchPaths); + } } int IndicatorHelper::daemonHook(QProcess &kdeconnectd) @@ -50,17 +64,26 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd) return 0; } -#ifdef QSYSTRAY +void onThemeChanged(QSystemTrayIcon &systray) +{ + // Since this is a system tray icon, we care about the system theme and not the app theme + QSettings registry(QStringLiteral("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), QSettings::Registry64Format); + bool isLightTheme = registry.value(QStringLiteral("SystemUsesLightTheme")).toBool(); + if (isLightTheme) { + systray.setIcon(QIcon(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("icons/hicolor/scalable/apps/kdeconnectindicator.svg")))); + } else { + systray.setIcon(QIcon(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("icons/hicolor/scalable/apps/kdeconnectindicatordark.svg")))); + } +} + void IndicatorHelper::systrayIconHook(QSystemTrayIcon &systray) { - systray.setIcon(QIcon::fromTheme(QStringLiteral("kdeconnect-tray"))); + // Set a callback so we can detect changes to light/dark themes and manually call the callback once the first time + uiSettings.ColorValuesChanged([&systray](auto &&unused1, auto &&unused2) { + onThemeChanged(systray); + }); + onThemeChanged(systray); } -#else -void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) -{ - Q_UNUSED(systray); -} -#endif bool IndicatorHelper::terminateProcess(const QString &processName, const QUrl &indicatorUrl) const { diff --git a/indicator/main.cpp b/indicator/main.cpp index 738dd0d5d..eedd20a3f 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -13,7 +13,7 @@ #include #endif -#ifdef QSYSTRAY +#ifdef Q_OS_WIN #include #else #include @@ -146,7 +146,7 @@ int main(int argc, char **argv) // Run icon to add icon path (if necessary) helper.iconPathHook(); -#ifdef QSYSTRAY +#ifdef Q_OS_WIN QSystemTrayIcon systray; helper.systrayIconHook(systray); systray.setVisible(true);