From 18f3e123ed8e323b821fcbe8c44ca63011f8fd0c Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Tue, 4 Jul 2023 12:18:56 +0200 Subject: [PATCH] SNI: Allow IconPath to be empty Fixes network-manager-applet --- src/Common.h | 15 +++++++++++++++ src/SNI.cpp | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Common.h b/src/Common.h index 1aa3347..5c52237 100644 --- a/src/Common.h +++ b/src/Common.h @@ -2,6 +2,7 @@ #include #include #include +#include #include "Log.h" @@ -82,6 +83,20 @@ namespace Utils snprintf(buf, sizeof(buf), fmt, bytes, "B"); return buf; } + + inline std::string FindFileWithName(const std::string& directory, const std::string& name, const std::string& extension) + { + for (auto& path : std::filesystem::recursive_directory_iterator(directory)) + { + if (path.is_directory()) + continue; + if (path.path().filename().string().find(name) != std::string::npos && path.path().extension().string() == extension) + { + return path.path().string(); + } + } + return ""; + } } struct Process diff --git a/src/SNI.cpp b/src/SNI.cpp index e105eea..89fb808 100644 --- a/src/SNI.cpp +++ b/src/SNI.cpp @@ -2,6 +2,7 @@ #include "Log.h" #include "Widget.h" #include "Config.h" +#include "Common.h" #ifdef WITH_SNI @@ -136,7 +137,16 @@ namespace SNI const char* themePath = g_variant_get_string(themePathStr, nullptr); const char* iconName = g_variant_get_string(iconNameStr, nullptr); - iconPath = std::string(themePath) + "/" + iconName + ".png"; // TODO: Find out if this is always png + if (strlen(themePath) == 0) + { + // Nothing defined, look in /usr/share/icons + // network-manager-applet does this + iconPath = Utils::FindFileWithName("/usr/share/icons", iconName, ".png"); + } + else + { + iconPath = std::string(themePath) + "/" + iconName + ".png"; // TODO: Find out if this is always png + } g_variant_unref(themePathVariant); g_variant_unref(themePathStr);