Przeglądaj źródła

Fix remaining direct pattern_lock accesses

- Update main.py to use get_pattern_lock()
- Update playlist_manager.py to use get_pattern_lock()
- All accesses now go through lazy initialization getters

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris 3 tygodni temu
rodzic
commit
eda60ec058

+ 15 - 15
frontend/src/pages/SettingsPage.tsx

@@ -23,10 +23,6 @@ import {
 import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
 
 // Types
-interface SerialPort {
-  port: string
-  description: string
-}
 
 interface Settings {
   app_name?: string
@@ -67,7 +63,7 @@ export function SettingsPage() {
   const sectionParam = searchParams.get('section')
 
   // Connection state
-  const [ports, setPorts] = useState<SerialPort[]>([])
+  const [ports, setPorts] = useState<string[]>([])
   const [selectedPort, setSelectedPort] = useState('')
   const [isConnected, setIsConnected] = useState(false)
   const [connectionStatus, setConnectionStatus] = useState('Disconnected')
@@ -175,14 +171,18 @@ export function SettingsPage() {
 
   const fetchPorts = async () => {
     try {
-      const response = await fetch('/serial_status')
-      const data = await response.json()
-      console.log('Serial status response:', data)
-      setPorts(data.available_ports || [])
-      setIsConnected(data.connected || false)
-      setConnectionStatus(data.connected ? 'Connected' : 'Disconnected')
-      if (data.current_port) {
-        setSelectedPort(data.current_port)
+      // Fetch available ports
+      const portsResponse = await fetch('/list_serial_ports')
+      const portsData = await portsResponse.json()
+      setPorts(portsData || [])
+
+      // Fetch connection status
+      const statusResponse = await fetch('/serial_status')
+      const statusData = await statusResponse.json()
+      setIsConnected(statusData.connected || false)
+      setConnectionStatus(statusData.connected ? 'Connected' : 'Disconnected')
+      if (statusData.port) {
+        setSelectedPort(statusData.port)
       }
     } catch (error) {
       console.error('Error fetching ports:', error)
@@ -524,8 +524,8 @@ export function SettingsPage() {
                       </div>
                     ) : (
                       ports.map((port) => (
-                        <SelectItem key={port.port} value={port.port}>
-                          {port.port} - {port.description}
+                        <SelectItem key={port} value={port}>
+                          {port}
                         </SelectItem>
                       ))
                     )}

+ 1 - 0
frontend/vite.config.ts

@@ -44,6 +44,7 @@ export default defineConfig({
       '/pause_execution': 'http://localhost:8080',
       '/resume_execution': 'http://localhost:8080',
       '/serial_status': 'http://localhost:8080',
+      '/list_serial_ports': 'http://localhost:8080',
       '/connect': 'http://localhost:8080',
       '/disconnect': 'http://localhost:8080',
       '/get_speed': 'http://localhost:8080',

+ 1 - 1
main.py

@@ -1275,7 +1275,7 @@ async def run_theta_rho(request: ThetaRhoRequest, background_tasks: BackgroundTa
             logger.warning("Attempted to run a pattern without a connection")
             raise HTTPException(status_code=400, detail="Connection not established")
         
-        if pattern_manager.pattern_lock.locked():
+        if pattern_manager.get_pattern_lock().locked():
             logger.info("Another pattern is running, stopping it first...")
             await pattern_manager.stop_actions()
             

+ 1 - 1
modules/core/playlist_manager.py

@@ -115,7 +115,7 @@ def rename_playlist(old_name, new_name):
 
 async def run_playlist(playlist_name, pause_time=0, clear_pattern=None, run_mode="single", shuffle=False):
     """Run a playlist with the given options."""
-    if pattern_manager.pattern_lock.locked():
+    if pattern_manager.get_pattern_lock().locked():
         logger.info("Another pattern is running, stopping it first...")
         await pattern_manager.stop_actions()