1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-29 22:42:11 -04:00

ui: cleanup some anti patterns

This commit is contained in:
bbedward
2026-06-29 12:39:56 -04:00
parent f293def3a8
commit 50570023ff
6 changed files with 113 additions and 109 deletions
@@ -28,10 +28,6 @@ Column {
signal collapseRequested
signal configRequested(int index, var widgetData, var anchor)
function requestCollapse() {
collapseRequested();
}
spacing: editMode ? Theme.spacingL : Theme.spacingS
property real maxPopoutHeight: 9999
@@ -103,39 +99,56 @@ Column {
}
function getCompoundPillIconBlinking(id) {
if (id === "wifi") return NetworkService.isWifiConnecting;
if (id === "bluetooth") return BluetoothService.connecting;
if (id === "wifi")
return NetworkService.isWifiConnecting;
if (id === "bluetooth")
return BluetoothService.connecting;
return false;
}
function getCompoundPillIconName(id, widgetDef) {
switch (id) {
case "wifi": {
if (NetworkService.wifiToggling) return "sync";
if (NetworkService.isConnecting && !NetworkService.ethernetConnected) return NetworkService.wifiSignalIcon;
const status = NetworkService.networkStatus;
if (status === "ethernet") return "settings_ethernet";
if (status === "vpn") return NetworkService.ethernetConnected ? "settings_ethernet" : NetworkService.wifiSignalIcon;
if (status === "wifi") return NetworkService.wifiSignalIcon;
return "wifi";
}
case "bluetooth": {
return "bluetooth";
}
case "audioOutput": {
if (!AudioService.sink?.audio) return "volume_off";
let volume = AudioService.sink.audio.volume;
let muted = AudioService.sink.audio.muted;
if (muted) return "volume_off";
if (volume === 0.0) return "volume_mute";
if (volume <= 0.33) return "volume_down";
if (volume <= 0.66) return "volume_up";
return "volume_up";
}
case "audioInput": {
if (!AudioService.source?.audio) return "mic_off";
return AudioService.source.audio.muted ? "mic_off" : "mic";
}
case "wifi":
{
if (NetworkService.wifiToggling)
return "sync";
if (NetworkService.isConnecting && !NetworkService.ethernetConnected)
return NetworkService.wifiSignalIcon;
const status = NetworkService.networkStatus;
if (status === "ethernet")
return "settings_ethernet";
if (status === "vpn")
return NetworkService.ethernetConnected ? "settings_ethernet" : NetworkService.wifiSignalIcon;
if (status === "wifi")
return NetworkService.wifiSignalIcon;
return "wifi";
}
case "bluetooth":
{
return "bluetooth";
}
case "audioOutput":
{
if (!AudioService.sink?.audio)
return "volume_off";
let volume = AudioService.sink.audio.volume;
let muted = AudioService.sink.audio.muted;
if (muted)
return "volume_off";
if (volume === 0.0)
return "volume_mute";
if (volume <= 0.33)
return "volume_down";
if (volume <= 0.66)
return "volume_up";
return "volume_up";
}
case "audioInput":
{
if (!AudioService.source?.audio)
return "mic_off";
return AudioService.source.audio.muted ? "mic_off" : "mic";
}
default:
return widgetDef?.icon || "help";
}
@@ -143,14 +156,19 @@ Column {
function getCompoundPillIsActive(id) {
switch (id) {
case "wifi": {
if (NetworkService.wifiToggling) return false;
const status = NetworkService.networkStatus;
if (status === "ethernet") return true;
if (status === "vpn") return NetworkService.ethernetConnected || NetworkService.wifiConnected;
if (status === "wifi") return true;
return NetworkService.wifiEnabled;
}
case "wifi":
{
if (NetworkService.wifiToggling)
return false;
const status = NetworkService.networkStatus;
if (status === "ethernet")
return true;
if (status === "vpn")
return NetworkService.ethernetConnected || NetworkService.wifiConnected;
if (status === "wifi")
return true;
return NetworkService.wifiEnabled;
}
case "bluetooth":
return !!(BluetoothService.available && BluetoothService.adapter && BluetoothService.adapter.enabled);
case "audioOutput":
@@ -164,52 +182,62 @@ Column {
function handleCompoundPillToggled(id) {
switch (id) {
case "wifi": {
if (NetworkService.networkStatus !== "ethernet" && !NetworkService.wifiToggling) {
NetworkService.toggleWifiRadio();
case "wifi":
{
if (NetworkService.networkStatus !== "ethernet" && !NetworkService.wifiToggling) {
NetworkService.toggleWifiRadio();
}
break;
}
break;
}
case "bluetooth": {
if (BluetoothService.available && BluetoothService.adapter) {
BluetoothService.adapter.enabled = !BluetoothService.adapter.enabled;
case "bluetooth":
{
if (BluetoothService.available && BluetoothService.adapter) {
BluetoothService.adapter.enabled = !BluetoothService.adapter.enabled;
}
break;
}
break;
}
case "audioOutput": {
if (AudioService.sink && AudioService.sink.audio) {
AudioService.sink.audio.muted = !AudioService.sink.audio.muted;
case "audioOutput":
{
if (AudioService.sink && AudioService.sink.audio) {
AudioService.sink.audio.muted = !AudioService.sink.audio.muted;
}
break;
}
break;
}
case "audioInput": {
if (AudioService.source && AudioService.source.audio) {
AudioService.source.audio.muted = !AudioService.source.audio.muted;
case "audioInput":
{
if (AudioService.source && AudioService.source.audio) {
AudioService.source.audio.muted = !AudioService.source.audio.muted;
}
break;
}
break;
}
}
}
function handleCompoundPillWheelEvent(id, wheelEvent) {
if (id === "audioOutput") {
if (!AudioService.sink || !AudioService.sink.audio) return;
if (!AudioService.sink || !AudioService.sink.audio)
return;
let delta = wheelEvent.angleDelta.y;
let maxVol = AudioService.sinkMaxVolume;
let currentVolume = AudioService.sink.audio.volume * 100;
let newVolume;
if (delta > 0) newVolume = Math.min(maxVol, currentVolume + 5);
else newVolume = Math.max(0, currentVolume - 5);
if (delta > 0)
newVolume = Math.min(maxVol, currentVolume + 5);
else
newVolume = Math.max(0, currentVolume - 5);
AudioService.sink.audio.muted = false;
AudioService.sink.audio.volume = newVolume / 100;
wheelEvent.accepted = true;
} else if (id === "audioInput") {
if (!AudioService.source || !AudioService.source.audio) return;
if (!AudioService.source || !AudioService.source.audio)
return;
let delta = wheelEvent.angleDelta.y;
let currentVolume = AudioService.source.audio.volume * 100;
let newVolume;
if (delta > 0) newVolume = Math.min(100, currentVolume + 5);
else newVolume = Math.max(0, currentVolume - 5);
if (delta > 0)
newVolume = Math.min(100, currentVolume + 5);
else
newVolume = Math.max(0, currentVolume - 5);
AudioService.source.audio.muted = false;
AudioService.source.audio.volume = newVolume / 100;
wheelEvent.accepted = true;
@@ -354,7 +382,7 @@ Column {
expandedWidgetData: active ? root.expandedWidgetData : retainedWidgetData
bluetoothCodecSelector: root.bluetoothCodecSelector
widgetModel: root.model
collapseCallback: root.requestCollapse
collapseCallback: root.collapseRequested
screenName: root.screenName
screenModel: root.screenModel
@@ -1208,15 +1236,18 @@ Column {
isActive: root.getCompoundPillIsActive(widgetData.id || "")
enabled: (widgetDef?.enabled ?? true) && !root.editMode
onToggled: {
if (root.editMode) return;
if (root.editMode)
return;
root.handleCompoundPillToggled(widgetData.id || "");
}
onExpandClicked: {
if (root.editMode) return;
if (root.editMode)
return;
root.expandClicked(widgetData, widgetIndex);
}
onWheelEvent: function(wheelEvent) {
if (root.editMode) return;
onWheelEvent: function (wheelEvent) {
if (root.editMode)
return;
root.handleCompoundPillWheelEvent(widgetData.id || "", wheelEvent);
}
}
@@ -1231,7 +1262,8 @@ Column {
height: 48
colorPickerModal: root.colorPickerModal
onClicked: {
if (root.editMode) return;
if (root.editMode)
return;
if (root.colorPickerModal)
root.colorPickerModal.show();
}