Skip to content

Harshul23/Grapes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Grapes

A lightweight macOS menu bar application that monitors your battery level and provides visual alerts when battery charge reaches customizable thresholds.

Overview

Grapes is a battery observer app designed for macOS that runs quietly in the menu bar and alerts you when your battery level is too low (needs charging) or too high (should be unplugged). The app features beautiful sliding overlay animations with customizable threshold settings to help you maintain optimal battery health.

Features

  • Menu Bar Integration: Runs as a lightweight menu bar app with battery icon indicator
  • Customizable Thresholds: Set your own low and high battery percentage alerts
    • Default low threshold: 20%
    • Default high threshold: 80%
  • Visual Alerts: Beautiful full-screen sliding overlay animations that show:
    • Current battery percentage
    • Color-coded indicators (red for low, green for high)
    • Action prompts ("Plug in!" or "Enough!")
  • Smart Notifications:
    • Monitors battery every 20 seconds
    • Alerts only once per threshold crossing
    • Auto-dismisses after 3 seconds or click to dismiss instantly
  • Toggle Alerts: Easily enable or disable alerts from the menu bar
  • Auto-start at Login: Automatically starts with macOS (macOS Ventura 13.0+)
  • Blur Effect: Elegant blurred background overlay with smooth animations

Requirements

  • macOS 13.0 (Ventura) or later
  • Xcode 15.0 or later (for building from source)

Installation

Building from Source

  1. Clone the repository:

    git clone https://github.com/Harshul23/Grapes.git
    cd Grapes
  2. Open the project in Xcode:

    open Grapes.xcodeproj

    Or simply double-click Grapes.xcodeproj in Finder.

  3. Build and run the project:

    • Select the "Grapes" scheme in Xcode
    • Press ⌘ + R to build and run
    • Or use Product → Run from the menu
  4. The app will appear in your menu bar with a battery icon once running

Note: The project requires Xcode 15.0+ with macOS deployment target of 13.0 (Ventura) or later.

Xcode setup (for macOS Sequoia 15.6.1 and earlier versions)

  1. Open Grapes.xcodeproj in Xcode 15+ on your Mac.
  2. In the project navigator, select the Grapes target → Signing & Capabilities. Pick your Apple ID/team so the app can be signed for local builds (Automatic signing is enabled in the project).
  3. In Build Settings, confirm macOS Deployment Target is set to 13.0 or later. This value is configured in the project file so the app runs on Ventura (13), Sonoma (14), and Sequoia (15.6.1).
  4. Choose the My Mac (Designed for macOS) destination and press ⌘R to build and run. No additional entitlements are required beyond the sandbox already enabled in the target.

Usage

Starting the App

Once launched, Grapes runs in the background and appears as a battery icon in your macOS menu bar.

Menu Bar Options

Click the battery icon in the menu bar to access:

  • Preferences…: Open settings to customize battery thresholds
  • Enable/Disable Alerts: Toggle battery alerts on or off
  • Quit: Exit the application

Setting Battery Thresholds

  1. Click the battery icon in the menu bar
  2. Select "Preferences…" (or press ⌘ + ,)
  3. Adjust the sliders:
    • High Battery Threshold: Set between 50% - 100% (when to alert for unplugging)
    • Low Battery Threshold: Set between 5% - 50% (when to alert for charging)
  4. Values are automatically saved and take effect immediately
Screenshot 2025-12-09 at 3 22 17 AM

Screenshot 2025-12-09 at 3 23 03 AM

Understanding Alerts

Low Battery Alert (Red)

  • Triggers when battery drops to or below your low threshold

  • Shows red sliding bar animation

  • Displays current percentage and "Plug in!" message

  • Suggests you should charge your device

    Screenshot 2025-12-07 at 8 54 26 PM copy

High Battery Alert (Green)

  • Triggers when battery reaches or exceeds your high threshold

  • Shows green sliding bar animation

  • Displays current percentage and "Enough!" message

  • Suggests you should unplug your device

    Screenshot 2025-12-09 at 3 11 00 AM

Dismissing Alerts

Alerts automatically dismiss after 3 seconds, or you can:

  • Click anywhere on the overlay to dismiss immediately

Technical Details

Project Structure

Grapes/
├── Grapes.xcodeproj/          # Xcode project file
│   ├── project.pbxproj        # Project configuration
│   └── xcshareddata/          # Shared schemes
│       └── xcschemes/
│           └── Grapes.xcscheme
├── Grapes/                    # Source code directory
│   ├── main.swift            # Application entry point
│   ├── AppDelegate.swift     # Main application logic
│   └── Assets.xcassets/      # App icons and resources
└── README.md

Architecture

The app is built with native macOS technologies:

  • Cocoa Framework: For macOS app development
  • IOKit: For battery status monitoring via IOPSCopyPowerSourcesInfo()
  • QuartzCore: For smooth animations
  • ServiceManagement: For auto-start at login functionality

Components

main.swift

Entry point that initializes the NSApplication and sets up the AppDelegate.

AppDelegate.swift

Main application logic including:

  • Menu bar setup and management
  • Battery monitoring timer (checks every 20 seconds)
  • Alert threshold management with UserDefaults persistence
  • Sliding overlay UI with blur effects
  • Preferences window with real-time slider updates

Battery Monitoring

The app uses IOKit to access battery information:

  • Reads current capacity and maximum capacity
  • Calculates percentage level
  • Compares against user-defined thresholds
  • Triggers alerts only on threshold crossings (not continuously)

Data Persistence

User preferences are stored using UserDefaults:

  • lowThreshold: Low battery alert percentage (default: 20)
  • highThreshold: High battery alert percentage (default: 80)

Battery Health Tips

Optimal battery health is often maintained by:

  • Keeping charge between 20% and 80% when possible
  • Avoiding full discharge cycles
  • Not leaving devices plugged in at 100% for extended periods

Grapes helps you maintain these practices with customizable alerts!

Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests

License

Please check the repository for license information.

Author

Created by Harshul23


Note: This app requires appropriate permissions to monitor battery status. macOS may prompt you to grant necessary permissions on first launch.

About

Grapes is a lightweight macOS utility that helps you maintain healthy battery habits with smart charge alerts and a simple, elegant interface.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages