Skip to content

Commit

Permalink
properly show wifi ip address in wifi panel. fixed guppy restart for …
Browse files Browse the repository at this point in the history
…systemd variants.
  • Loading branch information
ballaswag committed Apr 11, 2024
1 parent 8c29efe commit 4bfcfe8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion debian/guppyconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
},
"display_sleep_sec": 600,
"fans": [],
"guppy_init_script": "service guppyscreen",
"log_level": "debug",
"monitored_sensors": [],
"moonraker_api_key": false,
"moonraker_host": "127.0.0.1",
"moonraker_port": 7125
}
},
"guppy_init_script": "service guppyscreen",
"thumbnail_path": "<GUPPY_DIR>/thumbnails",
"wpa_supplicant": "/var/run/wpa_supplicant"
}
6 changes: 3 additions & 3 deletions src/setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ void SettingPanel::handle_callback(lv_event_t *event) {
Config *conf = Config::get_instance();
auto init_script = conf->get<std::string>("/guppy_init_script");
const fs::path script(init_script);
if (fs::exists(script)) {
sp::call({init_script, "restart"});
if (fs::exists(script) || init_script.rfind("service guppyscreen", 0) == 0) {
sp::call({init_script, "restart"});
} else {
spdlog::warn("Failed to restart Guppy Screen. Did not find restart script.");
spdlog::warn("Failed to restart Guppy Screen. Did not find restart script.");
}
} else if (btn == guppy_update_btn.get_container()) {
spdlog::trace("update guppy pressed");
Expand Down
13 changes: 13 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ namespace KUtils {
return ip;
}

std::string get_wifi_interface() {
std::string wpa_socket = Config::get_instance()->get<std::string>("/wpa_supplicant");
if (fs::is_directory(fs::status(wpa_socket))) {
for (const auto &e : fs::directory_iterator(wpa_socket)) {
if (fs::is_socket(e.path()) && e.path().string().find("p2p") == std::string::npos) {
return e.path().filename().string();
}
}
}

return "";
}

template <typename Out>
void split(const std::string &s, char delim, Out result) {
std::istringstream iss(s);
Expand Down
1 change: 1 addition & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace KUtils {

std::vector<std::string> get_interfaces();
std::string interface_ip(const std::string &interface);
std::string get_wifi_interface();

template <typename Out>
void split(const std::string &s, char delim, Out result);
Expand Down
10 changes: 5 additions & 5 deletions src/wifi_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void WifiPanel::handle_callback(lv_event_t *e) {

selected_network = lv_table_get_cell_value(wifi_table, row, 0);
if (cur_network.length() > 0 && cur_network == selected_network) {
auto ip = KUtils::interface_ip(Config::get_instance()->get_wifi_interface());
auto ip = KUtils::interface_ip(KUtils::get_wifi_interface());
lv_label_set_text(wifi_label, fmt::format("Connected to network {}\nIP: {}",
selected_network,
ip).c_str());
Expand Down Expand Up @@ -192,7 +192,7 @@ void WifiPanel::handle_wpa_event(const std::string &event) {
} else {
spdlog::trace("adding symbol with ok");
lv_table_set_cell_value(wifi_table, index, 1, LV_SYMBOL_OK " " LV_SYMBOL_WIFI);
auto ip = KUtils::interface_ip(Config::get_instance()->get_wifi_interface());
auto ip = KUtils::interface_ip(KUtils::get_wifi_interface());
lv_label_set_text(wifi_label, fmt::format("Connected to network {}\nIP: {}",
cur_network,
ip).c_str());
Expand Down Expand Up @@ -232,7 +232,7 @@ void WifiPanel::handle_wpa_event(const std::string &event) {
} else {
spdlog::trace("adding symbol with ok");
lv_table_set_cell_value(wifi_table, index, 1, LV_SYMBOL_OK " " LV_SYMBOL_WIFI);
auto ip = KUtils::interface_ip(Config::get_instance()->get_wifi_interface());
auto ip = KUtils::interface_ip(KUtils::get_wifi_interface());
lv_label_set_text(wifi_label, fmt::format("Connected to network {}\nIP: {}",
cur_network,
ip).c_str());
Expand All @@ -253,10 +253,10 @@ void WifiPanel::handle_kb_input(lv_event_t *e)
{
const lv_event_code_t code = lv_event_get_code(e);

if(code == LV_EVENT_FOCUSED) {
if (code == LV_EVENT_FOCUSED) {
lv_keyboard_set_textarea(kb, password_input);
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
} else if(code == LV_EVENT_DEFOCUSED) {
} else if (code == LV_EVENT_DEFOCUSED) {
lv_keyboard_set_textarea(kb, NULL);
lv_label_set_text(wifi_label, "Please select your wifi network");
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
Expand Down

0 comments on commit 4bfcfe8

Please sign in to comment.