Skip to content

Commit

Permalink
Net service store simplify & bugfix (#1592)
Browse files Browse the repository at this point in the history
Some things not working when building a fresh main & fixing a rando
blackscreen issue when disabling wifi & opening search...
  • Loading branch information
XK9274 authored May 20, 2024
1 parent 046c193 commit 761e050
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions static/build/.tmp_update/script/network/update_networking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ check() {
bootScreen Boot "Waiting for network..."
fi

# Check to see if mainui has demanded wifi go down
local current_main_ui_control=$(get_main_ui_control &)
local wifi_status=$(wifi_enabled && echo "1" || echo "0")

if [ "$wifi_status" != "$current_main_ui_control" ]; then
update_main_ui_control "$wifi_status" &
if [ "$wifi_status" = "1" ]; then
# Being turned on, restore the previous state of net servs
if [ $is_booting -eq 0 ]; then
restore_state
fi
fi
fi

check_wifi
check_ftpstate &
check_sshstate &
Expand Down Expand Up @@ -144,6 +130,7 @@ check_wifi() {
else
if wifi_enabled; then
if ! ifconfig wlan0 >> /dev/null 2>&1 || [ -f /tmp/restart_wifi ]; then
restore_state
if [ -f /tmp/restart_wifi ]; then
pkill -9 wpa_supplicant
pkill -9 udhcpc
Expand All @@ -159,6 +146,7 @@ check_wifi() {
fi
else
if [ ! -f "/tmp/dont_restart_wifi" ]; then
store_state
pkill -9 wpa_supplicant
pkill -9 udhcpc
/customer/app/axp_test wifioff
Expand Down Expand Up @@ -577,10 +565,6 @@ init_json() {
if [ ! -s "$jsonfile" ]; then
echo '{}' > "$jsonfile"
fi

if ! grep -q '"main_ui_control":' "$jsonfile"; then
sed -i 's/}$/,"main_ui_control": "0"}/' "$jsonfile"
fi
}

# unhook libpadsp.so on the wifi servs
Expand All @@ -602,23 +586,28 @@ libpadspblocker() {

# Store the network service state currently
store_state() {
# Make sure main_ui_control gets set at the start
local main_ui_control=$(get_main_ui_control)
local json_content="{\"main_ui_control\": \"$main_ui_control\""
service_key="{"
first_item=true

for service in $services; do
if [ "$first_item" = true ]; then
first_item=false
else
service_key="$service_key,"
fi

if [ -f "$sysdir/config/.$service" ]; then
json_content="$json_content, \"$service\": \"1\""
elif [ -f "$sysdir/config/.$service_" ]; then
json_content="$json_content, \"$service\": \"0\""
service_key="$service_key \"$service\": \"1\""
else
service_key="$service_key \"$service\": \"0\""
fi
done

# Echo the changes in, jq is too slow for this
json_content="$json_content }"
echo "$json_content" > "$jsonfile"
service_key="$service_key }"
echo "$service_key" > "$jsonfile"
}


# Restore the network service state, don't use jq it's too slow and holds the UI thread until it returns
# (you can't background this, you'll miss the checks for net servs as the flags won't be set)
restore_state() {
Expand Down Expand Up @@ -646,16 +635,6 @@ full_reset() {
rm -f "$jsonfile"
}

update_main_ui_control() {
control_status="$1"
sed -i'' -e "/\"main_ui_control\"/s/: \".*\"/: \"$control_status\"/" "$jsonfile"
}

get_main_ui_control() {
value=$(grep '"main_ui_control"' "$jsonfile" | sed -n 's/.*"main_ui_control": "\([^"]*\)".*/\1/p')
echo "${value:-0}"
}

convert_seconds_to_utc_offset() {
seconds=$(($1))
if [ $seconds -ne 0 ]; then
Expand Down Expand Up @@ -717,7 +696,7 @@ enable_flag() {

disable_flag() {
flag="$1"
rm "$sysdir/config/.$flag" /dev/null 2>&1
mv "$sysdir/config/.$flag" "$sysdir/config/.$flag_"
}

is_running() {
Expand Down

0 comments on commit 761e050

Please sign in to comment.