fix: Add pywebview for native mode and avoid module loading warning
- Add pywebview>=4.0.0 to requirements.txt for native window support - Make native mode optional: gracefully fall back to browser mode if pywebview is not installed - Change launcher to use direct execution (python3 whispering_ui/main.py) instead of module execution (python3 -m whispering_ui.main) to avoid RuntimeWarning about module loading - Update scripts/run_nicegui.sh with direct execution
+50 −5 · 4 files changed
-
requirements.txt+1 −0 -
scripts/run_nicegui.sh+2 −2 -
scripts/run_nicegui_direct.sh+35 −0 -
src/whispering_ui/main.py+12 −3
@@ -29,3 +29,4 @@ pyperclip # NiceGUI for modern UI nicegui>=1.4.0 +pywebview>=4.0.0 # Required for NiceGUI native mode @@ -29,7 +29,7 @@ export SDL_AUDIODRIVER=pulse # Add src to Python path export PYTHONPATH="$PROJECT_DIR/src:$PYTHONPATH" -# Change to src directory and run +# Change to src directory and run (direct execution avoids module loading warning) cd "$PROJECT_DIR/src" echo "Starting Whispering with NiceGUI interface..." -python3 -m whispering_ui.main "$@" +python3 whispering_ui/main.py "$@" @@ -0,0 +1,35 @@ +#!/bin/bash +# Run Whispering with NiceGUI interface (direct execution) + +# Get the project directory (parent of scripts directory) +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Check if NiceGUI is installed +if ! python3 -c "import nicegui" 2>/dev/null; then + echo "Error: NiceGUI is not installed." + echo "Please install dependencies:" + echo " pip install nicegui pyperclip pywebview" + exit 1 +fi + +# Check if pyperclip is installed +if ! python3 -c "import pyperclip" 2>/dev/null; then + echo "Warning: pyperclip is not installed. Copy/Cut features may not work." + echo "Install with: pip install pyperclip" +fi + +# Activate virtual environment if it exists +if [ -d "$PROJECT_DIR/.venv" ]; then + source "$PROJECT_DIR/.venv/bin/activate" +fi + +# Prefer PulseAudio/PipeWire over ALSA for audio +export SDL_AUDIODRIVER=pulse + +# Add src to Python path +export PYTHONPATH="$PROJECT_DIR/src:$PYTHONPATH" + +# Change to src directory and run directly (avoids module loading warning) +cd "$PROJECT_DIR/src" +echo "Starting Whispering with NiceGUI interface..." +python3 whispering_ui/main.py "$@" @@ -160,12 +160,21 @@ def main(): app.on_shutdown(save_settings_on_exit) # === RUN APPLICATION === - # Run as native desktop window + # Try to run as native desktop window, fall back to web if pywebview not available + try: + import pywebview + native_mode = True + except ImportError: + print("Note: pywebview not installed. Running in browser mode.") + print("Install pywebview for native window: pip install pywebview") + native_mode = False + ui.run( title='Whispering', - native=True, + native=native_mode, window_size=(400 if not state.text_visible else 900, 1000), - reload=False + reload=False, + show=not native_mode # Auto-open browser if not native mode )