فهرست منبع

fix service startup + preview

tuanchris 3 ماه پیش
والد
کامیت
b44e504d4b
3فایلهای تغییر یافته به همراه47 افزوده شده و 31 حذف شده
  1. 31 20
      dune-weaver-touch/backend.py
  2. 12 4
      dune-weaver-touch/dune-weaver-touch.service
  3. 4 7
      dune-weaver-touch/install.sh

+ 31 - 20
dune-weaver-touch/backend.py

@@ -381,7 +381,7 @@ class Backend(QObject):
             # Extract just the filename from the path (remove any directory prefixes)
             clean_filename = fileName.split('/')[-1]  # Get last part of path
             print(f"🔍 Original fileName: {fileName}, clean filename: {clean_filename}")
-            
+
             # Check multiple possible locations for patterns directory
             # Use relative paths that work across different environments
             possible_dirs = [
@@ -389,29 +389,40 @@ class Backend(QObject):
                 Path("patterns"),     # Same level (for when running from main directory)
                 Path(__file__).parent.parent / "patterns"  # Dynamic path relative to backend.py
             ]
-            
+
             for patterns_dir in possible_dirs:
                 cache_dir = patterns_dir / "cached_images"
                 if cache_dir.exists():
-                    print(f"🔍 Checking preview cache directory: {cache_dir}")
-                    # Try different preview image extensions - PNG first for kiosk
-                    # First try with .thr suffix (e.g., pattern.thr.png)
-                    for ext in [".png", ".webp", ".jpg", ".jpeg"]:
-                        preview_file = cache_dir / (clean_filename + ext)
-                        print(f"🔍 Looking for preview: {preview_file}")
-                        if preview_file.exists():
-                            print(f"✅ Found preview: {preview_file}")
-                            return str(preview_file.absolute())
-                    
-                    # Then try without .thr suffix (e.g., pattern.png)
+                    print(f"🔍 Searching for preview in cache directory: {cache_dir}")
+
+                    # Extensions to try - PNG first for better kiosk compatibility
+                    extensions = [".png", ".webp", ".jpg", ".jpeg"]
+
+                    # Filenames to try - with and without .thr suffix
                     base_name = clean_filename.replace(".thr", "")
-                    for ext in [".png", ".webp", ".jpg", ".jpeg"]:
-                        preview_file = cache_dir / (base_name + ext)
-                        print(f"🔍 Looking for preview (no .thr): {preview_file}")
-                        if preview_file.exists():
-                            print(f"✅ Found preview: {preview_file}")
-                            return str(preview_file.absolute())
-            
+                    filenames_to_try = [clean_filename, base_name]
+
+                    # Try direct path in cache_dir first (fastest)
+                    for filename in filenames_to_try:
+                        for ext in extensions:
+                            preview_file = cache_dir / (filename + ext)
+                            if preview_file.exists():
+                                print(f"✅ Found preview (direct): {preview_file}")
+                                return str(preview_file.absolute())
+
+                    # If not found directly, search recursively through subdirectories
+                    print(f"🔍 Searching recursively in {cache_dir}...")
+                    for filename in filenames_to_try:
+                        for ext in extensions:
+                            target_name = filename + ext
+                            # Use rglob to search recursively
+                            matches = list(cache_dir.rglob(target_name))
+                            if matches:
+                                # Return the first match found
+                                preview_file = matches[0]
+                                print(f"✅ Found preview (recursive): {preview_file}")
+                                return str(preview_file.absolute())
+
             print("❌ No preview image found")
             return ""
         except Exception as e:

+ 12 - 4
dune-weaver-touch/dune-weaver-touch.service

@@ -1,7 +1,10 @@
 [Unit]
 Description=Dune Weaver Touch Interface
-After=graphical.target
-Wants=graphical.target
+After=multi-user.target network-online.target
+Wants=network-online.target
+# Wait for DRM/KMS devices to be ready
+After=systemd-udev-settle.service
+Wants=systemd-udev-settle.service
 
 [Service]
 Type=simple
@@ -13,9 +16,14 @@ Environment=QT_QPA_PLATFORM=eglfs
 Environment=QT_QPA_EGLFS_ALWAYS_SET_MODE=1
 Environment=QT_QPA_EGLFS_HIDECURSOR=1
 Environment=QT_QPA_FB_HIDECURSOR=1
+Environment=QT_QPA_EGLFS_INTEGRATION=eglfs_kms
+Environment=QT_QPA_EGLFS_KMS_ATOMIC=1
 ExecStart=/home/pi/dune-weaver-touch/venv/bin/python /home/pi/dune-weaver-touch/main.py
 Restart=always
-RestartSec=5
+RestartSec=10
+# Restart on failure with backoff
+StartLimitInterval=200
+StartLimitBurst=5
 
 [Install]
-WantedBy=graphical.target
+WantedBy=multi-user.target

+ 4 - 7
dune-weaver-touch/install.sh

@@ -52,22 +52,19 @@ install_scripts() {
 # Function to setup systemd service
 setup_systemd() {
     echo "🚀 Setting up systemd service..."
-    
+
     # Update paths in the service file
     sed "s|/home/pi/dune-weaver-touch|$SCRIPT_DIR|g" "$SCRIPT_DIR/dune-weaver-touch.service" > /tmp/dune-weaver-touch.service
     sed -i "s|User=pi|User=$ACTUAL_USER|g" /tmp/dune-weaver-touch.service
     sed -i "s|Group=pi|Group=$ACTUAL_USER|g" /tmp/dune-weaver-touch.service
-    
-    # Ensure the ExecStart uses the venv python
-    sed -i "s|ExecStart=.*python.*|ExecStart=$SCRIPT_DIR/venv/bin/python $SCRIPT_DIR/main.py|g" /tmp/dune-weaver-touch.service
-    
+
     # Copy service file
     cp /tmp/dune-weaver-touch.service /etc/systemd/system/
-    
+
     # Enable service
     systemctl daemon-reload
     systemctl enable dune-weaver-touch.service
-    
+
     echo "   🚀 Systemd service installed and enabled"
 }