mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 00:12:50 -05:00
network: general improvements, itnegrate preference of wifi/ethernet
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import "."
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
@@ -11,10 +12,13 @@ Singleton {
|
||||
property string wifiSignalStrength: "excellent" // "excellent", "good", "fair", "poor"
|
||||
property var wifiNetworks: []
|
||||
property var savedWifiNetworks: []
|
||||
property bool isScanning: false
|
||||
property string connectionStatus: "" // "connecting", "connected", "failed", ""
|
||||
property string connectingSSID: ""
|
||||
|
||||
Process {
|
||||
id: currentWifiInfo
|
||||
command: ["bash", "-c", "nmcli -t -f ssid,signal connection show --active | grep -v '^--' | grep -v '^$'"]
|
||||
command: ["bash", "-c", "nmcli -t -f ACTIVE,SSID,SIGNAL dev wifi | grep '^yes' | head -1"]
|
||||
running: false
|
||||
|
||||
stdout: SplitParser {
|
||||
@@ -22,9 +26,9 @@ Singleton {
|
||||
onRead: (data) => {
|
||||
if (data.trim()) {
|
||||
let parts = data.split(":")
|
||||
if (parts.length >= 2 && parts[0].trim() !== "") {
|
||||
root.currentWifiSSID = parts[0].trim()
|
||||
let signal = parseInt(parts[1]) || 100
|
||||
if (parts.length >= 3 && parts[1].trim() !== "") {
|
||||
root.currentWifiSSID = parts[1].trim()
|
||||
let signal = parseInt(parts[2]) || 100
|
||||
|
||||
if (signal >= 75) root.wifiSignalStrength = "excellent"
|
||||
else if (signal >= 50) root.wifiSignalStrength = "good"
|
||||
@@ -58,11 +62,15 @@ Singleton {
|
||||
|
||||
// Skip duplicates
|
||||
if (!networks.find(n => n.ssid === ssid)) {
|
||||
// Check if this network is saved
|
||||
let isSaved = root.savedWifiNetworks.some(saved => saved.ssid === ssid)
|
||||
|
||||
networks.push({
|
||||
ssid: ssid,
|
||||
signal: signal,
|
||||
secured: security !== "",
|
||||
connected: ssid === root.currentWifiSSID,
|
||||
saved: isSaved,
|
||||
signalStrength: signal >= 75 ? "excellent" :
|
||||
signal >= 50 ? "good" :
|
||||
signal >= 25 ? "fair" : "poor"
|
||||
@@ -75,6 +83,12 @@ Singleton {
|
||||
networks.sort((a, b) => b.signal - a.signal)
|
||||
root.wifiNetworks = networks
|
||||
console.log("Found", networks.length, "WiFi networks")
|
||||
|
||||
// Stop scanning once we have results
|
||||
if (networks.length > 0) {
|
||||
root.isScanning = false
|
||||
fallbackTimer.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,9 +106,14 @@ Singleton {
|
||||
let lines = text.trim().split('\n')
|
||||
|
||||
for (let line of lines) {
|
||||
if (line.trim() && !line.includes("ethernet") && !line.includes("lo")) {
|
||||
let connectionName = line.trim()
|
||||
if (connectionName &&
|
||||
!connectionName.includes("ethernet") &&
|
||||
!connectionName.includes("lo") &&
|
||||
!connectionName.includes("Wired") &&
|
||||
!connectionName.toLowerCase().includes("eth")) {
|
||||
saved.push({
|
||||
ssid: line.trim(),
|
||||
ssid: connectionName,
|
||||
saved: true
|
||||
})
|
||||
}
|
||||
@@ -108,65 +127,144 @@ Singleton {
|
||||
}
|
||||
|
||||
function scanWifi() {
|
||||
if (root.isScanning) return
|
||||
|
||||
root.isScanning = true
|
||||
console.log("Starting WiFi scan...")
|
||||
|
||||
wifiScanner.running = true
|
||||
savedWifiScanner.running = true
|
||||
currentWifiInfo.running = true
|
||||
|
||||
// Fallback timer in case no networks are found
|
||||
fallbackTimer.start()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: fallbackTimer
|
||||
interval: 5000
|
||||
onTriggered: {
|
||||
root.isScanning = false
|
||||
console.log("WiFi scan timeout - no networks found")
|
||||
}
|
||||
}
|
||||
|
||||
function connectToWifi(ssid) {
|
||||
console.log("Connecting to WiFi:", ssid)
|
||||
|
||||
let connectProcess = Qt.createQmlObject('
|
||||
root.connectionStatus = "connecting"
|
||||
root.connectingSSID = ssid
|
||||
|
||||
let connectProcess = Qt.createQmlObject(`
|
||||
import Quickshell.Io
|
||||
Process {
|
||||
command: ["nmcli", "dev", "wifi", "connect", "' + ssid + '"]
|
||||
command: ["bash", "-c", "nmcli dev wifi connect \\"' + ssid + '\\" || nmcli connection up \\"' + ssid + '\\"; if [ $? -eq 0 ]; then nmcli connection modify \\"' + ssid + '\\" connection.autoconnect-priority 50; nmcli connection down \\"' + ssid + '\\"; nmcli connection up \\"' + ssid + '\\"; fi"]
|
||||
running: true
|
||||
onExited: (exitCode) => {
|
||||
console.log("WiFi connection result:", exitCode)
|
||||
if (exitCode === 0) {
|
||||
root.connectionStatus = "connected"
|
||||
console.log("Connected to WiFi successfully")
|
||||
// Set user preference to WiFi when manually connecting
|
||||
NetworkService.setNetworkPreference("wifi")
|
||||
// Force network status refresh after successful connection
|
||||
NetworkService.delayedRefreshNetworkStatus()
|
||||
} else {
|
||||
root.connectionStatus = "failed"
|
||||
console.log("WiFi connection failed")
|
||||
}
|
||||
scanWifi()
|
||||
|
||||
statusResetTimer.start()
|
||||
}
|
||||
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
console.log("WiFi connection stderr:", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
', root)
|
||||
`, root)
|
||||
}
|
||||
|
||||
function connectToWifiWithPassword(ssid, password) {
|
||||
console.log("Connecting to WiFi with password:", ssid)
|
||||
|
||||
let connectProcess = Qt.createQmlObject('
|
||||
root.connectionStatus = "connecting"
|
||||
root.connectingSSID = ssid
|
||||
|
||||
let connectProcess = Qt.createQmlObject(`
|
||||
import Quickshell.Io
|
||||
Process {
|
||||
command: ["nmcli", "dev", "wifi", "connect", "' + ssid + '", "password", "' + password + '"]
|
||||
command: ["bash", "-c", "nmcli dev wifi connect \\"' + ssid + '\\" password \\"' + password + '\\"; if [ $? -eq 0 ]; then nmcli connection modify \\"' + ssid + '\\" connection.autoconnect-priority 50; nmcli connection down \\"' + ssid + '\\"; nmcli connection up \\"' + ssid + '\\"; fi"]
|
||||
running: true
|
||||
onExited: (exitCode) => {
|
||||
console.log("WiFi connection with password result:", exitCode)
|
||||
if (exitCode === 0) {
|
||||
root.connectionStatus = "connected"
|
||||
console.log("Connected to WiFi with password successfully")
|
||||
// Set user preference to WiFi when manually connecting
|
||||
NetworkService.setNetworkPreference("wifi")
|
||||
// Force network status refresh after successful connection
|
||||
NetworkService.delayedRefreshNetworkStatus()
|
||||
} else {
|
||||
root.connectionStatus = "failed"
|
||||
console.log("WiFi connection with password failed")
|
||||
}
|
||||
scanWifi()
|
||||
|
||||
statusResetTimer.start()
|
||||
}
|
||||
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
console.log("WiFi connection with password stderr:", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
', root)
|
||||
`, root)
|
||||
}
|
||||
|
||||
function forgetWifiNetwork(ssid) {
|
||||
console.log("Forgetting WiFi network:", ssid)
|
||||
let forgetProcess = Qt.createQmlObject('
|
||||
let forgetProcess = Qt.createQmlObject(`
|
||||
import Quickshell.Io
|
||||
Process {
|
||||
command: ["nmcli", "connection", "delete", "' + ssid + '"]
|
||||
command: ["bash", "-c", "nmcli connection delete \\"' + ssid + '\\" || nmcli connection delete id \\"' + ssid + '\\""]
|
||||
running: true
|
||||
onExited: (exitCode) => {
|
||||
console.log("WiFi forget result:", exitCode)
|
||||
if (exitCode === 0) {
|
||||
console.log("Successfully forgot WiFi network:", "' + ssid + '")
|
||||
} else {
|
||||
console.log("Failed to forget WiFi network:", "' + ssid + '")
|
||||
}
|
||||
scanWifi()
|
||||
}
|
||||
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
console.log("WiFi forget stderr:", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
', root)
|
||||
`, root)
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: statusResetTimer
|
||||
interval: 3000
|
||||
onTriggered: {
|
||||
root.connectionStatus = ""
|
||||
root.connectingSSID = ""
|
||||
}
|
||||
}
|
||||
|
||||
function updateCurrentWifiInfo() {
|
||||
console.log("Updating current WiFi info...")
|
||||
currentWifiInfo.running = true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user