From c3a302254693cec0ecd5fe173b3c9eb2145ea597 Mon Sep 17 00:00:00 2001
From: Xiao Pan <gky44px1999@gmail.com>
Date: Sat, 4 Feb 2023 14:38:26 -0800
Subject: use arch wiki example to fix issue of need nmcli wifi on when unplug
 ethernet cable after poweroff

---
 .../dispatcher.d/70-wifi-wired-exclusive           | 27 +++++++++++-----------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive b/etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive
index 79e18eb2..a0f0c4c8 100755
--- a/etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive
+++ b/etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive
@@ -1,17 +1,16 @@
 #!/bin/sh
 
-# code modified from:
-# `man nmcli-examples` and Copyright 2012 Johannes Buchner <buchner.johannes@gmx.at> Copyright 2012 - 2014 Red Hat, Inc.
+# https://wiki.archlinux.org/title/NetworkManager#Use_dispatcher_to_automatically_toggle_wireless_depending_on_LAN_cable_being_plugged_in
 
-enable_disable_wifi ()
-{
-	if nmcli -t --fields type,state device | grep -q 'ethernet:connected'; then
-		nmcli radio wifi off
-	else
-		nmcli radio wifi on
-	fi
-}
-
-case "$2" in
-	up|down) enable_disable_wifi;;
-esac
+if [ "$1" = "enp3s0" ]; then
+	case "$2" in
+		up)
+			nmcli radio wifi off
+			;;
+		down)
+			nmcli radio wifi on
+			;;
+	esac
+elif [ "$(nmcli -g GENERAL.STATE device show enp3s0)" = "20 (unavailable)" ]; then
+	nmcli radio wifi on
+fi
-- 
cgit v1.2.3-70-g09d2