[Linux] Add cross device setting

This commit is contained in:
Tim Gromeyer
2025-04-19 10:56:13 +02:00
committed by Tim Gromeyer
parent 816992fd8a
commit 1c7bdf987c
2 changed files with 52 additions and 25 deletions

View File

@@ -131,21 +131,6 @@ ApplicationWindow {
checked: airPodsTrayApp.conversationalAwareness
onCheckedChanged: airPodsTrayApp.conversationalAwareness = checked
}
Row {
spacing: 10
TextField {
id: newNameField
placeholderText: airPodsTrayApp.deviceName
maximumLength: 32
}
Button {
text: "Rename"
onClicked: airPodsTrayApp.renameAirPods(newNameField.text)
}
}
}
RoundButton {
@@ -179,12 +164,41 @@ ApplicationWindow {
anchors.horizontalCenter: parent.horizontalCenter
}
ComboBox {
anchors.horizontalCenter: parent.horizontalCenter
model: ["Pause When One Removed", "Pause When Both Removed", "Never Pause"]
currentIndex: airPodsTrayApp.earDetectionBehavior
onActivated: {
airPodsTrayApp.earDetectionBehavior = currentIndex
Column {
spacing: 5 // Small gap between label and ComboBox
Label {
text: "Pause Behavior When Removing AirPods:"
}
ComboBox {
width: parent.width // Ensures full width
model: ["One Removed", "Both Removed", "Never"]
currentIndex: airPodsTrayApp.earDetectionBehavior
onActivated: airPodsTrayApp.earDetectionBehavior = currentIndex
}
}
Switch {
text: "Cross-Device Connectivity with Android"
checked: airPodsTrayApp.crossDeviceEnabled
onCheckedChanged: {
airPodsTrayApp.setCrossDeviceEnabled(checked)
}
}
Row {
spacing: 10
TextField {
id: newNameField
placeholderText: airPodsTrayApp.deviceName
maximumLength: 32
}
Button {
text: "Rename"
onClicked: airPodsTrayApp.renameAirPods(newNameField.text)
}
}
}

View File

@@ -30,6 +30,7 @@ class AirPodsTrayApp : public QObject {
Q_PROPERTY(bool rightPodInEar READ isRightPodInEar NOTIFY primaryChanged)
Q_PROPERTY(bool airpodsConnected READ areAirpodsConnected NOTIFY airPodsStatusChanged)
Q_PROPERTY(int earDetectionBehavior READ earDetectionBehavior WRITE setEarDetectionBehavior NOTIFY earDetectionBehaviorChanged)
Q_PROPERTY(bool crossDeviceEnabled READ crossDeviceEnabled WRITE setCrossDeviceEnabled NOTIFY crossDeviceEnabledChanged)
public:
AirPodsTrayApp(bool debugMode)
@@ -270,6 +271,20 @@ public slots:
emit earDetectionBehaviorChanged(behavior);
}
void setCrossDeviceEnabled(bool enabled)
{
if (CrossDevice.isEnabled == enabled)
{
LOG_INFO("Cross-device feature is already " << (enabled ? "enabled" : "disabled"));
return;
}
CrossDevice.isEnabled = enabled;
saveCrossDeviceEnabled();
connectToPhone();
emit crossDeviceEnabledChanged(enabled);
}
bool writePacketToSocket(const QByteArray &packet, const QString &logMessage)
{
if (socket && socket->isOpen())
@@ -578,10 +593,8 @@ private slots:
{
char primary = data[6];
char secondary = data[7];
m_primaryInEar = primary == 0x00;
m_secoundaryInEar = secondary == 0x00;
m_primaryInEar = primary == 0x00;
m_secoundaryInEar = secondary == 0x00;
m_primaryInEar = data[6] == 0x00;
m_secoundaryInEar = data[7] == 0x00;
m_earDetectionStatus = QString("Primary: %1, Secondary: %2")
.arg(getEarStatus(primary), getEarStatus(secondary));
LOG_INFO("Ear detection status: " << m_earDetectionStatus);