mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-08 22:45:38 -05:00
qmlformat-all script
This commit is contained in:
@@ -7,7 +7,7 @@ import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
|
||||
property string currentWifiSSID: ""
|
||||
property string wifiSignalStrength: "excellent" // "excellent", "good", "fair", "poor"
|
||||
property var wifiNetworks: []
|
||||
@@ -15,146 +15,26 @@ Singleton {
|
||||
property bool isScanning: false
|
||||
property string connectionStatus: "" // "cosnnecting", "connected", "failed", ""
|
||||
property string connectingSSID: ""
|
||||
|
||||
Process {
|
||||
id: currentWifiInfo
|
||||
command: ["bash", "-c", "nmcli -t -f ACTIVE,SSID,SIGNAL dev wifi | grep '^yes' | head -1"]
|
||||
running: false
|
||||
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: (data) => {
|
||||
if (data.trim()) {
|
||||
let parts = data.split(":")
|
||||
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"
|
||||
else if (signal >= 25) root.wifiSignalStrength = "fair"
|
||||
else root.wifiSignalStrength = "poor"
|
||||
|
||||
console.log("Active WiFi:", root.currentWifiSSID, "Signal:", signal + "%")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: wifiScanner
|
||||
command: ["nmcli", "-t", "-f", "SSID,SIGNAL,SECURITY", "dev", "wifi"]
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
if (text.trim()) {
|
||||
let networks = []
|
||||
let lines = text.trim().split('\n')
|
||||
|
||||
for (let line of lines) {
|
||||
let parts = line.split(':')
|
||||
if (parts.length >= 3 && parts[0].trim() !== "") {
|
||||
let ssid = parts[0].trim()
|
||||
let signal = parseInt(parts[1]) || 0
|
||||
let security = parts[2].trim()
|
||||
|
||||
// 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"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by signal strength
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: savedWifiScanner
|
||||
command: ["nmcli", "-t", "-f", "NAME", "connection", "show"]
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
if (text.trim()) {
|
||||
let saved = []
|
||||
let lines = text.trim().split('\n')
|
||||
|
||||
for (let line of lines) {
|
||||
let connectionName = line.trim()
|
||||
if (connectionName &&
|
||||
!connectionName.includes("ethernet") &&
|
||||
!connectionName.includes("lo") &&
|
||||
!connectionName.includes("Wired") &&
|
||||
!connectionName.toLowerCase().includes("eth")) {
|
||||
saved.push({
|
||||
ssid: connectionName,
|
||||
saved: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
root.savedWifiNetworks = saved
|
||||
console.log("Found", saved.length, "saved WiFi networks")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-refresh timer for when control center is open
|
||||
property bool autoRefreshEnabled: false
|
||||
|
||||
function scanWifi() {
|
||||
if (root.isScanning) return
|
||||
|
||||
root.isScanning = true
|
||||
console.log("Starting WiFi scan...")
|
||||
|
||||
wifiScanner.running = true
|
||||
savedWifiScanner.running = true
|
||||
currentWifiInfo.running = true
|
||||
|
||||
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()
|
||||
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)
|
||||
|
||||
root.connectionStatus = "connecting"
|
||||
root.connectingSSID = ssid
|
||||
|
||||
console.log("Connecting to WiFi:", ssid);
|
||||
root.connectionStatus = "connecting";
|
||||
root.connectingSSID = ssid;
|
||||
let connectProcess = Qt.createQmlObject(`
|
||||
import Quickshell.Io
|
||||
Process {
|
||||
@@ -174,10 +54,10 @@ Singleton {
|
||||
console.log("WiFi connection failed")
|
||||
}
|
||||
scanWifi()
|
||||
|
||||
|
||||
statusResetTimer.start()
|
||||
}
|
||||
|
||||
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
@@ -185,15 +65,13 @@ Singleton {
|
||||
}
|
||||
}
|
||||
}
|
||||
`, root)
|
||||
`, root);
|
||||
}
|
||||
|
||||
|
||||
function connectToWifiWithPassword(ssid, password) {
|
||||
console.log("Connecting to WiFi with password:", ssid)
|
||||
|
||||
root.connectionStatus = "connecting"
|
||||
root.connectingSSID = ssid
|
||||
|
||||
console.log("Connecting to WiFi with password:", ssid);
|
||||
root.connectionStatus = "connecting";
|
||||
root.connectingSSID = ssid;
|
||||
let connectProcess = Qt.createQmlObject(`
|
||||
import Quickshell.Io
|
||||
Process {
|
||||
@@ -213,10 +91,10 @@ Singleton {
|
||||
console.log("WiFi connection with password failed")
|
||||
}
|
||||
scanWifi()
|
||||
|
||||
|
||||
statusResetTimer.start()
|
||||
}
|
||||
|
||||
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
@@ -224,11 +102,11 @@ Singleton {
|
||||
}
|
||||
}
|
||||
}
|
||||
`, root)
|
||||
`, root);
|
||||
}
|
||||
|
||||
|
||||
function forgetWifiNetwork(ssid) {
|
||||
console.log("Forgetting WiFi network:", ssid)
|
||||
console.log("Forgetting WiFi network:", ssid);
|
||||
let forgetProcess = Qt.createQmlObject(`
|
||||
import Quickshell.Io
|
||||
Process {
|
||||
@@ -243,7 +121,7 @@ Singleton {
|
||||
}
|
||||
scanWifi()
|
||||
}
|
||||
|
||||
|
||||
stderr: SplitParser {
|
||||
splitMarker: "\\n"
|
||||
onRead: (data) => {
|
||||
@@ -251,35 +129,156 @@ Singleton {
|
||||
}
|
||||
}
|
||||
}
|
||||
`, root)
|
||||
`, root);
|
||||
}
|
||||
|
||||
|
||||
function updateCurrentWifiInfo() {
|
||||
console.log("Updating current WiFi info...");
|
||||
currentWifiInfo.running = true;
|
||||
}
|
||||
|
||||
Process {
|
||||
id: currentWifiInfo
|
||||
|
||||
command: ["bash", "-c", "nmcli -t -f ACTIVE,SSID,SIGNAL dev wifi | grep '^yes' | head -1"]
|
||||
running: false
|
||||
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: (data) => {
|
||||
if (data.trim()) {
|
||||
let parts = data.split(":");
|
||||
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";
|
||||
else if (signal >= 25)
|
||||
root.wifiSignalStrength = "fair";
|
||||
else
|
||||
root.wifiSignalStrength = "poor";
|
||||
console.log("Active WiFi:", root.currentWifiSSID, "Signal:", signal + "%");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Process {
|
||||
id: wifiScanner
|
||||
|
||||
command: ["nmcli", "-t", "-f", "SSID,SIGNAL,SECURITY", "dev", "wifi"]
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
if (text.trim()) {
|
||||
let networks = [];
|
||||
let lines = text.trim().split('\n');
|
||||
for (let line of lines) {
|
||||
let parts = line.split(':');
|
||||
if (parts.length >= 3 && parts[0].trim() !== "") {
|
||||
let ssid = parts[0].trim();
|
||||
let signal = parseInt(parts[1]) || 0;
|
||||
let security = parts[2].trim();
|
||||
// Skip duplicates
|
||||
if (!networks.find((n) => {
|
||||
return n.ssid === ssid;
|
||||
})) {
|
||||
// Check if this network is saved
|
||||
let isSaved = root.savedWifiNetworks.some((saved) => {
|
||||
return 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"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort by signal strength
|
||||
networks.sort((a, b) => {
|
||||
return 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Process {
|
||||
id: savedWifiScanner
|
||||
|
||||
command: ["nmcli", "-t", "-f", "NAME", "connection", "show"]
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
if (text.trim()) {
|
||||
let saved = [];
|
||||
let lines = text.trim().split('\n');
|
||||
for (let line of lines) {
|
||||
let connectionName = line.trim();
|
||||
if (connectionName && !connectionName.includes("ethernet") && !connectionName.includes("lo") && !connectionName.includes("Wired") && !connectionName.toLowerCase().includes("eth"))
|
||||
saved.push({
|
||||
"ssid": connectionName,
|
||||
"saved": true
|
||||
});
|
||||
|
||||
}
|
||||
root.savedWifiNetworks = saved;
|
||||
console.log("Found", saved.length, "saved WiFi networks");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: statusResetTimer
|
||||
interval: 3000
|
||||
id: fallbackTimer
|
||||
|
||||
interval: 5000
|
||||
onTriggered: {
|
||||
root.connectionStatus = ""
|
||||
root.connectingSSID = ""
|
||||
root.isScanning = false;
|
||||
console.log("WiFi scan timeout - no networks found");
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-refresh timer for when control center is open
|
||||
property bool autoRefreshEnabled: false
|
||||
|
||||
|
||||
Timer {
|
||||
id: statusResetTimer
|
||||
|
||||
interval: 3000
|
||||
onTriggered: {
|
||||
root.connectionStatus = "";
|
||||
root.connectingSSID = "";
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: autoRefreshTimer
|
||||
|
||||
interval: 20000
|
||||
running: root.autoRefreshEnabled
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if (root.autoRefreshEnabled) {
|
||||
root.scanWifi()
|
||||
}
|
||||
if (root.autoRefreshEnabled)
|
||||
root.scanWifi();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function updateCurrentWifiInfo() {
|
||||
console.log("Updating current WiFi info...")
|
||||
currentWifiInfo.running = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user