Skip to content

XXanderWP/WinPowerControl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Battery Auto-Shutdown

Dynamic TOML Badge Platform Python Version from PEP 621 TOML License: MIT

A lightweight desktop application that automatically shuts down your computer when running on battery power. Perfect for preventing accidental battery drain if your charger gets disconnected.

🌍 Multi-Language Support

The application automatically detects your system language and supports:

  • πŸ‡¬πŸ‡§ English
  • πŸ‡·πŸ‡Ί Russian (Русский)
  • πŸ‡ΊπŸ‡¦ Ukrainian (Π£ΠΊΡ€Π°Ρ—Π½ΡΡŒΠΊΠ°)

If your system language isn't supported, the app defaults to English.

✨ Features

  • πŸ”‹ Automatic Battery Monitoring - Continuously monitors your laptop's power status
  • ⏱️ Configurable Delay - Set a delay (1-60 minutes) before shutdown occurs
  • πŸ“Š Battery Threshold - Set minimum battery percentage for shutdown trigger
  • πŸ”” Warning Dialog - 30-second countdown with cancel option before shutdown
  • πŸ”Š Sound Alerts - Optional audio notifications (can be disabled)
  • πŸš€ Auto-Start - Option to run at Windows startup
  • πŸ’Ύ Persistent Settings - All configurations are automatically saved
  • 🎨 System Tray Integration - Minimizes to tray, runs in background

πŸ“‹ Requirements

  • Windows 7/8/10/11
  • Python 3.7 or higher (for running from source)
  • PyQt5
  • psutil

πŸš€ Quick Start

Option 1: Using Pre-built Executable (Recommended)

  1. Download the latest EXE file from Releases
  2. Run the executable
  3. Configure your settings
  4. Enable auto-shutdown

Option 2: Running from Source

  1. Clone the repository:

    git clone https://github.com/XXanderWP/WinPowerControl.git
    cd battery-shutdown
  2. Create and activate virtual environment:

    Windows:

    setup_venv.bat
    venv\Scripts\activate
  3. Run the application:

    # Default run
    python main.py
    
    # Debug mode (disables battery check at startup)
    python main.py --debug

πŸ› οΈ Building from Source

To create a standalone executable:

  1. Activate virtual environment (if not already activated)

    venv\Scripts\activate  # Windows
  2. Run build script:

    Windows:

    build.bat

The executable will be created in the dist folder.

πŸ“– How It Works

  1. Power Monitoring: The app continuously monitors your computer's power status
  2. Battery Transition: When disconnected from AC power, a countdown timer starts
  3. Threshold Check: If battery drops below your set percentage and time expires, shutdown is triggered
  4. Warning Dialog: A 30-second warning appears before shutdown
  5. Cancel Option: You can cancel the shutdown at any time

Example Scenario

  • Settings: 5-minute delay, 50% battery threshold
  • Event: Charger disconnects, battery at 75%
  • Process:
    • Timer starts (5 minutes)
    • After 5 minutes, if battery ≀ 50%, warning dialog appears
    • 30-second countdown begins
    • Computer shuts down (unless cancelled)

βš™οΈ Configuration

Main Settings

  • Enable Auto-Shutdown: Master on/off switch
  • Delay Before Shutdown: 1-60 minutes (time after AC disconnect)
  • Minimum Battery Charge: 1-100% (shutdown threshold)

Additional Settings

  • Sound Notifications: Enable/disable audio alerts
  • Auto-Start: Launch at Windows startup

Configuration File

Settings are stored in: %USERPROFILE%\.win_power_control\config.json

Example configuration:

{
  "enabled": true,
  "delay_minutes": 5,
  "battery_percent": 50,
  "sound_enabled": true,
  "language": null
}

🎯 Use Cases

  • Accidental Disconnect Protection: Prevent battery drain if charger unplugs
  • Power Outage Safety: Auto-shutdown during extended power outages
  • Battery Longevity: Avoid deep discharge cycles
  • Remote Systems: Automatically manage power on unattended machines

πŸ”’ Safety Features

  • Cancellable Shutdown: Always get 30 seconds to cancel
  • Auto-Disable on Cancel: If you cancel once, feature turns off
  • Persistent Status: System tray icon shows current state
  • Multiple Conditions: Both time AND battery level must be met

πŸ“‚ Project Structure

battery-shutdown/
β”œβ”€β”€ main.py                 # Application entry point
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ config.py      # Configuration management
β”‚   β”‚   └── monitor.py     # Battery monitoring thread
β”‚   β”œβ”€β”€ gui/
β”‚   β”‚   β”œβ”€β”€ main_window.py        # Main application window
β”‚   β”‚   β”œβ”€β”€ settings_dialog.py   # Settings dialog
β”‚   β”‚   β”œβ”€β”€ help_dialog.py        # Help/FAQ dialog
β”‚   β”‚   └── shutdown_dialog.py   # Shutdown warning dialog
β”‚   β”œβ”€β”€ i18n/
β”‚   β”‚   β”œβ”€β”€ translations.py       # Translation system
β”‚   β”‚   └── help_content.py       # Multi-language help text
β”‚   └── utils/
β”‚       └── system.py      # System utilities (shutdown, autostart)
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ setup_venv.bat        # Virtual environment setup (Windows)
β”œβ”€β”€ build.bat             # Build script (Windows)
└── README.md             # This file

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Adding a New Language

To add support for a new language:

  1. Edit src/i18n/translations.py
  2. Add your language code and translations to TRANSLATIONS dictionary
  3. Edit src/i18n/help_content.py
  4. Add help content in your language to HELP_CONTENT dictionary

πŸ› Troubleshooting

App doesn't start

  • Ensure Python 3.7+ is installed
  • Check that all dependencies are installed: pip install -r requirements.txt
  • Try running with admin privileges

Battery not detected

  • This app requires a laptop with a battery
  • Desktop computers are not supported
  • Check if Windows detects your battery in Device Manager

Auto-start not working

  • Ensure you have necessary permissions
  • Check Windows Registry: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
  • Try running the app as administrator

Shutdown doesn't work

  • Check Windows Event Viewer for shutdown errors
  • Ensure you have permission to shutdown the system
  • Test manual shutdown command: shutdown /s /t 0

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Created with ❀️ for better battery management

πŸ™ Acknowledgments

  • PyQt5 - Cross-platform GUI framework
  • psutil - System and process utilities
  • Python community - For amazing tools and libraries

πŸ“ž Support


⭐ If you find this project useful, please consider giving it a star!

πŸ—ΊοΈ Roadmap

  • macOS support
  • Linux support
  • Hibernate option (instead of shutdown)
  • Sleep mode trigger
  • Battery statistics
  • Custom shutdown scripts

About

Application that automatically shuts down your computer when running on battery power

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors