EVEN MORE DELTARUNE

This commit is contained in:
2026-03-24 23:08:26 +02:00
parent f3bddf0da5
commit 568c26db07
2 changed files with 82 additions and 39 deletions

Binary file not shown.

View File

@@ -24,12 +24,14 @@ PanelWindow {
aboveWindows: true aboveWindows: true
focusable: true focusable: true
property string bluetoothTargetName: "JBL Tune 525BT" property var bluetoothTargetNames: ["JBL Tune 525BT", "JBL GO"]
property int bluetoothTimeoutMs: 5000 property int bluetoothConnectAttemptMs: 3000
property bool waitingForBluetooth: true property bool waitingForBluetooth: true
property bool animationLaunchScheduled: false property bool animationLaunchScheduled: false
property bool animationStarted: false property bool animationStarted: false
property bool bluetoothConnectRequested: false property bool bluetoothConnectRequested: false
property int bluetoothTargetAttemptIndex: 0
property string bluetoothActiveTargetName: ""
function bluetoothModelCount() { function bluetoothModelCount() {
if (bluetoothDeviceRepeater) if (bluetoothDeviceRepeater)
@@ -54,44 +56,67 @@ PanelWindow {
return ""; return "";
} }
function findTargetBluetoothDevice() { function findBluetoothDeviceByName(targetName) {
for (var i = 0; i < bluetoothModelCount(); i++) { for (var i = 0; i < bluetoothModelCount(); i++) {
var device = bluetoothDeviceAt(i); var device = bluetoothDeviceAt(i);
var deviceName = bluetoothDeviceName(device); var deviceName = bluetoothDeviceName(device);
console.log("Startup BT: candidate", i, deviceName, device ? Boolean(device.connected) : false); console.log("Startup BT: candidate", i, deviceName, device ? Boolean(device.connected) : false);
if (deviceName === bluetoothTargetName) if (deviceName === targetName)
return device; return device;
} }
console.log("Startup BT: target not found", bluetoothTargetName, "count", bluetoothModelCount()); console.log("Startup BT: target not found", targetName, "count", bluetoothModelCount());
return null; return null;
} }
function findConnectedPreferredBluetoothDevice() {
for (var i = 0; i < bluetoothTargetNames.length; i++) {
var device = findBluetoothDeviceByName(bluetoothTargetNames[i]);
if (device && device.connected)
return device;
}
return null;
}
function resetBluetoothAttemptState() {
bluetoothConnectRequested = false;
bluetoothTargetAttemptIndex = 0;
bluetoothActiveTargetName = "";
bluetoothConnectAttemptTimer.stop();
}
function maybeStartBluetoothOrSkip() { function maybeStartBluetoothOrSkip() {
console.log("Startup BT: maybeStartBluetoothOrSkip", "waiting", waitingForBluetooth, "requested", bluetoothConnectRequested); console.log("Startup BT: maybeStartBluetoothOrSkip", "waiting", waitingForBluetooth, "requested", bluetoothConnectRequested, "active", bluetoothActiveTargetName, "attemptIndex", bluetoothTargetAttemptIndex);
if (!waitingForBluetooth) if (!waitingForBluetooth)
return; return;
const device = findTargetBluetoothDevice(); const connectedDevice = findConnectedPreferredBluetoothDevice();
if (!device) { if (connectedDevice) {
console.log("Startup BT: no matching device yet"); console.log("Startup BT: preferred device connected, starting animation", bluetoothDeviceName(connectedDevice));
return;
}
console.log("Startup BT: matched device", bluetoothDeviceName(device), "connected", Boolean(device.connected));
if (device.connected) {
console.log("Startup BT: already connected, starting animation");
beginAnimation(); beginAnimation();
return; return;
} }
if (!bluetoothConnectRequested) { if (bluetoothConnectRequested) {
bluetoothConnectRequested = true; console.log("Startup BT: connect already requested, waiting on", bluetoothActiveTargetName);
console.log("Startup BT: requesting connect", bluetoothDeviceName(device)); return;
device.connect();
} else {
console.log("Startup BT: connect already requested, waiting");
} }
for (var i = bluetoothTargetAttemptIndex; i < bluetoothTargetNames.length; i++) {
var targetName = bluetoothTargetNames[i];
var targetDevice = findBluetoothDeviceByName(targetName);
if (!targetDevice)
continue;
bluetoothConnectRequested = true;
bluetoothTargetAttemptIndex = i;
bluetoothActiveTargetName = targetName;
bluetoothConnectAttemptTimer.restart();
console.log("Startup BT: requesting connect", targetName);
targetDevice.connect();
return;
}
console.log("Startup BT: no preferred devices available yet");
} }
function beginAnimation() { function beginAnimation() {
@@ -100,7 +125,7 @@ PanelWindow {
return; return;
waitingForBluetooth = false; waitingForBluetooth = false;
bluetoothRetryTimer.stop(); bluetoothRetryTimer.stop();
bluetoothTimeoutTimer.stop(); bluetoothConnectAttemptTimer.stop();
animationLaunchScheduled = true; animationLaunchScheduled = true;
startupDelayTimer.restart(); startupDelayTimer.restart();
} }
@@ -127,7 +152,7 @@ PanelWindow {
} }
Component.onCompleted: { Component.onCompleted: {
console.log("Startup: overlay completed", "btCount", bluetoothModelCount(), "target", bluetoothTargetName); console.log("Startup: overlay completed", "btCount", bluetoothModelCount(), "targets", JSON.stringify(bluetoothTargetNames));
maybeStartBluetoothOrSkip(); maybeStartBluetoothOrSkip();
} }
@@ -161,7 +186,7 @@ PanelWindow {
function onCountChanged() { function onCountChanged() {
if (overlay.waitingForBluetooth) { if (overlay.waitingForBluetooth) {
console.log("Startup BT: devices count changed", overlay.bluetoothModelCount(), "repeater", bluetoothDeviceRepeater.count); console.log("Startup BT: devices count changed", overlay.bluetoothModelCount(), "repeater", bluetoothDeviceRepeater.count);
overlay.bluetoothConnectRequested = false; overlay.resetBluetoothAttemptState();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
@@ -169,7 +194,7 @@ PanelWindow {
function onModelReset() { function onModelReset() {
if (overlay.waitingForBluetooth) { if (overlay.waitingForBluetooth) {
console.log("Startup BT: devices model reset"); console.log("Startup BT: devices model reset");
overlay.bluetoothConnectRequested = false; overlay.resetBluetoothAttemptState();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
@@ -177,7 +202,7 @@ PanelWindow {
function onRowsInserted() { function onRowsInserted() {
if (overlay.waitingForBluetooth) { if (overlay.waitingForBluetooth) {
console.log("Startup BT: device rows inserted"); console.log("Startup BT: device rows inserted");
overlay.bluetoothConnectRequested = false; overlay.resetBluetoothAttemptState();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
@@ -185,7 +210,7 @@ PanelWindow {
function onRowsRemoved() { function onRowsRemoved() {
if (overlay.waitingForBluetooth) { if (overlay.waitingForBluetooth) {
console.log("Startup BT: device rows removed"); console.log("Startup BT: device rows removed");
overlay.bluetoothConnectRequested = false; overlay.resetBluetoothAttemptState();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
@@ -209,14 +234,17 @@ PanelWindow {
function onConnectedChanged() { function onConnectedChanged() {
console.log("Startup BT: connected changed", overlay.bluetoothDeviceName(device), Boolean(device ? device.connected : false)); console.log("Startup BT: connected changed", overlay.bluetoothDeviceName(device), Boolean(device ? device.connected : false));
if (overlay.waitingForBluetooth) if (overlay.waitingForBluetooth) {
if (Boolean(device ? device.connected : false))
overlay.bluetoothConnectAttemptTimer.stop();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
}
} }
function onNameChanged() { function onNameChanged() {
if (overlay.waitingForBluetooth) { if (overlay.waitingForBluetooth) {
console.log("Startup BT: name changed", overlay.bluetoothDeviceName(device)); console.log("Startup BT: name changed", overlay.bluetoothDeviceName(device));
overlay.bluetoothConnectRequested = false; overlay.resetBluetoothAttemptState();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
@@ -224,7 +252,7 @@ PanelWindow {
function onDeviceNameChanged() { function onDeviceNameChanged() {
if (overlay.waitingForBluetooth) { if (overlay.waitingForBluetooth) {
console.log("Startup BT: deviceName changed", overlay.bluetoothDeviceName(device)); console.log("Startup BT: deviceName changed", overlay.bluetoothDeviceName(device));
overlay.bluetoothConnectRequested = false; overlay.resetBluetoothAttemptState();
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
@@ -238,7 +266,7 @@ PanelWindow {
autoPlay: false autoPlay: false
videoOutput: videoOutput videoOutput: videoOutput
playbackRate: 1 playbackRate: 1
audioOutput: AudioOutput {} audioOutput: startupAudioOutput
onPlaybackStateChanged: a => { onPlaybackStateChanged: a => {
console.log("Startup: playback state changed", player.playbackState); console.log("Startup: playback state changed", player.playbackState);
if (player.playbackState === MediaPlayer.StoppedState) if (player.playbackState === MediaPlayer.StoppedState)
@@ -248,7 +276,7 @@ PanelWindow {
Timer { Timer {
id: startupDelayTimer id: startupDelayTimer
interval: 1000 interval: 1500
repeat: false repeat: false
onTriggered: { onTriggered: {
console.log("Startup: startup delay elapsed, playing video"); console.log("Startup: startup delay elapsed, playing video");
@@ -270,22 +298,37 @@ PanelWindow {
return; return;
} }
console.log("Startup BT: retry timer fired"); console.log("Startup BT: retry timer fired");
overlay.bluetoothConnectRequested = false;
overlay.maybeStartBluetoothOrSkip(); overlay.maybeStartBluetoothOrSkip();
} }
} }
Timer { Timer {
id: bluetoothTimeoutTimer id: bluetoothConnectAttemptTimer
interval: overlay.bluetoothTimeoutMs interval: overlay.bluetoothConnectAttemptMs
running: true running: false
repeat: false repeat: false
onTriggered: { onTriggered: {
console.log("Startup BT: timeout reached", overlay.bluetoothTimeoutMs); console.log("Startup BT: connect attempt timed out", overlay.bluetoothActiveTargetName);
overlay.beginAnimation(); overlay.bluetoothConnectRequested = false;
overlay.bluetoothActiveTargetName = "";
overlay.bluetoothTargetAttemptIndex = Math.min(overlay.bluetoothTargetAttemptIndex + 1, overlay.bluetoothTargetNames.length);
overlay.maybeStartBluetoothOrSkip();
} }
} }
MediaDevices {
id: mediaDevices
onDefaultAudioOutputChanged: {
console.log("Startup Audio: default output changed", mediaDevices.defaultAudioOutput.description);
startupAudioOutput.device = mediaDevices.defaultAudioOutput;
}
}
AudioOutput {
id: startupAudioOutput
device: mediaDevices.defaultAudioOutput
}
VideoOutput { VideoOutput {
id: videoOutput id: videoOutput
anchors.fill: parent anchors.fill: parent