WiFi: auto formattings (removed es6 syntax for split to not break qmlfmt)

This commit is contained in:
LemmyCook 2025-09-05 11:58:30 -04:00
parent de92c989f2
commit 0567da94dd
2 changed files with 114 additions and 84 deletions

View file

@ -139,7 +139,8 @@ NPanel {
ColumnLayout { ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
visible: Settings.data.network.wifiEnabled && NetworkService.isLoading && Object.keys(NetworkService.networks).length === 0 visible: Settings.data.network.wifiEnabled && NetworkService.isLoading && Object.keys(
NetworkService.networks).length === 0
spacing: Style.marginM * scaling spacing: Style.marginM * scaling
NBusyIndicator { NBusyIndicator {
@ -193,13 +194,16 @@ NPanel {
// Network list // Network list
Repeater { Repeater {
model: { model: {
if (!Settings.data.network.wifiEnabled || NetworkService.isLoading) return [] if (!Settings.data.network.wifiEnabled || NetworkService.isLoading)
return []
// Sort networks: connected first, then by signal strength // Sort networks: connected first, then by signal strength
const nets = Object.values(NetworkService.networks) const nets = Object.values(NetworkService.networks)
return nets.sort((a, b) => { return nets.sort((a, b) => {
if (a.connected && !b.connected) return -1 if (a.connected && !b.connected)
if (!a.connected && b.connected) return 1 return -1
if (!a.connected && b.connected)
return 1
return b.signal - a.signal return b.signal - a.signal
}) })
} }
@ -213,7 +217,8 @@ NPanel {
width: parent.width width: parent.width
implicitHeight: networkContent.implicitHeight + (Style.marginM * scaling * 2) implicitHeight: networkContent.implicitHeight + (Style.marginM * scaling * 2)
radius: Style.radiusM * scaling radius: Style.radiusM * scaling
color: modelData.connected ? Qt.rgba(Color.mPrimary.r, Color.mPrimary.g, Color.mPrimary.b, 0.05) : Color.mSurface color: modelData.connected ? Qt.rgba(Color.mPrimary.r, Color.mPrimary.g, Color.mPrimary.b,
0.05) : Color.mSurface
border.width: Math.max(1, Style.borderS * scaling) border.width: Math.max(1, Style.borderS * scaling)
border.color: modelData.connected ? Color.mPrimary : Color.mOutline border.color: modelData.connected ? Color.mPrimary : Color.mOutline
clip: true clip: true
@ -254,7 +259,8 @@ NPanel {
NText { NText {
text: { text: {
const security = modelData.security && modelData.security !== "--" ? modelData.security : "Open" const security = modelData.security
&& modelData.security !== "--" ? modelData.security : "Open"
const signal = `${modelData.signal}%` const signal = `${modelData.signal}%`
return `${signal} ${security}` return `${signal} ${security}`
} }
@ -333,7 +339,8 @@ NPanel {
visible: !modelData.connected && (expandedNetwork !== modelData.ssid || !showPasswordPrompt) visible: !modelData.connected && (expandedNetwork !== modelData.ssid || !showPasswordPrompt)
outlined: !hovered outlined: !hovered
fontSize: Style.fontSizeXS * scaling fontSize: Style.fontSizeXS * scaling
text: modelData.existing ? "Connect" : (NetworkService.isSecured(modelData.security) ? "Password" : "Connect") text: modelData.existing ? "Connect" : (NetworkService.isSecured(
modelData.security) ? "Password" : "Connect")
icon: "wifi" icon: "wifi"
onClicked: { onClicked: {
if (modelData.existing || !NetworkService.isSecured(modelData.security)) { if (modelData.existing || !NetworkService.isSecured(modelData.security)) {
@ -447,12 +454,15 @@ NPanel {
// Forget network option - appears when saved badge is clicked // Forget network option - appears when saved badge is clicked
RowLayout { RowLayout {
visible: (modelData.existing || modelData.cached) && expandedNetwork === modelData.ssid && !showPasswordPrompt visible: (modelData.existing || modelData.cached) && expandedNetwork === modelData.ssid
&& !showPasswordPrompt
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: Style.marginXS * scaling Layout.topMargin: Style.marginXS * scaling
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
Item { Layout.fillWidth: true } Item {
Layout.fillWidth: true
}
NButton { NButton {
id: forgetButton id: forgetButton
@ -478,7 +488,8 @@ NPanel {
ColumnLayout { ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
visible: Settings.data.network.wifiEnabled && !NetworkService.isLoading && Object.keys(NetworkService.networks).length === 0 visible: Settings.data.network.wifiEnabled && !NetworkService.isLoading && Object.keys(
NetworkService.networks).length === 0
spacing: Style.marginM * scaling spacing: Style.marginM * scaling
NIcon { NIcon {

View file

@ -71,15 +71,23 @@ Singleton {
// Signal strength icon mapping // Signal strength icon mapping
function signalIcon(signal) { function signalIcon(signal) {
const levels = [ const levels = [{
{ threshold: 80, icon: "network_wifi" }, "threshold": 80,
{ threshold: 60, icon: "network_wifi_3_bar" }, "icon": "network_wifi"
{ threshold: 40, icon: "network_wifi_2_bar" }, }, {
{ threshold: 20, icon: "network_wifi_1_bar" } "threshold": 60,
] "icon": "network_wifi_3_bar"
}, {
"threshold": 40,
"icon": "network_wifi_2_bar"
}, {
"threshold": 20,
"icon": "network_wifi_1_bar"
}]
for (const level of levels) { for (const level of levels) {
if (signal >= level.threshold) return level.icon if (signal >= level.threshold)
return level.icon
} }
return "signal_wifi_0_bar" return "signal_wifi_0_bar"
} }
@ -90,7 +98,8 @@ Singleton {
// Enhanced refresh with retry logic // Enhanced refresh with retry logic
function refreshNetworks() { function refreshNetworks() {
if (isLoading) return if (isLoading)
return
isLoading = true isLoading = true
retryCount = 0 retryCount = 0
@ -391,9 +400,9 @@ Singleton {
// Update cache // Update cache
let known = adapter.knownNetworks let known = adapter.knownNetworks
known[ssid] = { known[ssid] = {
profileName: ssid, "profileName": ssid,
lastConnected: Date.now(), "lastConnected": Date.now(),
autoConnect: true "autoConnect": true
} }
adapter.knownNetworks = known adapter.knownNetworks = known
adapter.lastConnected = ssid adapter.lastConnected = ssid
@ -442,9 +451,14 @@ Singleton {
const lines = text.split("\n").filter(l => l.trim()) const lines = text.split("\n").filter(l => l.trim())
for (const line of lines) { for (const line of lines) {
const [name, type] = line.split(":") const parts = line.split(":")
const name = parts[0]
const type = parts[1]
if (name && type === "802-11-wireless") { if (name && type === "802-11-wireless") {
profiles[name] = { ssid: name, type: type } profiles[name] = {
"ssid": name,
"type": type
}
} }
} }
@ -476,10 +490,15 @@ Singleton {
for (const line of lines) { for (const line of lines) {
const parts = line.split(":") const parts = line.split(":")
if (parts.length < 4) continue if (parts.length < 4)
continue
const [ssid, security, signalStr, inUse] = parts const ssid = parts[0]
if (!ssid) continue const security = parts[1]
const signalStr = parts[2]
const inUse = parts[3]
if (!ssid)
continue
const signal = parseInt(signalStr) || 0 const signal = parseInt(signalStr) || 0
const connected = inUse === "*" const connected = inUse === "*"
@ -493,12 +512,12 @@ Singleton {
// Merge with existing or create new // Merge with existing or create new
if (!networksMap[ssid] || signal > networksMap[ssid].signal) { if (!networksMap[ssid] || signal > networksMap[ssid].signal) {
networksMap[ssid] = { networksMap[ssid] = {
ssid: ssid, "ssid": ssid,
security: security || "--", "security": security || "--",
signal: signal, "signal": signal,
connected: connected, "connected": connected,
existing: ssid in scanProcess.existingProfiles, "existing": ssid in scanProcess.existingProfiles,
cached: ssid in adapter.knownNetworks "cached": ssid in adapter.knownNetworks
} }
} }
} }