mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
move functions to service 2/3
This commit is contained in:
@@ -41,46 +41,6 @@ Item {
|
||||
implicitWidth: pill.width
|
||||
implicitHeight: pill.height
|
||||
|
||||
function getStatustxt() {
|
||||
if (NetworkService.connecting) {
|
||||
return NetworkService.connectingTo ? I18n.tr("common.connecting") + " " + NetworkService.connectingTo : I18n.tr("common.connecting");
|
||||
}
|
||||
|
||||
let p = [];
|
||||
|
||||
// Ethernet
|
||||
if (NetworkService.ethernetConnected) {
|
||||
const eth = NetworkService.activeEthernetDetails;
|
||||
const name = eth.connectionName || (NetworkService.ethernetInterfaces.length > 0 ? NetworkService.ethernetInterfaces[0].connectionName : "") || NetworkService.activeEthernetIf || "";
|
||||
const speed = eth.speed || "";
|
||||
const s = name ? (speed ? name + " - " + speed : name) : "";
|
||||
if (s) {
|
||||
p.push(s);
|
||||
}
|
||||
}
|
||||
|
||||
// Wi-Fi
|
||||
if (NetworkService.activeWifiIf) {
|
||||
const wl = NetworkService.activeWifiDetails;
|
||||
const speed = wl.rateShort || wl.rate || "";
|
||||
const connectedNet = Object.values(NetworkService.networks).find(net => net.connected);
|
||||
const name = connectedNet ? connectedNet.ssid : (wl.connectionName || NetworkService.activeWifiIf || "");
|
||||
const s = name ? (speed ? name + " - " + speed : name) : "";
|
||||
if (s) {
|
||||
p.push(s);
|
||||
}
|
||||
}
|
||||
return p.join(isBarVertical ? "\n" : " + ");
|
||||
}
|
||||
|
||||
function getIcon() {
|
||||
if (NetworkService.ethernetConnected) {
|
||||
return NetworkService.internetConnectivity ? "ethernet" : "ethernet-off";
|
||||
}
|
||||
const connectedNet = Object.values(NetworkService.networks).find(net => net.connected);
|
||||
return connectedNet ? NetworkService.getSignalInfo(connectedNet.signal, true).icon : "wifi-off";
|
||||
}
|
||||
|
||||
NPopupContextMenu {
|
||||
id: contextMenu
|
||||
|
||||
@@ -123,8 +83,8 @@ Item {
|
||||
oppositeDirection: BarService.getPillDirection(root)
|
||||
customIconColor: Color.resolveColorKeyOptional(root.iconColorKey)
|
||||
customTextColor: Color.resolveColorKeyOptional(root.textColorKey)
|
||||
icon: getIcon()
|
||||
text: getStatustxt()
|
||||
icon: NetworkService.getIcon()
|
||||
text: NetworkService.getStatustxt()
|
||||
autoHide: false
|
||||
forceOpen: !isBarVertical && root.displayMode === "alwaysShow"
|
||||
forceClose: isBarVertical || root.displayMode === "alwaysHide" || text === ""
|
||||
|
||||
@@ -7,49 +7,8 @@ import qs.Widgets
|
||||
|
||||
NIconButtonHot {
|
||||
property ShellScreen screen
|
||||
|
||||
function getStatustxt() {
|
||||
if (NetworkService.connecting) {
|
||||
return NetworkService.connectingTo ? I18n.tr("common.connecting") + " " + NetworkService.connectingTo : I18n.tr("common.connecting");
|
||||
}
|
||||
|
||||
let p = [];
|
||||
|
||||
// Ethernet
|
||||
if (NetworkService.ethernetConnected) {
|
||||
const eth = NetworkService.activeEthernetDetails;
|
||||
const name = eth.connectionName || (NetworkService.ethernetInterfaces.length > 0 ? NetworkService.ethernetInterfaces[0].connectionName : "") || NetworkService.activeEthernetIf || "";
|
||||
const speed = eth.speed || "";
|
||||
const s = name ? (speed ? name + " - " + speed : name) : "";
|
||||
if (s) {
|
||||
p.push(s);
|
||||
}
|
||||
}
|
||||
|
||||
// Wi-Fi
|
||||
if (NetworkService.activeWifiIf) {
|
||||
const wl = NetworkService.activeWifiDetails;
|
||||
const speed = wl.rateShort || wl.rate || "";
|
||||
const connectedNet = Object.values(NetworkService.networks).find(net => net.connected);
|
||||
const name = connectedNet ? connectedNet.ssid : (wl.connectionName || NetworkService.activeWifiIf || "");
|
||||
const s = name ? (speed ? name + " - " + speed : name) : "";
|
||||
if (s) {
|
||||
p.push(s);
|
||||
}
|
||||
}
|
||||
return p.join(" + ");
|
||||
}
|
||||
|
||||
function getIcon() {
|
||||
if (NetworkService.ethernetConnected) {
|
||||
return NetworkService.internetConnectivity ? "wired" : "wired-off";
|
||||
}
|
||||
const connectedNet = Object.values(NetworkService.networks).find(net => net.connected);
|
||||
return connectedNet ? NetworkService.getSignalInfo(connectedNet.signal, true).icon : "wifi-off";
|
||||
}
|
||||
|
||||
icon: getIcon()
|
||||
tooltipText: getStatustxt()
|
||||
icon: NetworkService.getIcon()
|
||||
tooltipText: NetworkService.getStatustxt()
|
||||
onClicked: {
|
||||
var panel = PanelService.getPanel("networkPanel", screen);
|
||||
panel?.toggle(this);
|
||||
|
||||
Reference in New Issue
Block a user