Don't show Hotspot config on devices without wifi.

This commit is contained in:
Robin E. R. Davies
2024-11-14 21:05:11 -05:00
parent 04181958a1
commit 301cd6a60a
7 changed files with 106 additions and 74 deletions
+31
View File
@@ -33,6 +33,7 @@
using namespace pipedal;
using namespace dbus::networkmanager;
namespace fs = std::filesystem;
namespace pipedal::impl
{
@@ -1032,3 +1033,33 @@ std::vector<std::string> HotspotManagerImpl::GetKnownWifiNetworks()
std::lock_guard lock(knownWifiNetworksMutex); // pushed off the service thread.
return this->knownWifiNetworks;
}
static bool is_wireless_sysfs(const std::string& ifname) {
return fs::exists("/sys/class/net/" + ifname + "/wireless");
}
static std::vector<std::string> get_wireless_interfaces_sysfs() {
std::vector<std::string> wireless_interfaces;
const std::string net_path = "/sys/class/net";
try {
for (const auto& entry : fs::directory_iterator(net_path)) {
std::string ifname = entry.path().filename();
if (is_wireless_sysfs(ifname)) {
wireless_interfaces.push_back(ifname);
}
}
} catch (const fs::filesystem_error& e) {
std::cerr << "Error accessing " << net_path << ": " << e.what() << std::endl;
}
return wireless_interfaces;
}
bool HotspotManager::HasWifiDevice()
{
// use procfs to decide this, as NetworkManager may not be available yet.
return !(get_wireless_interfaces_sysfs().empty());
}
+2
View File
@@ -38,6 +38,8 @@ namespace pipedal {
using ptr = std::unique_ptr<HotspotManager>;
static bool HasWifiDevice();
static ptr Create();
virtual ~HotspotManager() noexcept { }
+2
View File
@@ -33,6 +33,7 @@
#include "TemporaryFile.hpp"
#include "PresetBundle.hpp"
#include "json.hpp"
#include "HotspotManager.hpp"
#define OLD_PRESET_EXTENSION ".piPreset"
#define PRESET_EXTENSION ".piPreset"
@@ -701,6 +702,7 @@ public:
<< ", \"socket_server_address\": \"" << webSocketAddress
<< "\", \"ui_plugins\": [ ], \"max_upload_size\": " << maxUploadSize
<< ", \"enable_auto_update\": " << (ENABLE_AUTO_UPDATE ? " true" : "false")
<< ", \"has_wifi_device\": " << (HotspotManager::HasWifiDevice() ? " true": "false")
<< " }";
return s.str();