Explorar el Código

properly exit app

tuanchris hace 3 meses
padre
commit
e3dbfb2581

+ 42 - 20
dune-weaver-touch/main.py

@@ -3,6 +3,7 @@ import os
 import asyncio
 import asyncio
 import logging
 import logging
 import time
 import time
+import signal
 from pathlib import Path
 from pathlib import Path
 from PySide6.QtCore import QUrl, QTimer, QObject, QEvent
 from PySide6.QtCore import QUrl, QTimer, QObject, QEvent
 from PySide6.QtGui import QGuiApplication, QTouchEvent, QMouseEvent
 from PySide6.QtGui import QGuiApplication, QTouchEvent, QMouseEvent
@@ -36,27 +37,34 @@ class FirstTouchFilter(QObject):
 
 
     def eventFilter(self, obj, event):
     def eventFilter(self, obj, event):
         """Filter out the first touch after idle period"""
         """Filter out the first touch after idle period"""
-        event_type = event.type()
+        try:
+            event_type = event.type()
 
 
-        # Handle touch events
-        if event_type == QEvent.Type.TouchBegin:
-            current_time = time.time()
-            time_since_last_touch = current_time - self.last_touch_time
+            # Handle touch events
+            if event_type == QEvent.Type.TouchBegin:
+                current_time = time.time()
+                time_since_last_touch = current_time - self.last_touch_time
 
 
-            # If it's been more than threshold since last touch, ignore this one
-            if time_since_last_touch > self.idle_threshold:
-                logger.debug(f"👆 Ignoring wake-up touch (idle for {time_since_last_touch:.1f}s)")
-                self.last_touch_time = current_time
-                return True  # Filter out (ignore) this event
+                # If it's been more than threshold since last touch, ignore this one
+                if time_since_last_touch > self.idle_threshold:
+                    logger.debug(f"👆 Ignoring wake-up touch (idle for {time_since_last_touch:.1f}s)")
+                    self.last_touch_time = current_time
+                    return True  # Filter out (ignore) this event
 
 
-            self.last_touch_time = current_time
+                self.last_touch_time = current_time
 
 
-        elif event_type in (QEvent.Type.TouchUpdate, QEvent.Type.TouchEnd):
-            # Update last touch time for any touch activity
-            self.last_touch_time = time.time()
+            elif event_type in (QEvent.Type.TouchUpdate, QEvent.Type.TouchEnd):
+                # Update last touch time for any touch activity
+                self.last_touch_time = time.time()
 
 
-        # Pass through the event
-        return False
+            # Pass through the event
+            return False
+        except KeyboardInterrupt:
+            # Re-raise KeyboardInterrupt to allow clean shutdown
+            raise
+        except Exception as e:
+            logger.error(f"Error in eventFilter: {e}")
+            return False
 
 
 async def startup_tasks():
 async def startup_tasks():
     """Run async startup tasks"""
     """Run async startup tasks"""
@@ -119,10 +127,24 @@ def main():
     startup_timer.timeout.connect(schedule_startup)
     startup_timer.timeout.connect(schedule_startup)
     startup_timer.setSingleShot(True)
     startup_timer.setSingleShot(True)
     startup_timer.start(100)  # 100ms delay
     startup_timer.start(100)  # 100ms delay
-    
-    with loop:
-        loop.run_forever()
-    
+
+    # Setup signal handlers for clean shutdown
+    def signal_handler(signum, frame):
+        logger.info("🛑 Received shutdown signal, exiting...")
+        loop.stop()
+        app.quit()
+
+    signal.signal(signal.SIGINT, signal_handler)
+    signal.signal(signal.SIGTERM, signal_handler)
+
+    try:
+        with loop:
+            loop.run_forever()
+    except KeyboardInterrupt:
+        logger.info("🛑 KeyboardInterrupt received, shutting down...")
+    finally:
+        loop.close()
+
     return 0
     return 0
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":

+ 1 - 1
dune-weaver-touch/qml/components/ThemeManager.qml

@@ -45,7 +45,7 @@ QtObject {
     property color placeholderText: darkMode ? "#606060" : "#cccccc"
     property color placeholderText: darkMode ? "#606060" : "#cccccc"
 
 
     // Preview background - lighter in dark mode for better pattern visibility
     // Preview background - lighter in dark mode for better pattern visibility
-    property color previewBackground: darkMode ? "#505050" : "#f8f9fa"
+    property color previewBackground: darkMode ? "#707070" : "#f8f9fa"
 
 
     // Shadow colors
     // Shadow colors
     property color shadowColor: darkMode ? "#000000" : "#00000020"
     property color shadowColor: darkMode ? "#000000" : "#00000020"

+ 1 - 1
dune-weaver-touch/qml/pages/ExecutionPage.qml

@@ -384,7 +384,7 @@ Page {
                                         MouseArea {
                                         MouseArea {
                                             id: skipMouseArea
                                             id: skipMouseArea
                                             anchors.fill: parent
                                             anchors.fill: parent
-                                            enabled: backend && backend.currentFile !== ""
+                                            enabled: backend
                                             onClicked: {
                                             onClicked: {
                                                 if (backend) {
                                                 if (backend) {
                                                     backend.skipPattern()
                                                     backend.skipPattern()

+ 1 - 0
dune-weaver-touch/qml/pages/ModernPatternListPage.qml

@@ -99,6 +99,7 @@ Page {
                             Layout.fillWidth: true
                             Layout.fillWidth: true
                             placeholderText: searchExpanded ? "Search patterns... (press Enter)" : "Search"
                             placeholderText: searchExpanded ? "Search patterns... (press Enter)" : "Search"
                             font.pixelSize: 14
                             font.pixelSize: 14
+                            color: Components.ThemeManager.textPrimary
                             visible: searchExpanded || text.length > 0
                             visible: searchExpanded || text.length > 0
                             
                             
                             property string lastSearchText: ""
                             property string lastSearchText: ""