mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 22:15:38 -05:00
Systematic cleanup and qmlfmt of all services
- qmlfmt kinda sucks but it's what qt creator uses
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
pragma ComponentBehavior
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
@@ -12,230 +13,238 @@ Singleton {
|
||||
readonly property BluetoothAdapter adapter: Bluetooth.defaultAdapter
|
||||
readonly property bool available: adapter !== null
|
||||
readonly property bool enabled: (adapter && adapter.enabled) ?? false
|
||||
readonly property bool discovering: (adapter
|
||||
&& adapter.discovering) ?? false
|
||||
readonly property bool discovering: (adapter && adapter.discovering) ?? false
|
||||
readonly property var devices: adapter ? adapter.devices : null
|
||||
readonly property var pairedDevices: {
|
||||
if (!adapter || !adapter.devices)
|
||||
return []
|
||||
if (!adapter || !adapter.devices) {
|
||||
return []
|
||||
}
|
||||
|
||||
return adapter.devices.values.filter(dev => {
|
||||
return dev && (dev.paired
|
||||
|| dev.trusted)
|
||||
return dev && (dev.paired || dev.trusted)
|
||||
})
|
||||
}
|
||||
readonly property var allDevicesWithBattery: {
|
||||
if (!adapter || !adapter.devices)
|
||||
return []
|
||||
if (!adapter || !adapter.devices) {
|
||||
return []
|
||||
}
|
||||
|
||||
return adapter.devices.values.filter(dev => {
|
||||
return dev
|
||||
&& dev.batteryAvailable
|
||||
&& dev.battery > 0
|
||||
return dev && dev.batteryAvailable && dev.battery > 0
|
||||
})
|
||||
}
|
||||
|
||||
function sortDevices(devices) {
|
||||
return devices.sort((a, b) => {
|
||||
var aName = a.name || a.deviceName || ""
|
||||
var bName = b.name || b.deviceName || ""
|
||||
const aName = a.name || a.deviceName || ""
|
||||
const bName = b.name || b.deviceName || ""
|
||||
|
||||
var aHasRealName = aName.includes(" ")
|
||||
&& aName.length > 3
|
||||
var bHasRealName = bName.includes(" ")
|
||||
&& bName.length > 3
|
||||
const aHasRealName = aName.includes(" ") && aName.length > 3
|
||||
const bHasRealName = bName.includes(" ") && bName.length > 3
|
||||
|
||||
if (aHasRealName && !bHasRealName)
|
||||
return -1
|
||||
if (!aHasRealName && bHasRealName)
|
||||
return 1
|
||||
if (aHasRealName && !bHasRealName) {
|
||||
return -1
|
||||
}
|
||||
if (!aHasRealName && bHasRealName) {
|
||||
return 1
|
||||
}
|
||||
|
||||
var aSignal = (a.signalStrength !== undefined
|
||||
&& a.signalStrength > 0) ? a.signalStrength : 0
|
||||
var bSignal = (b.signalStrength !== undefined
|
||||
&& b.signalStrength > 0) ? b.signalStrength : 0
|
||||
const aSignal = (a.signalStrength !== undefined && a.signalStrength > 0) ? a.signalStrength : 0
|
||||
const bSignal = (b.signalStrength !== undefined && b.signalStrength > 0) ? b.signalStrength : 0
|
||||
return bSignal - aSignal
|
||||
})
|
||||
}
|
||||
|
||||
function getDeviceIcon(device) {
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return "bluetooth"
|
||||
}
|
||||
|
||||
var name = (device.name || device.deviceName || "").toLowerCase()
|
||||
var icon = (device.icon || "").toLowerCase()
|
||||
if (icon.includes("headset") || icon.includes("audio") || name.includes(
|
||||
"headphone") || name.includes("airpod") || name.includes(
|
||||
"headset") || name.includes("arctis"))
|
||||
const name = (device.name || device.deviceName || "").toLowerCase()
|
||||
const icon = (device.icon || "").toLowerCase()
|
||||
|
||||
const audioKeywords = ["headset", "audio", "headphone", "airpod", "arctis"]
|
||||
if (audioKeywords.some(keyword => icon.includes(keyword) || name.includes(keyword))) {
|
||||
return "headset"
|
||||
}
|
||||
|
||||
if (icon.includes("mouse") || name.includes("mouse"))
|
||||
if (icon.includes("mouse") || name.includes("mouse")) {
|
||||
return "mouse"
|
||||
}
|
||||
|
||||
if (icon.includes("keyboard") || name.includes("keyboard"))
|
||||
if (icon.includes("keyboard") || name.includes("keyboard")) {
|
||||
return "keyboard"
|
||||
}
|
||||
|
||||
if (icon.includes("phone") || name.includes("phone") || name.includes(
|
||||
"iphone") || name.includes("android") || name.includes(
|
||||
"samsung"))
|
||||
const phoneKeywords = ["phone", "iphone", "android", "samsung"]
|
||||
if (phoneKeywords.some(keyword => icon.includes(keyword) || name.includes(keyword))) {
|
||||
return "smartphone"
|
||||
}
|
||||
|
||||
if (icon.includes("watch") || name.includes("watch"))
|
||||
if (icon.includes("watch") || name.includes("watch")) {
|
||||
return "watch"
|
||||
}
|
||||
|
||||
if (icon.includes("speaker") || name.includes("speaker"))
|
||||
if (icon.includes("speaker") || name.includes("speaker")) {
|
||||
return "speaker"
|
||||
}
|
||||
|
||||
if (icon.includes("display") || name.includes("tv"))
|
||||
if (icon.includes("display") || name.includes("tv")) {
|
||||
return "tv"
|
||||
}
|
||||
|
||||
return "bluetooth"
|
||||
}
|
||||
|
||||
function canConnect(device) {
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return false
|
||||
}
|
||||
|
||||
return !device.paired && !device.pairing && !device.blocked
|
||||
}
|
||||
|
||||
function getSignalStrength(device) {
|
||||
if (!device || device.signalStrength === undefined
|
||||
|| device.signalStrength <= 0)
|
||||
if (!device || device.signalStrength === undefined || device.signalStrength <= 0) {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
var signal = device.signalStrength
|
||||
if (signal >= 80)
|
||||
const signal = device.signalStrength
|
||||
if (signal >= 80) {
|
||||
return "Excellent"
|
||||
|
||||
if (signal >= 60)
|
||||
}
|
||||
if (signal >= 60) {
|
||||
return "Good"
|
||||
|
||||
if (signal >= 40)
|
||||
}
|
||||
if (signal >= 40) {
|
||||
return "Fair"
|
||||
|
||||
if (signal >= 20)
|
||||
}
|
||||
if (signal >= 20) {
|
||||
return "Poor"
|
||||
}
|
||||
|
||||
return "Very Poor"
|
||||
}
|
||||
|
||||
function getSignalIcon(device) {
|
||||
if (!device || device.signalStrength === undefined
|
||||
|| device.signalStrength <= 0)
|
||||
if (!device || device.signalStrength === undefined || device.signalStrength <= 0) {
|
||||
return "signal_cellular_null"
|
||||
}
|
||||
|
||||
var signal = device.signalStrength
|
||||
if (signal >= 80)
|
||||
const signal = device.signalStrength
|
||||
if (signal >= 80) {
|
||||
return "signal_cellular_4_bar"
|
||||
|
||||
if (signal >= 60)
|
||||
}
|
||||
if (signal >= 60) {
|
||||
return "signal_cellular_3_bar"
|
||||
|
||||
if (signal >= 40)
|
||||
}
|
||||
if (signal >= 40) {
|
||||
return "signal_cellular_2_bar"
|
||||
|
||||
if (signal >= 20)
|
||||
}
|
||||
if (signal >= 20) {
|
||||
return "signal_cellular_1_bar"
|
||||
}
|
||||
|
||||
return "signal_cellular_0_bar"
|
||||
}
|
||||
|
||||
function isDeviceBusy(device) {
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return false
|
||||
return device.pairing
|
||||
|| device.state === BluetoothDeviceState.Disconnecting
|
||||
|| device.state === BluetoothDeviceState.Connecting
|
||||
}
|
||||
return device.pairing || device.state === BluetoothDeviceState.Disconnecting || device.state === BluetoothDeviceState.Connecting
|
||||
}
|
||||
|
||||
function connectDeviceWithTrust(device) {
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return
|
||||
}
|
||||
|
||||
device.trusted = true
|
||||
device.connect()
|
||||
}
|
||||
|
||||
function getCardName(device) {
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return ""
|
||||
return "bluez_card." + device.address.replace(/:/g, "_")
|
||||
}
|
||||
return `bluez_card.${device.address.replace(/:/g, "_")}`
|
||||
}
|
||||
|
||||
function isAudioDevice(device) {
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return false
|
||||
let icon = getDeviceIcon(device)
|
||||
}
|
||||
const icon = getDeviceIcon(device)
|
||||
return icon === "headset" || icon === "speaker"
|
||||
}
|
||||
|
||||
function getCodecInfo(codecName) {
|
||||
let codec = codecName.replace(/-/g, "_").toUpperCase()
|
||||
|
||||
let codecMap = {
|
||||
const codec = codecName.replace(/-/g, "_").toUpperCase()
|
||||
|
||||
const codecMap = {
|
||||
"LDAC": {
|
||||
name: "LDAC",
|
||||
description: "Highest quality • Higher battery usage",
|
||||
qualityColor: "#4CAF50"
|
||||
"name": "LDAC",
|
||||
"description": "Highest quality • Higher battery usage",
|
||||
"qualityColor": "#4CAF50"
|
||||
},
|
||||
"APTX_HD": {
|
||||
name: "aptX HD",
|
||||
description: "High quality • Balanced battery",
|
||||
qualityColor: "#FF9800"
|
||||
"name": "aptX HD",
|
||||
"description": "High quality • Balanced battery",
|
||||
"qualityColor": "#FF9800"
|
||||
},
|
||||
"APTX": {
|
||||
name: "aptX",
|
||||
description: "Good quality • Low latency",
|
||||
qualityColor: "#FF9800"
|
||||
"name": "aptX",
|
||||
"description": "Good quality • Low latency",
|
||||
"qualityColor": "#FF9800"
|
||||
},
|
||||
"AAC": {
|
||||
name: "AAC",
|
||||
description: "Balanced quality and battery",
|
||||
qualityColor: "#2196F3"
|
||||
"name": "AAC",
|
||||
"description": "Balanced quality and battery",
|
||||
"qualityColor": "#2196F3"
|
||||
},
|
||||
"SBC_XQ": {
|
||||
name: "SBC-XQ",
|
||||
description: "Enhanced SBC • Better compatibility",
|
||||
qualityColor: "#2196F3"
|
||||
"name": "SBC-XQ",
|
||||
"description": "Enhanced SBC • Better compatibility",
|
||||
"qualityColor": "#2196F3"
|
||||
},
|
||||
"SBC": {
|
||||
name: "SBC",
|
||||
description: "Basic quality • Universal compatibility",
|
||||
qualityColor: "#9E9E9E"
|
||||
"name": "SBC",
|
||||
"description": "Basic quality • Universal compatibility",
|
||||
"qualityColor": "#9E9E9E"
|
||||
},
|
||||
"MSBC": {
|
||||
name: "mSBC",
|
||||
description: "Modified SBC • Optimized for speech",
|
||||
qualityColor: "#9E9E9E"
|
||||
"name": "mSBC",
|
||||
"description": "Modified SBC • Optimized for speech",
|
||||
"qualityColor": "#9E9E9E"
|
||||
},
|
||||
"CVSD": {
|
||||
name: "CVSD",
|
||||
description: "Basic speech codec • Legacy compatibility",
|
||||
qualityColor: "#9E9E9E"
|
||||
"name": "CVSD",
|
||||
"description": "Basic speech codec • Legacy compatibility",
|
||||
"qualityColor": "#9E9E9E"
|
||||
}
|
||||
}
|
||||
|
||||
return codecMap[codec] || {
|
||||
name: codecName,
|
||||
description: "Unknown codec",
|
||||
qualityColor: "#9E9E9E"
|
||||
"name": codecName,
|
||||
"description": "Unknown codec",
|
||||
"qualityColor": "#9E9E9E"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
property var deviceCodecs: ({})
|
||||
|
||||
|
||||
function updateDeviceCodec(deviceAddress, codec) {
|
||||
deviceCodecs[deviceAddress] = codec
|
||||
deviceCodecsChanged()
|
||||
}
|
||||
|
||||
|
||||
function refreshDeviceCodec(device) {
|
||||
if (!device || !device.connected || !isAudioDevice(device)) {
|
||||
return
|
||||
}
|
||||
|
||||
let cardName = getCardName(device)
|
||||
|
||||
const cardName = getCardName(device)
|
||||
codecQueryProcess.cardName = cardName
|
||||
codecQueryProcess.deviceAddress = device.address
|
||||
codecQueryProcess.availableCodecs = []
|
||||
@@ -243,14 +252,14 @@ Singleton {
|
||||
codecQueryProcess.detectedCodec = ""
|
||||
codecQueryProcess.running = true
|
||||
}
|
||||
|
||||
|
||||
function getCurrentCodec(device, callback) {
|
||||
if (!device || !device.connected || !isAudioDevice(device)) {
|
||||
callback("")
|
||||
return
|
||||
}
|
||||
|
||||
let cardName = getCardName(device)
|
||||
|
||||
const cardName = getCardName(device)
|
||||
codecQueryProcess.cardName = cardName
|
||||
codecQueryProcess.callback = callback
|
||||
codecQueryProcess.availableCodecs = []
|
||||
@@ -258,14 +267,14 @@ Singleton {
|
||||
codecQueryProcess.detectedCodec = ""
|
||||
codecQueryProcess.running = true
|
||||
}
|
||||
|
||||
|
||||
function getAvailableCodecs(device, callback) {
|
||||
if (!device || !device.connected || !isAudioDevice(device)) {
|
||||
callback([], "")
|
||||
return
|
||||
}
|
||||
|
||||
let cardName = getCardName(device)
|
||||
|
||||
const cardName = getCardName(device)
|
||||
codecFullQueryProcess.cardName = cardName
|
||||
codecFullQueryProcess.callback = callback
|
||||
codecFullQueryProcess.availableCodecs = []
|
||||
@@ -273,33 +282,33 @@ Singleton {
|
||||
codecFullQueryProcess.detectedCodec = ""
|
||||
codecFullQueryProcess.running = true
|
||||
}
|
||||
|
||||
|
||||
function switchCodec(device, profileName, callback) {
|
||||
if (!device || !isAudioDevice(device)) {
|
||||
callback(false, "Invalid device")
|
||||
return
|
||||
}
|
||||
|
||||
let cardName = getCardName(device)
|
||||
|
||||
const cardName = getCardName(device)
|
||||
codecSwitchProcess.cardName = cardName
|
||||
codecSwitchProcess.profile = profileName
|
||||
codecSwitchProcess.callback = callback
|
||||
codecSwitchProcess.running = true
|
||||
}
|
||||
|
||||
|
||||
Process {
|
||||
id: codecQueryProcess
|
||||
|
||||
|
||||
property string cardName: ""
|
||||
property string deviceAddress: ""
|
||||
property var callback: null
|
||||
property bool parsingTargetCard: false
|
||||
property string detectedCodec: ""
|
||||
property var availableCodecs: []
|
||||
|
||||
|
||||
command: ["pactl", "list", "cards"]
|
||||
|
||||
onExited: function(exitCode, exitStatus) {
|
||||
|
||||
onExited: (exitCode, exitStatus) => {
|
||||
if (exitCode === 0 && detectedCodec) {
|
||||
if (deviceAddress) {
|
||||
root.updateDeviceCodec(deviceAddress, detectedCodec)
|
||||
@@ -310,35 +319,35 @@ Singleton {
|
||||
} else if (callback) {
|
||||
callback("")
|
||||
}
|
||||
|
||||
|
||||
parsingTargetCard = false
|
||||
detectedCodec = ""
|
||||
availableCodecs = []
|
||||
deviceAddress = ""
|
||||
callback = null
|
||||
}
|
||||
|
||||
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: (data) => {
|
||||
onRead: data => {
|
||||
let line = data.trim()
|
||||
|
||||
|
||||
if (line.includes(`Name: ${codecQueryProcess.cardName}`)) {
|
||||
codecQueryProcess.parsingTargetCard = true
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (codecQueryProcess.parsingTargetCard && line.startsWith("Name: ") && !line.includes(codecQueryProcess.cardName)) {
|
||||
codecQueryProcess.parsingTargetCard = false
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (codecQueryProcess.parsingTargetCard) {
|
||||
if (line.startsWith("Active Profile:")) {
|
||||
let profile = line.split(": ")[1] || ""
|
||||
let activeCodec = codecQueryProcess.availableCodecs.find((c) => {
|
||||
return c.profile === profile
|
||||
})
|
||||
let activeCodec = codecQueryProcess.availableCodecs.find(c => {
|
||||
return c.profile === profile
|
||||
})
|
||||
if (activeCodec) {
|
||||
codecQueryProcess.detectedCodec = activeCodec.name
|
||||
}
|
||||
@@ -352,16 +361,16 @@ Singleton {
|
||||
let codecMatch = description.match(/codec ([^\)\s]+)/i)
|
||||
let codecName = codecMatch ? codecMatch[1].toUpperCase() : "UNKNOWN"
|
||||
let codecInfo = root.getCodecInfo(codecName)
|
||||
if (codecInfo && !codecQueryProcess.availableCodecs.some((c) => {
|
||||
return c.profile === profile
|
||||
})) {
|
||||
if (codecInfo && !codecQueryProcess.availableCodecs.some(c => {
|
||||
return c.profile === profile
|
||||
})) {
|
||||
let newCodecs = codecQueryProcess.availableCodecs.slice()
|
||||
newCodecs.push({
|
||||
"name": codecInfo.name,
|
||||
"profile": profile,
|
||||
"description": codecInfo.description,
|
||||
"qualityColor": codecInfo.qualityColor
|
||||
})
|
||||
"name": codecInfo.name,
|
||||
"profile": profile,
|
||||
"description": codecInfo.description,
|
||||
"qualityColor": codecInfo.qualityColor
|
||||
})
|
||||
codecQueryProcess.availableCodecs = newCodecs
|
||||
}
|
||||
}
|
||||
@@ -370,19 +379,19 @@ Singleton {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Process {
|
||||
id: codecFullQueryProcess
|
||||
|
||||
|
||||
property string cardName: ""
|
||||
property var callback: null
|
||||
property bool parsingTargetCard: false
|
||||
property string detectedCodec: ""
|
||||
property var availableCodecs: []
|
||||
|
||||
|
||||
command: ["pactl", "list", "cards"]
|
||||
|
||||
onExited: function(exitCode, exitStatus) {
|
||||
|
||||
onExited: function (exitCode, exitStatus) {
|
||||
if (callback) {
|
||||
callback(exitCode === 0 ? availableCodecs : [], exitCode === 0 ? detectedCodec : "")
|
||||
}
|
||||
@@ -391,28 +400,28 @@ Singleton {
|
||||
availableCodecs = []
|
||||
callback = null
|
||||
}
|
||||
|
||||
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: (data) => {
|
||||
onRead: data => {
|
||||
let line = data.trim()
|
||||
|
||||
|
||||
if (line.includes(`Name: ${codecFullQueryProcess.cardName}`)) {
|
||||
codecFullQueryProcess.parsingTargetCard = true
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (codecFullQueryProcess.parsingTargetCard && line.startsWith("Name: ") && !line.includes(codecFullQueryProcess.cardName)) {
|
||||
codecFullQueryProcess.parsingTargetCard = false
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (codecFullQueryProcess.parsingTargetCard) {
|
||||
if (line.startsWith("Active Profile:")) {
|
||||
let profile = line.split(": ")[1] || ""
|
||||
let activeCodec = codecFullQueryProcess.availableCodecs.find((c) => {
|
||||
return c.profile === profile
|
||||
})
|
||||
let activeCodec = codecFullQueryProcess.availableCodecs.find(c => {
|
||||
return c.profile === profile
|
||||
})
|
||||
if (activeCodec) {
|
||||
codecFullQueryProcess.detectedCodec = activeCodec.name
|
||||
}
|
||||
@@ -426,16 +435,16 @@ Singleton {
|
||||
let codecMatch = description.match(/codec ([^\)\s]+)/i)
|
||||
let codecName = codecMatch ? codecMatch[1].toUpperCase() : "UNKNOWN"
|
||||
let codecInfo = root.getCodecInfo(codecName)
|
||||
if (codecInfo && !codecFullQueryProcess.availableCodecs.some((c) => {
|
||||
return c.profile === profile
|
||||
})) {
|
||||
if (codecInfo && !codecFullQueryProcess.availableCodecs.some(c => {
|
||||
return c.profile === profile
|
||||
})) {
|
||||
let newCodecs = codecFullQueryProcess.availableCodecs.slice()
|
||||
newCodecs.push({
|
||||
"name": codecInfo.name,
|
||||
"profile": profile,
|
||||
"description": codecInfo.description,
|
||||
"qualityColor": codecInfo.qualityColor
|
||||
})
|
||||
"name": codecInfo.name,
|
||||
"profile": profile,
|
||||
"description": codecInfo.description,
|
||||
"qualityColor": codecInfo.qualityColor
|
||||
})
|
||||
codecFullQueryProcess.availableCodecs = newCodecs
|
||||
}
|
||||
}
|
||||
@@ -444,32 +453,32 @@ Singleton {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Process {
|
||||
id: codecSwitchProcess
|
||||
|
||||
|
||||
property string cardName: ""
|
||||
property string profile: ""
|
||||
property var callback: null
|
||||
|
||||
|
||||
command: ["pactl", "set-card-profile", cardName, profile]
|
||||
|
||||
onExited: function(exitCode, exitStatus) {
|
||||
|
||||
onExited: function (exitCode, exitStatus) {
|
||||
if (callback) {
|
||||
callback(exitCode === 0, exitCode === 0 ? "Codec switched successfully" : "Failed to switch codec")
|
||||
}
|
||||
|
||||
|
||||
// If successful, refresh the codec for this device
|
||||
if (exitCode === 0) {
|
||||
if (root.adapter && root.adapter.devices) {
|
||||
root.adapter.devices.values.forEach(device => {
|
||||
if (device && root.getCardName(device) === cardName) {
|
||||
Qt.callLater(() => root.refreshDeviceCodec(device))
|
||||
}
|
||||
})
|
||||
if (device && root.getCardName(device) === cardName) {
|
||||
Qt.callLater(() => root.refreshDeviceCodec(device))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user