mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 05:55:37 -05:00
bluetooth: trust device before connecting
Fixes devices not staying in history
This commit is contained in:
@@ -92,7 +92,7 @@ Item {
|
|||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: BluetoothService.adapter && BluetoothService.adapter.devices ? BluetoothService.adapter.devices.values.filter((dev) => {
|
model: BluetoothService.adapter && BluetoothService.adapter.devices ? BluetoothService.adapter.devices.values.filter((dev) => {
|
||||||
return dev && dev.paired;
|
return dev && (dev.paired || dev.trusted);
|
||||||
}) : []
|
}) : []
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@@ -131,7 +131,7 @@ Item {
|
|||||||
spacing: Theme.spacingXS
|
spacing: Theme.spacingXS
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: modelData.connected ? "Connected" : "Disconnected"
|
text: BluetoothDeviceState.toString(modelData.state)
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||||
}
|
}
|
||||||
@@ -204,13 +204,13 @@ Item {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.rightMargin: 40
|
anchors.rightMargin: 40
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
enabled: !BluetoothService.isDeviceBusy(modelData)
|
||||||
|
cursorShape: enabled ? Qt.PointingHandCursor : Qt.BusyCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
BluetoothService.debugDevice(modelData);
|
|
||||||
if (modelData.connected) {
|
if (modelData.connected) {
|
||||||
modelData.disconnect();
|
modelData.disconnect();
|
||||||
} else {
|
} else {
|
||||||
modelData.connect();
|
BluetoothService.connectDeviceWithTrust(modelData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,15 +304,16 @@ Item {
|
|||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
property bool canConnect: BluetoothService.canConnect(modelData)
|
property bool canConnect: BluetoothService.canConnect(modelData)
|
||||||
|
property bool isBusy: BluetoothService.isDeviceBusy(modelData)
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 70
|
height: 70
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: {
|
color: {
|
||||||
if (availableDeviceArea.containsMouse)
|
if (availableDeviceArea.containsMouse && !isBusy)
|
||||||
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08);
|
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08);
|
||||||
|
|
||||||
if (modelData.pairing)
|
if (modelData.pairing || modelData.state === BluetoothDeviceState.Connecting)
|
||||||
return Qt.rgba(Theme.warning.r, Theme.warning.g, Theme.warning.b, 0.12);
|
return Qt.rgba(Theme.warning.r, Theme.warning.g, Theme.warning.b, 0.12);
|
||||||
|
|
||||||
if (modelData.blocked)
|
if (modelData.blocked)
|
||||||
@@ -426,18 +427,19 @@ Item {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: Theme.spacingM
|
anchors.rightMargin: Theme.spacingM
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
visible: modelData.state !== BluetoothDeviceState.Connecting
|
||||||
color: {
|
color: {
|
||||||
if (!canConnect && !modelData.pairing)
|
if (!canConnect && !isBusy)
|
||||||
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3);
|
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3);
|
||||||
|
|
||||||
if (actionButtonArea.containsMouse)
|
if (actionButtonArea.containsMouse && !isBusy)
|
||||||
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12);
|
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12);
|
||||||
|
|
||||||
return "transparent";
|
return "transparent";
|
||||||
}
|
}
|
||||||
border.color: canConnect || modelData.pairing ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
|
border.color: canConnect || isBusy ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
|
||||||
border.width: 1
|
border.width: 1
|
||||||
opacity: canConnect || modelData.pairing ? 1 : 0.5
|
opacity: canConnect || isBusy ? 1 : 0.5
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
@@ -451,7 +453,7 @@ Item {
|
|||||||
return "Connect";
|
return "Connect";
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: canConnect || modelData.pairing ? Theme.primary : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.5)
|
color: canConnect || isBusy ? Theme.primary : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.5)
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,10 +462,12 @@ Item {
|
|||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: canConnect ? Qt.PointingHandCursor : Qt.ArrowCursor
|
cursorShape: canConnect && !isBusy ? Qt.PointingHandCursor : (isBusy ? Qt.BusyCursor : Qt.ArrowCursor)
|
||||||
enabled: canConnect
|
enabled: canConnect && !isBusy
|
||||||
onClicked: {
|
onClicked: {
|
||||||
modelData && modelData.connect();
|
if (modelData) {
|
||||||
|
BluetoothService.connectDeviceWithTrust(modelData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,10 +479,12 @@ Item {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.rightMargin: 90 // Don't overlap with action button
|
anchors.rightMargin: 90 // Don't overlap with action button
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: canConnect ? Qt.PointingHandCursor : Qt.ArrowCursor
|
cursorShape: canConnect && !isBusy ? Qt.PointingHandCursor : (isBusy ? Qt.BusyCursor : Qt.ArrowCursor)
|
||||||
enabled: canConnect
|
enabled: canConnect && !isBusy
|
||||||
onClicked: {
|
onClicked: {
|
||||||
modelData && modelData.connect();
|
if (modelData) {
|
||||||
|
BluetoothService.connectDeviceWithTrust(modelData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,7 +666,7 @@ Item {
|
|||||||
if (bluetoothContextMenuWindow.deviceData.connected) {
|
if (bluetoothContextMenuWindow.deviceData.connected) {
|
||||||
bluetoothContextMenuWindow.deviceData.disconnect();
|
bluetoothContextMenuWindow.deviceData.disconnect();
|
||||||
} else {
|
} else {
|
||||||
bluetoothContextMenuWindow.deviceData.connect();
|
BluetoothService.connectDeviceWithTrust(bluetoothContextMenuWindow.deviceData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bluetoothContextMenuWindow.hide();
|
bluetoothContextMenuWindow.hide();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Singleton {
|
|||||||
return [];
|
return [];
|
||||||
|
|
||||||
return adapter.devices.values.filter((dev) => {
|
return adapter.devices.values.filter((dev) => {
|
||||||
return dev && dev.paired;
|
return dev && (dev.paired || dev.trusted);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
readonly property var allDevicesWithBattery: {
|
readonly property var allDevicesWithBattery: {
|
||||||
@@ -158,6 +158,18 @@ Singleton {
|
|||||||
|
|
||||||
return "signal_cellular_0_bar";
|
return "signal_cellular_0_bar";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDeviceBusy(device) {
|
||||||
|
if (!device) return false;
|
||||||
|
return device.pairing || device.state === BluetoothDeviceState.Disconnecting || device.state === BluetoothDeviceState.Connecting;
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectDeviceWithTrust(device) {
|
||||||
|
if (!device) return;
|
||||||
|
|
||||||
|
device.trusted = true;
|
||||||
|
device.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user