--amend
This commit is contained in:
parent
b9c1a8a54f
commit
507843be21
2 changed files with 213 additions and 233 deletions
|
|
@ -139,8 +139,7 @@ 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(
|
visible: Settings.data.network.wifiEnabled && NetworkService.isLoading && Object.keys(NetworkService.networks).length === 0
|
||||||
NetworkService.networks).length === 0
|
|
||||||
spacing: Style.marginM * scaling
|
spacing: Style.marginM * scaling
|
||||||
|
|
||||||
NBusyIndicator {
|
NBusyIndicator {
|
||||||
|
|
@ -194,18 +193,15 @@ NPanel {
|
||||||
// Network list
|
// Network list
|
||||||
Repeater {
|
Repeater {
|
||||||
model: {
|
model: {
|
||||||
if (!Settings.data.network.wifiEnabled || NetworkService.isLoading)
|
if (!Settings.data.network.wifiEnabled || NetworkService.isLoading) return []
|
||||||
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)
|
if (a.connected && !b.connected) return -1
|
||||||
return -1
|
if (!a.connected && b.connected) return 1
|
||||||
if (!a.connected && b.connected)
|
return b.signal - a.signal
|
||||||
return 1
|
})
|
||||||
return b.signal - a.signal
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
|
@ -217,8 +213,7 @@ 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,
|
color: modelData.connected ? Qt.rgba(Color.mPrimary.r, Color.mPrimary.g, Color.mPrimary.b, 0.05) : Color.mSurface
|
||||||
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
|
||||||
|
|
@ -259,8 +254,7 @@ NPanel {
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
text: {
|
text: {
|
||||||
const security = modelData.security
|
const security = modelData.security && modelData.security !== "--" ? modelData.security : "Open"
|
||||||
&& modelData.security !== "--" ? modelData.security : "Open"
|
|
||||||
const signal = `${modelData.signal}%`
|
const signal = `${modelData.signal}%`
|
||||||
return `${signal} • ${security}`
|
return `${signal} • ${security}`
|
||||||
}
|
}
|
||||||
|
|
@ -282,7 +276,7 @@ NPanel {
|
||||||
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||||
spacing: Style.marginS * scaling
|
spacing: Style.marginS * scaling
|
||||||
|
|
||||||
// Status badges
|
// Connected badge
|
||||||
Rectangle {
|
Rectangle {
|
||||||
visible: modelData.connected
|
visible: modelData.connected
|
||||||
color: Color.mPrimary
|
color: Color.mPrimary
|
||||||
|
|
@ -299,6 +293,7 @@ NPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saved badge - clickable
|
||||||
Rectangle {
|
Rectangle {
|
||||||
visible: modelData.cached && !modelData.connected
|
visible: modelData.cached && !modelData.connected
|
||||||
color: Color.mSurfaceVariant
|
color: Color.mSurfaceVariant
|
||||||
|
|
@ -308,6 +303,18 @@ NPanel {
|
||||||
border.color: Color.mOutline
|
border.color: Color.mOutline
|
||||||
border.width: Math.max(1, Style.borderS * scaling)
|
border.width: Math.max(1, Style.borderS * scaling)
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
hoverEnabled: true
|
||||||
|
onEntered: parent.color = Qt.darker(Color.mSurfaceVariant, 1.1)
|
||||||
|
onExited: parent.color = Color.mSurfaceVariant
|
||||||
|
onClicked: {
|
||||||
|
expandedNetwork = expandedNetwork === modelData.ssid ? "" : modelData.ssid
|
||||||
|
showPasswordPrompt = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
id: savedLabel
|
id: savedLabel
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
@ -317,17 +324,6 @@ NPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NIconButton {
|
|
||||||
visible: modelData.existing || modelData.cached
|
|
||||||
icon: "more_vert"
|
|
||||||
tooltipText: "Options"
|
|
||||||
sizeRatio: 0.7
|
|
||||||
onClicked: {
|
|
||||||
expandedNetwork = expandedNetwork === modelData.ssid ? "" : modelData.ssid
|
|
||||||
showPasswordPrompt = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Action buttons
|
// Action buttons
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: Style.marginXS * scaling
|
spacing: Style.marginXS * scaling
|
||||||
|
|
@ -337,8 +333,7 @@ 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(
|
text: modelData.existing ? "Connect" : (NetworkService.isSecured(modelData.security) ? "Password" : "Connect")
|
||||||
modelData.security) ? "Password" : "Connect")
|
|
||||||
icon: "wifi"
|
icon: "wifi"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (modelData.existing || !NetworkService.isSecured(modelData.security)) {
|
if (modelData.existing || !NetworkService.isSecured(modelData.security)) {
|
||||||
|
|
@ -389,8 +384,12 @@ NPanel {
|
||||||
|
|
||||||
TextInput {
|
TextInput {
|
||||||
id: passwordInputField
|
id: passwordInputField
|
||||||
anchors.fill: parent
|
anchors.left: parent.left
|
||||||
anchors.margins: Style.marginM * scaling
|
anchors.right: parent.right
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.leftMargin: Style.marginM * scaling
|
||||||
|
anchors.rightMargin: Style.marginM * scaling
|
||||||
|
height: parent.height - (Style.marginS * scaling * 2)
|
||||||
text: passwordInput
|
text: passwordInput
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
font.pointSize: Style.fontSizeS * scaling
|
||||||
color: Color.mOnSurface
|
color: Color.mOnSurface
|
||||||
|
|
@ -423,6 +422,7 @@ NPanel {
|
||||||
icon: "check"
|
icon: "check"
|
||||||
fontSize: Style.fontSizeXS * scaling
|
fontSize: Style.fontSizeXS * scaling
|
||||||
enabled: passwordInput.length > 0
|
enabled: passwordInput.length > 0
|
||||||
|
outlined: !enabled
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (passwordInput) {
|
if (passwordInput) {
|
||||||
NetworkService.submitPassword(passwordPromptSsid, passwordInput)
|
NetworkService.submitPassword(passwordPromptSsid, passwordInput)
|
||||||
|
|
@ -435,7 +435,7 @@ NPanel {
|
||||||
NIconButton {
|
NIconButton {
|
||||||
icon: "close"
|
icon: "close"
|
||||||
tooltipText: "Cancel"
|
tooltipText: "Cancel"
|
||||||
sizeRatio: 0.7
|
sizeRatio: 0.9
|
||||||
onClicked: {
|
onClicked: {
|
||||||
showPasswordPrompt = false
|
showPasswordPrompt = false
|
||||||
expandedNetwork = ""
|
expandedNetwork = ""
|
||||||
|
|
@ -445,31 +445,27 @@ NPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options menu (forget network)
|
// Forget network option - appears when saved badge is clicked
|
||||||
Rectangle {
|
RowLayout {
|
||||||
visible: expandedNetwork === modelData.ssid && !showPasswordPrompt && (modelData.existing
|
visible: (modelData.existing || modelData.cached) && expandedNetwork === modelData.ssid && !showPasswordPrompt
|
||||||
|| modelData.cached)
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
implicitHeight: visible ? 40 * scaling : 0
|
Layout.topMargin: Style.marginXS * scaling
|
||||||
color: Color.mSurfaceVariant
|
spacing: Style.marginS * scaling
|
||||||
radius: Style.radiusS * scaling
|
|
||||||
|
|
||||||
RowLayout {
|
Item { Layout.fillWidth: true }
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Style.marginS * scaling
|
|
||||||
spacing: Style.marginM * scaling
|
|
||||||
|
|
||||||
NButton {
|
NButton {
|
||||||
Layout.fillWidth: true
|
id: forgetButton
|
||||||
text: "Forget Network"
|
text: "Forget Network"
|
||||||
icon: "delete"
|
icon: "delete_outline"
|
||||||
fontSize: Style.fontSizeXS * scaling
|
fontSize: Style.fontSizeXXS * scaling
|
||||||
backgroundColor: Color.mError
|
backgroundColor: Color.mError
|
||||||
outlined: !hovered
|
textColor: !forgetButton.hovered ? Color.mError : Color.mOnTertiary
|
||||||
onClicked: {
|
outlined: !forgetButton.hovered
|
||||||
NetworkService.forgetNetwork(modelData.ssid)
|
Layout.preferredHeight: 28 * scaling
|
||||||
expandedNetwork = ""
|
onClicked: {
|
||||||
}
|
NetworkService.forgetNetwork(modelData.ssid)
|
||||||
|
expandedNetwork = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -482,8 +478,7 @@ 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(
|
visible: Settings.data.network.wifiEnabled && !NetworkService.isLoading && Object.keys(NetworkService.networks).length === 0
|
||||||
NetworkService.networks).length === 0
|
|
||||||
spacing: Style.marginM * scaling
|
spacing: Style.marginM * scaling
|
||||||
|
|
||||||
NIcon {
|
NIcon {
|
||||||
|
|
@ -511,4 +506,4 @@ NPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ Singleton {
|
||||||
property bool ethernet: false
|
property bool ethernet: false
|
||||||
property int retryCount: 0
|
property int retryCount: 0
|
||||||
property int maxRetries: 3
|
property int maxRetries: 3
|
||||||
|
|
||||||
// File path for persistent storage
|
// File path for persistent storage
|
||||||
property string cacheFile: Settings.cacheDir + "network.json"
|
property string cacheFile: Settings.cacheDir + "network.json"
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ Singleton {
|
||||||
autoConnectTimer.start()
|
autoConnectTimer.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onLoadFailed: function (error) {
|
onLoadFailed: function(error) {
|
||||||
Logger.log("Network", "No existing cache found, creating new one")
|
Logger.log("Network", "No existing cache found, creating new one")
|
||||||
// Initialize with empty data
|
// Initialize with empty data
|
||||||
adapter.knownNetworks = ({})
|
adapter.knownNetworks = ({})
|
||||||
|
|
@ -63,7 +63,7 @@ Singleton {
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
Logger.log("Network", "Service started")
|
Logger.log("Network", "Service started")
|
||||||
|
|
||||||
if (Settings.data.network.wifiEnabled) {
|
if (Settings.data.network.wifiEnabled) {
|
||||||
refreshNetworks()
|
refreshNetworks()
|
||||||
}
|
}
|
||||||
|
|
@ -71,23 +71,15 @@ Singleton {
|
||||||
|
|
||||||
// Signal strength icon mapping
|
// Signal strength icon mapping
|
||||||
function signalIcon(signal) {
|
function signalIcon(signal) {
|
||||||
const levels = [{
|
const levels = [
|
||||||
"threshold": 80,
|
{ threshold: 80, icon: "network_wifi" },
|
||||||
"icon": "network_wifi"
|
{ threshold: 60, icon: "network_wifi_3_bar" },
|
||||||
}, {
|
{ threshold: 40, icon: "network_wifi_2_bar" },
|
||||||
"threshold": 60,
|
{ threshold: 20, icon: "network_wifi_1_bar" }
|
||||||
"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)
|
if (signal >= level.threshold) return level.icon
|
||||||
return level.icon
|
|
||||||
}
|
}
|
||||||
return "signal_wifi_0_bar"
|
return "signal_wifi_0_bar"
|
||||||
}
|
}
|
||||||
|
|
@ -98,9 +90,8 @@ Singleton {
|
||||||
|
|
||||||
// Enhanced refresh with retry logic
|
// Enhanced refresh with retry logic
|
||||||
function refreshNetworks() {
|
function refreshNetworks() {
|
||||||
if (isLoading)
|
if (isLoading) return
|
||||||
return
|
|
||||||
|
|
||||||
isLoading = true
|
isLoading = true
|
||||||
retryCount = 0
|
retryCount = 0
|
||||||
adapter.lastRefresh = Date.now()
|
adapter.lastRefresh = Date.now()
|
||||||
|
|
@ -146,20 +137,20 @@ Singleton {
|
||||||
// Forget network function
|
// Forget network function
|
||||||
function forgetNetwork(ssid) {
|
function forgetNetwork(ssid) {
|
||||||
Logger.log("Network", `Forgetting network: ${ssid}`)
|
Logger.log("Network", `Forgetting network: ${ssid}`)
|
||||||
|
|
||||||
// Remove from cache
|
// Remove from cache
|
||||||
let known = adapter.knownNetworks
|
let known = adapter.knownNetworks
|
||||||
delete known[ssid]
|
delete known[ssid]
|
||||||
adapter.knownNetworks = known
|
adapter.knownNetworks = known
|
||||||
|
|
||||||
// Clear last connected if it's this network
|
// Clear last connected if it's this network
|
||||||
if (adapter.lastConnected === ssid) {
|
if (adapter.lastConnected === ssid) {
|
||||||
adapter.lastConnected = ""
|
adapter.lastConnected = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save changes
|
// Save changes
|
||||||
saveTimer.restart()
|
saveTimer.restart()
|
||||||
|
|
||||||
// Remove NetworkManager profile
|
// Remove NetworkManager profile
|
||||||
forgetProcess.ssid = ssid
|
forgetProcess.ssid = ssid
|
||||||
forgetProcess.running = true
|
forgetProcess.running = true
|
||||||
|
|
@ -170,14 +161,14 @@ Singleton {
|
||||||
property string ssid: ""
|
property string ssid: ""
|
||||||
running: false
|
running: false
|
||||||
command: ["nmcli", "connection", "delete", "id", ssid]
|
command: ["nmcli", "connection", "delete", "id", ssid]
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
Logger.log("Network", `Successfully forgot network: ${forgetProcess.ssid}`)
|
Logger.log("Network", `Successfully forgot network: ${forgetProcess.ssid}`)
|
||||||
refreshNetworks()
|
refreshNetworks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr: StdioCollector {
|
stderr: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
if (text.includes("no such connection profile")) {
|
if (text.includes("no such connection profile")) {
|
||||||
|
|
@ -206,7 +197,7 @@ Singleton {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wifiRadioProcess.action = "off"
|
wifiRadioProcess.action = "off"
|
||||||
wifiRadioProcess.running = true
|
wifiRadioProcess.running = true
|
||||||
}
|
}
|
||||||
|
|
@ -218,7 +209,7 @@ Singleton {
|
||||||
property string action: "on"
|
property string action: "on"
|
||||||
running: false
|
running: false
|
||||||
command: ["nmcli", "radio", "wifi", action]
|
command: ["nmcli", "radio", "wifi", action]
|
||||||
|
|
||||||
onRunningChanged: {
|
onRunningChanged: {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
if (action === "on") {
|
if (action === "on") {
|
||||||
|
|
@ -229,7 +220,7 @@ Singleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr: StdioCollector {
|
stderr: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
if (text.trim()) {
|
if (text.trim()) {
|
||||||
|
|
@ -268,26 +259,26 @@ Singleton {
|
||||||
connectStatus = ""
|
connectStatus = ""
|
||||||
connectStatusSsid = ssid
|
connectStatusSsid = ssid
|
||||||
connectError = ""
|
connectError = ""
|
||||||
|
|
||||||
// Check if profile exists
|
// Check if profile exists
|
||||||
if (networks[ssid]?.existing) {
|
if (networks[ssid]?.existing) {
|
||||||
connectToExisting(ssid)
|
connectToExisting(ssid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check cache for known network
|
// Check cache for known network
|
||||||
const known = adapter.knownNetworks[ssid]
|
const known = adapter.knownNetworks[ssid]
|
||||||
if (known?.profileName) {
|
if (known?.profileName) {
|
||||||
connectToExisting(known.profileName)
|
connectToExisting(known.profileName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// New connection - need password for secured networks
|
// New connection - need password for secured networks
|
||||||
if (isSecured(security)) {
|
if (isSecured(security)) {
|
||||||
// Password will be provided through submitPassword
|
// Password will be provided through submitPassword
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open network - connect directly
|
// Open network - connect directly
|
||||||
createAndConnect(ssid, "", security)
|
createAndConnect(ssid, "", security)
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +296,7 @@ Singleton {
|
||||||
|
|
||||||
function createAndConnect(ssid, password, security) {
|
function createAndConnect(ssid, password, security) {
|
||||||
connectingSsid = ssid
|
connectingSsid = ssid
|
||||||
|
|
||||||
connectProcess.ssid = ssid
|
connectProcess.ssid = ssid
|
||||||
connectProcess.password = password
|
connectProcess.password = password
|
||||||
connectProcess.isSecured = isSecured(security)
|
connectProcess.isSecured = isSecured(security)
|
||||||
|
|
@ -324,7 +315,7 @@ Singleton {
|
||||||
property string password: ""
|
property string password: ""
|
||||||
property bool isSecured: false
|
property bool isSecured: false
|
||||||
running: false
|
running: false
|
||||||
|
|
||||||
command: {
|
command: {
|
||||||
const cmd = ["nmcli", "device", "wifi", "connect", ssid]
|
const cmd = ["nmcli", "device", "wifi", "connect", ssid]
|
||||||
if (isSecured && password) {
|
if (isSecured && password) {
|
||||||
|
|
@ -332,13 +323,13 @@ Singleton {
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
handleConnectionSuccess(connectProcess.ssid)
|
handleConnectionSuccess(connectProcess.ssid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr: StdioCollector {
|
stderr: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
handleConnectionError(connectProcess.ssid, text)
|
handleConnectionError(connectProcess.ssid, text)
|
||||||
|
|
@ -351,13 +342,13 @@ Singleton {
|
||||||
property string profileName: ""
|
property string profileName: ""
|
||||||
running: false
|
running: false
|
||||||
command: ["nmcli", "connection", "up", "id", profileName]
|
command: ["nmcli", "connection", "up", "id", profileName]
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
handleConnectionSuccess(upConnectionProcess.profileName)
|
handleConnectionSuccess(upConnectionProcess.profileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr: StdioCollector {
|
stderr: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
handleConnectionError(upConnectionProcess.profileName, text)
|
handleConnectionError(upConnectionProcess.profileName, text)
|
||||||
|
|
@ -370,7 +361,7 @@ Singleton {
|
||||||
property string ssid: ""
|
property string ssid: ""
|
||||||
running: false
|
running: false
|
||||||
command: ["nmcli", "connection", "down", "id", ssid]
|
command: ["nmcli", "connection", "down", "id", ssid]
|
||||||
|
|
||||||
onRunningChanged: {
|
onRunningChanged: {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
connectingSsid = ""
|
connectingSsid = ""
|
||||||
|
|
@ -380,7 +371,7 @@ Singleton {
|
||||||
refreshNetworks()
|
refreshNetworks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr: StdioCollector {
|
stderr: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
if (text.trim()) {
|
if (text.trim()) {
|
||||||
|
|
@ -396,18 +387,18 @@ Singleton {
|
||||||
connectStatus = "success"
|
connectStatus = "success"
|
||||||
connectStatusSsid = ssid
|
connectStatusSsid = ssid
|
||||||
connectError = ""
|
connectError = ""
|
||||||
|
|
||||||
// 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
|
||||||
saveTimer.restart()
|
saveTimer.restart()
|
||||||
|
|
||||||
Logger.log("Network", `Successfully connected to ${ssid}`)
|
Logger.log("Network", `Successfully connected to ${ssid}`)
|
||||||
refreshNetworks()
|
refreshNetworks()
|
||||||
}
|
}
|
||||||
|
|
@ -417,7 +408,7 @@ Singleton {
|
||||||
connectStatus = "error"
|
connectStatus = "error"
|
||||||
connectStatusSsid = ssid
|
connectStatusSsid = ssid
|
||||||
connectError = parseError(error)
|
connectError = parseError(error)
|
||||||
|
|
||||||
Logger.warn("Network", `Failed to connect to ${ssid}: ${error}`)
|
Logger.warn("Network", `Failed to connect to ${ssid}: ${error}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,144 +435,138 @@ Singleton {
|
||||||
id: existingNetworkProcess
|
id: existingNetworkProcess
|
||||||
running: false
|
running: false
|
||||||
command: ["nmcli", "-t", "-f", "NAME,TYPE", "connection", "show"]
|
command: ["nmcli", "-t", "-f", "NAME,TYPE", "connection", "show"]
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
const profiles = {}
|
const profiles = {}
|
||||||
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 [ = line.split(":")
|
const [name, type] = line.split(":")
|
||||||
if (name && type === "802-11-wireless") {
|
if (name && type === "802-11-wireless") {
|
||||||
profiles[name] = {
|
profiles[name] = { ssid: name, type: type }
|
||||||
"ssid": name,
|
}
|
||||||
"type": type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scanProcess.existingProfiles = profiles
|
scanProcess.existingProfiles = profiles
|
||||||
scanProcess.running = true
|
scanProcess.running = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stderr: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
if (text.trim()) {
|
||||||
|
Logger.warn("Network", "Error listing connections:", text)
|
||||||
|
retryRefresh()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: scanProcess
|
||||||
|
property var existingProfiles: ({})
|
||||||
|
running: false
|
||||||
|
command: ["nmcli", "-t", "-f", "SSID,SECURITY,SIGNAL,IN-USE", "device", "wifi", "list"]
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
const networksMap = {}
|
||||||
|
const lines = text.split("\n").filter(l => l.trim())
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
const parts = line.split(":")
|
||||||
|
if (parts.length < 4) continue
|
||||||
|
|
||||||
|
const [ssid, security, signalStr, inUse] = parts
|
||||||
|
if (!ssid) continue
|
||||||
|
|
||||||
|
const signal = parseInt(signalStr) || 0
|
||||||
|
const connected = inUse === "*"
|
||||||
|
|
||||||
|
// Update last connected if we find the connected network
|
||||||
|
if (connected && adapter.lastConnected !== ssid) {
|
||||||
|
adapter.lastConnected = ssid
|
||||||
|
saveTimer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge with existing or create new
|
||||||
|
if (!networksMap[ssid] || signal > networksMap[ssid].signal) {
|
||||||
|
networksMap[ssid] = {
|
||||||
|
ssid: ssid,
|
||||||
|
security: security || "--",
|
||||||
|
signal: signal,
|
||||||
|
connected: connected,
|
||||||
|
existing: ssid in scanProcess.existingProfiles,
|
||||||
|
cached: ssid in adapter.knownNetworks
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr: StdioCollector {
|
root.networks = networksMap
|
||||||
onStreamFinished: {
|
root.isLoading = false
|
||||||
if (text.trim()) {
|
scanProcess.existingProfiles = {}
|
||||||
Logger.warn("Network", "Error listing connections:", text)
|
|
||||||
retryRefresh()
|
Logger.log("Network", `Found ${Object.keys(networksMap).length} networks`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
stderr: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
if (text.trim()) {
|
||||||
|
Logger.warn("Network", "Error scanning networks:", text)
|
||||||
|
retryRefresh()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: scanProcess
|
id: checkEthernet
|
||||||
property var existingProfiles: ({})
|
running: false
|
||||||
running: false
|
command: ["nmcli", "-t", "-f", "DEVICE,TYPE,STATE", "device"]
|
||||||
command: ["nmcli", "-t", "-f", "SSID,SECURITY,SIGNAL,IN-USE", "device", "wifi", "list"]
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
root.ethernet = text.split("\n").some(line => {
|
||||||
|
const parts = line.split(":")
|
||||||
|
return parts[1] === "ethernet" && parts[2] === "connected"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stdout: StdioCollector {
|
// Auto-refresh timer
|
||||||
onStreamFinished: {
|
Timer {
|
||||||
const networksMap = {}
|
interval: 30000 // 30 seconds
|
||||||
const lines = text.split("\n").filter(l => l.trim())
|
running: Settings.data.network.wifiEnabled && !isLoading
|
||||||
|
repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
// Only refresh if we should
|
||||||
|
const now = Date.now()
|
||||||
|
const timeSinceLastRefresh = now - adapter.lastRefresh
|
||||||
|
|
||||||
|
// Refresh if: connected, or it's been more than 30 seconds
|
||||||
|
if (hasActiveConnection || timeSinceLastRefresh > 30000) {
|
||||||
|
refreshNetworks()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const line of lines) {
|
property bool hasActiveConnection: {
|
||||||
const parts = line.split(":")
|
return Object.values(networks).some(net => net.connected)
|
||||||
if (parts.length < 4)
|
}
|
||||||
continue
|
|
||||||
|
|
||||||
const [ = parts
|
// Menu state management
|
||||||
if (!ssid)
|
function onMenuOpened() {
|
||||||
continue
|
if (Settings.data.network.wifiEnabled) {
|
||||||
|
refreshNetworks()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const signal = parseInt(signalStr) || 0
|
function onMenuClosed() {
|
||||||
const connected = inUse === "*"
|
// Clean up temporary states
|
||||||
|
connectStatus = ""
|
||||||
// Update last connected if we find the connected network
|
connectError = ""
|
||||||
if (connected && adapter.lastConnected !== ssid) {
|
}
|
||||||
adapter.lastConnected = ssid
|
}
|
||||||
saveTimer.restart()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge with existing or create new
|
|
||||||
if (!networksMap[ssid] || signal > networksMap[ssid].signal) {
|
|
||||||
networksMap[ssid] = {
|
|
||||||
"ssid": ssid,
|
|
||||||
"security": security || "--",
|
|
||||||
"signal": signal,
|
|
||||||
"connected": connected,
|
|
||||||
"existing": ssid in scanProcess.existingProfiles,
|
|
||||||
"cached": ssid in adapter.knownNetworks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
root.networks = networksMap
|
|
||||||
root.isLoading = false
|
|
||||||
scanProcess.existingProfiles = {}
|
|
||||||
|
|
||||||
Logger.log("Network", `Found ${Object.keys(networksMap).length} networks`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stderr: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
if (text.trim()) {
|
|
||||||
Logger.warn("Network", "Error scanning networks:", text)
|
|
||||||
retryRefresh()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: checkEthernet
|
|
||||||
running: false
|
|
||||||
command: ["nmcli", "-t", "-f", "DEVICE,TYPE,STATE", "device"]
|
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
root.ethernet = text.split("\n").some(line => {
|
|
||||||
const parts = line.split(":")
|
|
||||||
return parts[1] === "ethernet"
|
|
||||||
&& parts[2] === "connected"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-refresh timer
|
|
||||||
Timer {
|
|
||||||
interval: 30000 // 30 seconds
|
|
||||||
running: Settings.data.network.wifiEnabled && !isLoading
|
|
||||||
repeat: true
|
|
||||||
onTriggered: {
|
|
||||||
// Only refresh if we should
|
|
||||||
const now = Date.now()
|
|
||||||
const timeSinceLastRefresh = now - adapter.lastRefresh
|
|
||||||
|
|
||||||
// Refresh if: connected, or it's been more than 30 seconds
|
|
||||||
if (hasActiveConnection || timeSinceLastRefresh > 30000) {
|
|
||||||
refreshNetworks()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
property bool hasActiveConnection: {
|
|
||||||
return Object.values(networks).some(net => net.connected)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Menu state management
|
|
||||||
function onMenuOpened() {
|
|
||||||
if (Settings.data.network.wifiEnabled) {
|
|
||||||
refreshNetworks()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMenuClosed() {
|
|
||||||
// Clean up temporary states
|
|
||||||
connectStatus = ""
|
|
||||||
connectError = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue