tuanchris 4 месяцев назад
Родитель
Сommit
50d868eb96

+ 12 - 14
dune-weaver-touch/backend.py

@@ -457,23 +457,21 @@ class Backend(QObject):
                 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
+                    # Use PNG format only for kiosk compatibility
                     # 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())
-                    
+                    preview_file = cache_dir / (clean_filename + ".png")
+                    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)
                     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())
+                    preview_file = cache_dir / (base_name + ".png")
+                    print(f"🔍 Looking for preview (no .thr): {preview_file}")
+                    if preview_file.exists():
+                        print(f"✅ Found preview: {preview_file}")
+                        return str(preview_file.absolute())
             
             print("❌ No preview image found")
             return ""

+ 41 - 5
dune-weaver-touch/install.sh

@@ -108,7 +108,7 @@ setup_kiosk_optimizations() {
 # Function to setup Python virtual environment and install dependencies
 setup_python_environment() {
     echo "🐍 Setting up Python virtual environment..."
-    
+
     # Create virtual environment if it doesn't exist
     if [ ! -d "$SCRIPT_DIR/venv" ]; then
         echo "   📦 Creating virtual environment..."
@@ -120,30 +120,65 @@ setup_python_environment() {
     else
         echo "   ℹ️  Virtual environment already exists"
     fi
-    
+
     # Activate virtual environment and install dependencies
     echo "   📦 Installing Python dependencies in virtual environment..."
     "$SCRIPT_DIR/venv/bin/python" -m pip install --upgrade pip
-    
+
     # Install from requirements.txt if it exists, otherwise install manually
     if [ -f "$SCRIPT_DIR/requirements.txt" ]; then
         "$SCRIPT_DIR/venv/bin/pip" install -r "$SCRIPT_DIR/requirements.txt"
     else
         "$SCRIPT_DIR/venv/bin/pip" install PySide6 requests
     fi
-    
+
     # Change ownership to the actual user (not root)
     chown -R "$ACTUAL_USER:$ACTUAL_USER" "$SCRIPT_DIR/venv"
-    
+
     echo "   🐍 Python virtual environment ready"
 }
 
+# Function to setup patterns directory permissions
+setup_patterns_permissions() {
+    echo "📁 Setting up patterns directory permissions..."
+
+    # Determine patterns directory location (parent of touch app)
+    PATTERNS_DIR="$(dirname "$SCRIPT_DIR")/patterns"
+
+    if [ -d "$PATTERNS_DIR" ]; then
+        echo "   📂 Found patterns directory: $PATTERNS_DIR"
+
+        # Ensure cached_images directory exists
+        CACHE_DIR="$PATTERNS_DIR/cached_images"
+        if [ ! -d "$CACHE_DIR" ]; then
+            echo "   📁 Creating cached_images directory..."
+            mkdir -p "$CACHE_DIR"
+        fi
+
+        # Set ownership to the user who will run the service
+        echo "   🔑 Setting ownership to $ACTUAL_USER..."
+        chown -R "$ACTUAL_USER:$ACTUAL_USER" "$CACHE_DIR"
+
+        # Set permissions: user can read/write, group can read, others can read
+        echo "   🔒 Setting permissions (755 for dirs, 644 for files)..."
+        find "$CACHE_DIR" -type d -exec chmod 755 {} \;
+        find "$CACHE_DIR" -type f -exec chmod 644 {} \;
+
+        echo "   ✅ Patterns cache directory permissions configured"
+    else
+        echo "   ⚠️  Patterns directory not found at $PATTERNS_DIR"
+        echo "   ℹ️  If patterns exist elsewhere, manually run:"
+        echo "      sudo chown -R $ACTUAL_USER:$ACTUAL_USER /path/to/patterns/cached_images"
+    fi
+}
+
 # Main installation process
 echo "Starting complete installation..."
 echo ""
 
 # Install everything
 setup_python_environment
+setup_patterns_permissions
 install_scripts
 setup_systemd
 setup_kiosk_optimizations
@@ -153,6 +188,7 @@ echo "🎉 Installation Complete!"
 echo "========================"
 echo ""
 echo "✅ Python virtual environment created at: $SCRIPT_DIR/venv"
+echo "✅ Patterns cache directory permissions configured"
 echo "✅ System scripts installed in /usr/local/bin/"
 echo "✅ Systemd service configured for auto-start"
 echo "✅ Kiosk optimizations applied"

+ 12 - 7
dune-weaver-touch/main.py

@@ -83,15 +83,20 @@ async def startup_tasks():
     logger.info("✨ dune-weaver-touch startup tasks completed")
 
 def main():
-    # Set Qt platform to linuxfb for Raspberry Pi compatibility
+    # Set Qt platform to linuxfb for Raspberry Pi compatibility (Linux only)
     # This must be set before QGuiApplication is created
     if 'QT_QPA_PLATFORM' not in os.environ:
-        os.environ['QT_QPA_PLATFORM'] = 'linuxfb'
-        os.environ['QT_QPA_FB_DRM'] = '1'
-        os.environ['QT_QPA_FONTDIR'] = '/usr/share/fonts'
-
-    # Enable virtual keyboard
-    os.environ['QT_IM_MODULE'] = 'qtvirtualkeyboard'
+        # Only use linuxfb on Linux systems (Raspberry Pi)
+        # On macOS, let Qt use the native cocoa platform
+        if sys.platform.startswith('linux'):
+            os.environ['QT_QPA_PLATFORM'] = 'linuxfb'
+            os.environ['QT_QPA_FB_DRM'] = '1'
+            os.environ['QT_QPA_FONTDIR'] = '/usr/share/fonts'
+
+            # Enable virtual keyboard on Linux kiosk
+            os.environ['QT_IM_MODULE'] = 'qtvirtualkeyboard'
+        else:
+            logger.info(f"🖥️ Running on {sys.platform} - using native Qt platform")
 
     app = QGuiApplication(sys.argv)
 

+ 3 - 12
dune-weaver-touch/models/pattern_model.py

@@ -46,27 +46,18 @@ class PatternModel(QAbstractListModel):
             # For patterns in subdirectories, check both flattened and hierarchical cache structures
             pattern_name = pattern["name"]
             
-            # Try PNG format for kiosk compatibility
+            # Use PNG format only for kiosk compatibility
             # First try hierarchical structure (preserving subdirectories)
             preview_path_hierarchical = self.cache_dir / f"{pattern_name}.png"
             if preview_path_hierarchical.exists():
                 return str(preview_path_hierarchical.absolute())
-            
+
             # Then try flattened structure (replace / with _)
             preview_name_flat = pattern_name.replace("/", "_").replace("\\", "_")
             preview_path_flat = self.cache_dir / f"{preview_name_flat}.png"
             if preview_path_flat.exists():
                 return str(preview_path_flat.absolute())
-            
-            # Fallback to WebP if PNG not found (for existing caches)
-            preview_path_hierarchical_webp = self.cache_dir / f"{pattern_name}.webp"
-            if preview_path_hierarchical_webp.exists():
-                return str(preview_path_hierarchical_webp.absolute())
-            
-            preview_path_flat_webp = self.cache_dir / f"{preview_name_flat}.webp"
-            if preview_path_flat_webp.exists():
-                return str(preview_path_flat_webp.absolute())
-            
+
             return ""
         
         return None