fix: ID Duplikate und Sync-Aufrufe behoben, Settings inline integriert

- Doppelte Timer-ID in Main.qml (initTimer) durch Umbenennung behoben
- Settings.qml in Main.qml inline integriert
- Sync-Aufrufe durch async Callbacks ersetzt, um Deadlocks zu vermeiden
- addImportPath für PyOtherSide wiederhergestellt
- color-Property mit Fallback-Wert für Theme-Palette
- Version auf 1.0.7 erhöht

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
darklithium
2026-06-03 02:25:44 +02:00
parent f4a0e46e9f
commit 4c5268a528
3 changed files with 87 additions and 320 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "fortunecookie.darklithium",
"title": "Fortune Cookie",
"version": "1.0.6",
"version": "1.0.7",
"description": "Glückskeks App mit Sprüchen, Musik und einfacher Listenverwaltung",
"maintainer": "darklithium <dev@darklithium.de>",
"architecture": "all",
+86 -123
View File
@@ -14,12 +14,14 @@ MainView {
theme.name: "Lomiri.Components.Themes.SuruDark"
// ====================================================================
// PROPERTIES (am Anfang definieren!)
// PROPERTIES
// ====================================================================
property bool fortuneOpened: false
property string currentFortune: ""
property bool musicPlaying: false
property bool appInitialized: false
property real musicVolume: 0.5
property real crackVolume: 1.0
Python {
id: py
@@ -31,26 +33,15 @@ MainView {
}
}
property real musicVolume: 0.5
property real crackVolume: 1.0
// Funktionen zum Setzen der Lautstärke
function setMusicVolume(volume) {
root.musicVolume = volume;
py.call("fortunecookie.set_music_volume", [volume]);
}
function setCrackVolume(volume) {
root.crackVolume = volume;
py.call("fortunecookie.set_crack_volume", [volume]);
}
// Funktionen
function reloadFortune() {
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
currentFortuneLabel.text = currentFortune;
if (fortuneOpened) {
currentFortuneLabel.visible = true;
}
py.call("fortunecookie.get_current_fortune", [], function(result) {
currentFortune = result;
currentFortuneLabel.text = currentFortune;
if (fortuneOpened) {
currentFortuneLabel.visible = true;
}
});
}
MediaPlayer {
@@ -96,59 +87,43 @@ MainView {
]
}
// ============================================================
// INITIALISIERUNGS-TIMER
// ============================================================
Timer {
id: initTimer
interval: 1000
running: true
repeat: false
onTriggered: {
Component.onCompleted: {
// Verzögerte Initialisierung
Qt.callLater(function() {
try {
currentFortune = py.call_sync("fortunecookie.get_initial_fortune", []);
currentFortuneLabel.text = currentFortune;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
// Initialisierung mit async Aufrufen
py.call("fortunecookie.get_initial_fortune", [], function(result) {
currentFortune = result;
currentFortuneLabel.text = currentFortune;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
});
// Musik-Status laden
musicPlaying = py.call_sync("fortunecookie.get_music_enabled", []);
console.log("DEBUG QML: musicPlaying geladen: " + musicPlaying);
py.call("fortunecookie.get_music_enabled", [], function(result) {
musicPlaying = result;
console.log("DEBUG QML: musicPlaying geladen: " + musicPlaying);
if (musicPlaying) {
mediaPlayer.play();
}
});
// MediaPlayer Zustand synchronisieren
if (musicPlaying) {
mediaPlayer.play();
}
// Volumes laden
py.call("fortunecookie.get_music_volume", [], function(result) {
root.musicVolume = result;
mediaPlayer.volume = result;
});
// Volumes laden und Properties setzen
var musicVol = py.call_sync("fortunecookie.get_music_volume", []);
var crackVol = py.call_sync("fortunecookie.get_crack_volume", []);
root.musicVolume = musicVol;
root.crackVolume = crackVol;
py.call("fortunecookie.get_crack_volume", [], function(result) {
root.crackVolume = result;
crackMediaPlayer.volume = result;
});
appInitialized = true;
} catch (e) {
console.log("ERROR QML: Initialisierung fehlgeschlagen: " + e);
}
}
}
// Timer zum regelmäßigen Prüfen der Lautstärke-Einstellungen
Timer {
id: volumeCheckTimer
interval: 200 // Prüfen alle 200ms
running: true
repeat: true
onTriggered: {
var musicVol = py.call_sync("fortunecookie.get_music_volume", []);
var crackVol = py.call_sync("fortunecookie.get_crack_volume", []);
if (musicVol !== root.musicVolume) {
root.musicVolume = musicVol;
}
if (crackVol !== root.crackVolume) {
root.crackVolume = crackVol;
}
}
});
}
Image {
@@ -170,10 +145,12 @@ MainView {
py.call("fortunecookie.open_fortune", [], function() {
crackMediaPlayer.play();
fortuneOpened = true;
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
currentFortuneLabel.text = currentFortune;
currentFortuneLabel.visible = true;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_open2.png");
py.call("fortunecookie.get_current_fortune", [], function(result) {
currentFortune = result;
currentFortuneLabel.text = currentFortune;
currentFortuneLabel.visible = true;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_open2.png");
});
});
}
}
@@ -188,10 +165,12 @@ MainView {
py.call("fortunecookie.open_fortune", [], function() {
crackMediaPlayer.play();
fortuneOpened = true;
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
currentFortuneLabel.text = currentFortune;
currentFortuneLabel.visible = true;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_open2.png");
py.call("fortunecookie.get_current_fortune", [], function(result) {
currentFortune = result;
currentFortuneLabel.text = currentFortune;
currentFortuneLabel.visible = true;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_open2.png");
});
});
} else {
fortuneOpened = false;
@@ -225,17 +204,17 @@ MainView {
onClicked: {
py.call("fortunecookie.get_new_fortune", [], function() {
fortuneOpened = false;
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
currentFortuneLabel.text = currentFortune;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
py.call("fortunecookie.get_current_fortune", [], function(result) {
currentFortune = result;
currentFortuneLabel.text = currentFortune;
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
});
});
}
}
}
// ================================================================
// MUSIK-BUTTON
// ================================================================
Label {
id: musicButton
anchors {
@@ -249,7 +228,7 @@ MainView {
fontSize: "xxx-large"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: theme.palette.normalText
color: theme.palette.normalText || "white"
visible: true
MouseArea {
@@ -278,52 +257,44 @@ MainView {
id: settingsPage
objectName: 'settingsPage'
property bool settingsInitialized: false
property var currentFortuneList: "classic"
property real musicVolume: 0.5
property real crackVolume: 1.0
header: PageHeader {
title: "Einstellungen"
}
// Timer für PyOtherSide Initialisierung
Timer {
id: initTimer
interval: 1000
running: true
repeat: false
onTriggered: {
Component.onCompleted: {
// Verzögerte Initialisierung
Qt.callLater(function() {
try {
// Einstellungen laden
currentFortuneList = py.call_sync("fortunecookie.get_current_fortune_list", []);
musicVolume = py.call_sync("fortunecookie.get_music_volume", []);
crackVolume = py.call_sync("fortunecookie.get_crack_volume", []);
py.call("fortunecookie.get_current_fortune_list", [], function(currentFortuneList) {
py.call("fortunecookie.get_music_volume", [], function(musicVol) {
py.call("fortunecookie.get_crack_volume", [], function(crackVol) {
// Slider Werte setzen
musicVolumeSlider.value = musicVol;
crackVolumeSlider.value = crackVol;
// Slider Werte setzen
musicVolumeSlider.value = musicVolume;
crackVolumeSlider.value = crackVolume;
// Spruchlisten ComboBox füllen
py.call("fortunecookie.get_fortune_lists_with_description", [], function(lists) {
fortuneListCombo.model = lists;
// Spruchlisten ComboBox füllen
var lists = py.call_sync("fortunecookie.get_fortune_lists_with_description", []);
fortuneListCombo.model = lists;
// Aktuelle Liste auswählen (vergleiche nur den Listennamen, nicht die Beschreibung)
for (var i = 0; i < fortuneListCombo.count; i++) {
var text = fortuneListCombo.textAt(i);
var listName = text.split(" - ")[0];
if (listName === currentFortuneList) {
fortuneListCombo.currentIndex = i;
break;
}
}
settingsInitialized = true;
// Aktuelle Liste auswählen
for (var i = 0; i < fortuneListCombo.count; i++) {
var text = fortuneListCombo.textAt(i);
var listName = text.split(" - ")[0];
if (listName === currentFortuneList) {
fortuneListCombo.currentIndex = i;
break;
}
}
});
});
});
});
} catch (e) {
console.log("ERROR: Einstellungen nicht geladen: " + e);
}
}
});
}
ColumnLayout {
@@ -337,10 +308,7 @@ MainView {
Layout.preferredHeight: units.gu(2)
}
// ============================================================
// SPRUCHLISTEN-AUSWAHL
// ============================================================
Label {
text: "Spruchliste:"
Layout.fillWidth: true
@@ -354,18 +322,15 @@ MainView {
onActivated: {
var newListFull = fortuneListCombo.currentText;
// Extrahiere den Listennamen (Teil vor " - ")
var newList = newListFull.split(" - ")[0];
py.call("fortunecookie.set_fortune_list", [newList], function() {
console.log("Spruchliste gewaehlt: " + newList);
reloadFortune();
});
}
}
// ============================================================
// LAUTSTÄRKE - MUSIK
// ============================================================
Label {
text: "Musik-Lautstärke:"
Layout.fillWidth: true
@@ -386,6 +351,8 @@ MainView {
onValueChanged: {
var volume = musicVolumeSlider.value;
root.musicVolume = volume;
mediaPlayer.volume = volume;
py.call("fortunecookie.set_music_volume", [volume]);
musicVolumeLabel.text = Math.round(volume * 100) + "%";
}
@@ -400,10 +367,7 @@ MainView {
}
}
// ============================================================
// LAUTSTÄRKE - KNACK-GERÄUSCH
// ============================================================
Label {
text: "Knack-Lautstärke:"
Layout.fillWidth: true
@@ -424,6 +388,8 @@ MainView {
onValueChanged: {
var volume = crackVolumeSlider.value;
root.crackVolume = volume;
crackMediaPlayer.volume = volume;
py.call("fortunecookie.set_crack_volume", [volume]);
crackVolumeLabel.text = Math.round(volume * 100) + "%";
}
@@ -438,10 +404,7 @@ MainView {
}
}
// ============================================================
// ZURÜCK-BUTTON
// ============================================================
Item {
Layout.fillWidth: true
Layout.preferredHeight: units.gu(10)
-196
View File
@@ -1,196 +0,0 @@
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import QtMultimedia 5.0
import Lomiri.Components 1.3
import Lomiri.Components.Popups 1.3
import io.thp.pyotherside 1.4
Page {
id: settingsPage
objectName: 'settingsPage'
property bool settingsInitialized: false
property var currentFortuneList: "classic"
property real musicVolume: 0.5
property real crackVolume: 1.0
header: PageHeader {
title: "Einstellungen"
}
// Timer für PyOtherSide Initialisierung
Timer {
id: initTimer
interval: 1000
running: true
repeat: false
onTriggered: {
try {
// Einstellungen laden
currentFortuneList = py.call_sync("fortunecookie.get_current_fortune_list", []);
musicVolume = py.call_sync("fortunecookie.get_music_volume", []);
crackVolume = py.call_sync("fortunecookie.get_crack_volume", []);
// Slider Werte setzen
musicVolumeSlider.value = musicVolume;
crackVolumeSlider.value = crackVolume;
// Spruchlisten ComboBox füllen
var lists = py.call_sync("fortunecookie.get_fortune_lists_with_description", []);
fortuneListCombo.model = lists;
// Aktuelle Liste auswählen (vergleiche nur den Listennamen, nicht die Beschreibung)
for (var i = 0; i < fortuneListCombo.count; i++) {
var text = fortuneListCombo.textAt(i);
var listName = text.split(" - ")[0];
if (listName === currentFortuneList) {
fortuneListCombo.currentIndex = i;
break;
}
}
settingsInitialized = true;
} catch (e) {
console.log("ERROR: Einstellungen nicht geladen: " + e);
}
}
}
ColumnLayout {
anchors.fill: parent
anchors.margins: units.gu(2)
spacing: units.gu(2)
// Spacer für Header
Item {
Layout.fillWidth: true
Layout.preferredHeight: units.gu(2)
}
// ============================================================
// SPRUCHLISTEN-AUSWAHL
// ============================================================
Label {
text: "Spruchliste:"
Layout.fillWidth: true
fontSize: "large"
}
ComboBox {
id: fortuneListCombo
Layout.fillWidth: true
Layout.preferredHeight: units.gu(8)
onActivated: {
var newListFull = fortuneListCombo.currentText;
// Extrahiere den Listennamen (Teil vor " - ")
var newList = newListFull.split(" - ")[0];
py.call("fortunecookie.set_fortune_list", [newList], function() {
console.log("Spruchliste gewaehlt: " + newList);
});
}
}
// ============================================================
// LAUTSTÄRKE - MUSIK
// ============================================================
Label {
text: "Musik-Lautstärke:"
Layout.fillWidth: true
fontSize: "large"
}
RowLayout {
Layout.fillWidth: true
spacing: units.gu(2)
Slider {
id: musicVolumeSlider
Layout.fillWidth: true
minimumValue: 0.0
maximumValue: 1.0
stepSize: 0.1
value: 0.5
showValue: false
onValueChanged: {
var volume = musicVolumeSlider.value;
py.call("fortunecookie.set_music_volume", [volume]);
musicVolumeLabel.text = Math.round(volume * 100) + "%";
}
}
Label {
id: musicVolumeLabel
text: Math.round(musicVolumeSlider.value * 100) + "%"
width: units.gu(10)
horizontalAlignment: Text.AlignHCenter
fontSize: "medium"
}
}
// ============================================================
// LAUTSTÄRKE - KNACK-GERÄUSCH
// ============================================================
Label {
text: "Knack-Lautstärke:"
Layout.fillWidth: true
fontSize: "large"
}
RowLayout {
Layout.fillWidth: true
spacing: units.gu(2)
Slider {
id: crackVolumeSlider
Layout.fillWidth: true
minimumValue: 0.0
maximumValue: 1.0
stepSize: 0.1
value: 1.0
showValue: false
onValueChanged: {
var volume = crackVolumeSlider.value;
py.call("fortunecookie.set_crack_volume", [volume]);
crackVolumeLabel.text = Math.round(volume * 100) + "%";
}
}
Label {
id: crackVolumeLabel
text: Math.round(crackVolumeSlider.value * 100) + "%"
width: units.gu(10)
horizontalAlignment: Text.AlignHCenter
fontSize: "medium"
}
}
// ============================================================
// ZURÜCK-BUTTON
// ============================================================
Item {
Layout.fillWidth: true
Layout.preferredHeight: units.gu(10)
}
Button {
text: "Zurück"
Layout.fillWidth: false
Layout.preferredWidth: units.gu(20)
Layout.preferredHeight: units.gu(8)
Layout.alignment: Qt.AlignHCenter
onClicked: {
mainStack.currentIndex = 0;
}
}
}
}