diff --git a/debian/guppyconfig.json b/debian/guppyconfig.json index 194575c..713337e 100644 --- a/debian/guppyconfig.json +++ b/debian/guppyconfig.json @@ -11,7 +11,6 @@ }, "display_sleep_sec": 600, "fans": [], - "guppy_init_script": "service guppyscreen", "log_level": "debug", "monitored_sensors": [], "moonraker_api_key": false, @@ -19,6 +18,7 @@ "moonraker_port": 7125 } }, + "guppy_init_script": "service guppyscreen", "thumbnail_path": "/thumbnails", "wpa_supplicant": "/var/run/wpa_supplicant" } diff --git a/src/setting_panel.cpp b/src/setting_panel.cpp index c26892d..8a6384d 100644 --- a/src/setting_panel.cpp +++ b/src/setting_panel.cpp @@ -100,10 +100,10 @@ void SettingPanel::handle_callback(lv_event_t *event) { Config *conf = Config::get_instance(); auto init_script = conf->get("/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"); diff --git a/src/utils.cpp b/src/utils.cpp index 8a877cb..2d336f2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -171,6 +171,19 @@ namespace KUtils { return ip; } + std::string get_wifi_interface() { + std::string wpa_socket = Config::get_instance()->get("/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 void split(const std::string &s, char delim, Out result) { std::istringstream iss(s); diff --git a/src/utils.h b/src/utils.h index d9a154a..e16a745 100644 --- a/src/utils.h +++ b/src/utils.h @@ -24,6 +24,7 @@ namespace KUtils { std::vector get_interfaces(); std::string interface_ip(const std::string &interface); + std::string get_wifi_interface(); template void split(const std::string &s, char delim, Out result); diff --git a/src/wifi_panel.cpp b/src/wifi_panel.cpp index 69538dc..bac777e 100644 --- a/src/wifi_panel.cpp +++ b/src/wifi_panel.cpp @@ -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()); @@ -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()); @@ -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()); @@ -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);