chore: move wifi process to a singleton
This commit is contained in:
parent
a6548c9c9b
commit
e50a21ebc5
13 changed files with 161 additions and 85 deletions
|
@ -35,7 +35,7 @@ BRectangle {
|
|||
|
||||
onWheel: wheel => {
|
||||
const newVal = audiow.sink.audio.volume + (wheel.angleDelta.y / 12000);
|
||||
sink.audio.volume = newVal < 1.0 ? (newVal > 0 ? newVal : 0.0) : 1.0;
|
||||
audiow.sink.audio.volume = newVal < 1.0 ? (newVal > 0 ? newVal : 0.0) : 1.0;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
|
|
|
@ -155,6 +155,7 @@ PanelWindow {
|
|||
id: internet
|
||||
BigWifiView {
|
||||
onNavigationReturn: stack.pop()
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,9 +53,15 @@ PanelWindow {
|
|||
|
||||
Battery {}
|
||||
|
||||
Network {}
|
||||
Network {
|
||||
width: parent.width
|
||||
height: parent.width
|
||||
}
|
||||
|
||||
Caffeine {}
|
||||
Caffeine {
|
||||
width: parent.width
|
||||
height: parent.width
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillHeight: true
|
||||
|
|
|
@ -5,10 +5,12 @@ import Quickshell
|
|||
|
||||
Singleton {
|
||||
id: inhibitor
|
||||
property var toggle: () => {
|
||||
|
||||
property bool active: false
|
||||
|
||||
function toggle() {
|
||||
active = !active;
|
||||
}
|
||||
property bool active: false
|
||||
|
||||
Process {
|
||||
running: inhibitor.active
|
||||
|
|
|
@ -41,6 +41,8 @@ Singleton {
|
|||
return day ? "weather-clear" : "weather-clear-night";
|
||||
case "116":
|
||||
return day ? "weather-few-clouds" : "weather-few-clouds-night";
|
||||
case "122":
|
||||
return "weather-overcast";
|
||||
default:
|
||||
return "weather-none-available";
|
||||
}
|
||||
|
|
63
src/provider/Wifi.qml
Normal file
63
src/provider/Wifi.qml
Normal file
|
@ -0,0 +1,63 @@
|
|||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
id: networks
|
||||
property list<var> list: []
|
||||
property list<string> lastBSSIDS: []
|
||||
|
||||
function refresh() {
|
||||
getter.running = true;
|
||||
}
|
||||
|
||||
signal added(network: var)
|
||||
|
||||
signal removed(network: var)
|
||||
|
||||
Process {
|
||||
id: getter
|
||||
command: ["nmcli", "-t", "device", "wifi"]
|
||||
running: true
|
||||
stdout: SplitParser {
|
||||
onRead: rawData => {
|
||||
rawData = rawData.replace(/\\:/g, ":").split(":");
|
||||
|
||||
const data = {
|
||||
connected: rawData[0] === "*",
|
||||
bssid: rawData.slice(1, 7).join(":").replace(),
|
||||
ssid: rawData[7],
|
||||
mode: rawData[8],
|
||||
channel: rawData[9],
|
||||
rate: rawData[10],
|
||||
signal: rawData[11],
|
||||
bars: rawData[12],
|
||||
security: rawData[13]
|
||||
};
|
||||
|
||||
const index = list.findIndex(e => e.bssid === data.bssid);
|
||||
if (0 <= index) {
|
||||
Object.assign(networks.list[index], data);
|
||||
}
|
||||
|
||||
networks.list.push(data);
|
||||
lastBSSIDS.push(data.bssid);
|
||||
if (data.connected) {
|
||||
console.log(data.ssid);
|
||||
}
|
||||
added(data);
|
||||
}
|
||||
}
|
||||
onExited: {
|
||||
networks.list.forEach((b, i) => {
|
||||
const found = networks.lastBSSIDS.find(e => e.bssid === b);
|
||||
|
||||
if (!found) {
|
||||
networks.list.splice(i, 1);
|
||||
removed(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
module Provider
|
||||
singleton Wifi 0.1 Wifi.qml
|
||||
singleton Config 0.1 Config.qml
|
||||
singleton NyshState 0.1 NyshState.qml
|
||||
singleton Player 0.1 Player.qml
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
import "../../base"
|
||||
import "../../provider"
|
||||
|
||||
import QtQuick
|
||||
import Quickshell.Widgets
|
||||
import Quickshell
|
||||
|
||||
BRectangle {
|
||||
BButton {
|
||||
id: caffeine
|
||||
|
||||
MouseArea {
|
||||
IconImage {
|
||||
anchors.fill: parent
|
||||
|
||||
IconImage {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 4
|
||||
source: Inhibitor.active ? "root:assets/eye-open.svg" : "root:assets/eye-closed.svg"
|
||||
}
|
||||
|
||||
onClicked: () => Inhibitor.toggle()
|
||||
anchors.margins: 4
|
||||
source: Inhibitor.active ? "root:assets/eye-open.svg" : "root:assets/eye-closed.svg"
|
||||
}
|
||||
|
||||
onClicked: () => Inhibitor.toggle()
|
||||
}
|
||||
|
|
|
@ -4,27 +4,23 @@ import Quickshell.Io
|
|||
import Quickshell.Widgets
|
||||
import Quickshell
|
||||
|
||||
BRectangle {
|
||||
MouseArea {
|
||||
BButton {
|
||||
IconImage {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 2
|
||||
source: Quickshell.iconPath("wifi-radar")
|
||||
}
|
||||
|
||||
IconImage {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 2
|
||||
source: Quickshell.iconPath("wifi-radar")
|
||||
}
|
||||
onClicked: () => {
|
||||
gui.running = !gui.running;
|
||||
}
|
||||
|
||||
onClicked: () => {
|
||||
gui.running = !gui.running;
|
||||
}
|
||||
|
||||
Process {
|
||||
id: gui
|
||||
running: false
|
||||
command: ["foot", "nmtui"]
|
||||
stdout: SplitParser {
|
||||
onRead: data => console.log(`line read: ${data}`)
|
||||
}
|
||||
Process {
|
||||
id: gui
|
||||
running: false
|
||||
command: ["foot", "nmtui"]
|
||||
stdout: SplitParser {
|
||||
onRead: data => console.log(`line read: ${data}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ MouseArea {
|
|||
notifAction: modelData
|
||||
hasIcons: toast.notif?.hasActionIcons ?? false
|
||||
height: toast.actionHeight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
visible: toast.notif?.actions.length ?? false
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import QtQuick.Controls
|
||||
import Quickshell.Widgets
|
||||
import QtQuick
|
||||
import "../../base"
|
||||
|
||||
Button {
|
||||
BButton {
|
||||
id: actionButton
|
||||
|
||||
required property var notifAction
|
||||
|
|
|
@ -2,6 +2,7 @@ import QtQuick.Layouts
|
|||
import QtQuick
|
||||
import Quickshell.Widgets
|
||||
import Quickshell
|
||||
import QtQml
|
||||
|
||||
import "../../provider"
|
||||
import "../../base"
|
||||
|
@ -36,9 +37,41 @@ BRectangle {
|
|||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
height: 1
|
||||
GridLayout {
|
||||
|
||||
Repeater {
|
||||
|
||||
model: Weather.lastFetch?.weather
|
||||
|
||||
delegate: Rectangle {
|
||||
id: forecastRect
|
||||
required property var modelData
|
||||
property string mintempC: modelData.mintempC
|
||||
property string maxtempC: modelData.maxtempC
|
||||
property string date: modelData.date
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.margins: 5
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
|
||||
Text {
|
||||
text: {
|
||||
const day = (new Date(forecastRect.date)).getDay();
|
||||
const weekday = Qt.locale().dayName(day, Locale.LongFormat);
|
||||
return weekday;
|
||||
}
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
}
|
||||
Text {
|
||||
text: `${forecastRect.mintempC}°C - ${forecastRect.maxtempC}°C`
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell.Io
|
||||
import "../../base"
|
||||
import "../../provider"
|
||||
|
||||
ColumnLayout {
|
||||
id: wifi
|
||||
|
@ -11,19 +10,27 @@ ColumnLayout {
|
|||
Layout.fillWidth: true
|
||||
Layout.margins: 15
|
||||
|
||||
property ListModel networks: ListModel {}
|
||||
property ListModel networks: ListModel {
|
||||
id: list
|
||||
Component.onCompleted: {
|
||||
Wifi.list.forEach(e => list.append(e));
|
||||
Wifi.added.connect(e => list?.append(e));
|
||||
Wifi.removed.connect(e => {
|
||||
for (let i = 0; i < list?.count; i++) {
|
||||
if (list.get(i).bssid === e.bssid) {
|
||||
list.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
signal navigationReturn
|
||||
|
||||
BRectangle {
|
||||
width: 100
|
||||
height: 100
|
||||
visible: getter.running
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: re
|
||||
visible: wifi.networks.count > 0
|
||||
model: wifi.networks
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
@ -94,6 +101,10 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
BButton {
|
||||
|
@ -107,46 +118,11 @@ ColumnLayout {
|
|||
|
||||
BButton {
|
||||
text: "refresh"
|
||||
onClicked: getter.running = true
|
||||
onClicked: Wifi.refresh()
|
||||
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
|
||||
Layout.fillWidth: true
|
||||
width: 30
|
||||
height: 30
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: getter
|
||||
command: ["nmcli", "-t", "device", "wifi"]
|
||||
running: true
|
||||
stdout: SplitParser {
|
||||
onRead: rawData => {
|
||||
rawData = rawData.replace(/\\:/g, ":").split(":");
|
||||
|
||||
const data = {
|
||||
connected: rawData[0] === "*",
|
||||
bssid: rawData.slice(1, 7).join(":").replace(),
|
||||
ssid: rawData[7],
|
||||
mode: rawData[8],
|
||||
channel: rawData[9],
|
||||
rate: rawData[10],
|
||||
signal: rawData[11],
|
||||
bars: rawData[12],
|
||||
security: rawData[13]
|
||||
};
|
||||
|
||||
for (let i = 0; i < networks.count; i++) {
|
||||
if (networks.get(i).bssid === data.bssid) {
|
||||
Object.entries(data).map(([key, value]) => {
|
||||
networks.setProperty(i, key, value);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
networks.append(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue