Skip to content

Commit 7863200

Browse files
committed
feat: implement professional distribution system (DMG, Homebrew, One-liner, GitHub Actions)
1 parent 1bc4dfb commit 7863200

5 files changed

Lines changed: 173 additions & 17 deletions

File tree

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
name: Build & Package
11+
runs-on: macos-14
12+
permissions:
13+
contents: write
14+
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v4
18+
19+
- name: Run Build Script
20+
run: |
21+
chmod +x build.sh
22+
./build.sh
23+
24+
- name: Run Package Script
25+
run: |
26+
chmod +x package.sh
27+
./package.sh
28+
29+
- name: Create GitHub Release
30+
id: create_release
31+
uses: softprops/action-gh-release@v2
32+
with:
33+
files: ChargeControl.dmg
34+
draft: false
35+
prerelease: false
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ Thumbs.db
2727
*~
2828
test_*.swift
2929
check_*.swift
30+
31+
# Disk images
32+
*.dmg

README.md

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,68 @@ Unlike standard macOS battery management, ChargeControl gives you direct control
4848

4949
## 🛠️ Installation & Setup
5050

51-
### 1. Build from Source
51+
Choose your preferred way to install ChargeControl.
5252

53+
### 1. The "Standard Mac" way (DMG) [Recommended]
54+
1. Go to the [Releases](https://github.com/will2022/ChargeControl/releases) page.
55+
2. Download the latest `ChargeControl.dmg`.
56+
3. Double-click the DMG and drag **ChargeControl** to your **Applications** folder.
57+
58+
### 2. The Homebrew way
59+
If you have [Homebrew](https://brew.sh) installed, run:
60+
```bash
61+
brew tap will2022/chargecontrol
62+
brew install --cask will2022/chargecontrol/chargecontrol
63+
```
64+
65+
### 3. The One-Liner (Terminal)
66+
Run this command to automatically download and install the latest release:
67+
```bash
68+
curl -sL https://raw.githubusercontent.com/will2022/ChargeControl/main/install.sh | bash
69+
```
70+
71+
### 4. Build from Source (Developers)
5372
1. Clone the repository:
5473
```bash
5574
git clone https://github.com/will2022/ChargeControl.git
56-
cd ChargeControl/ChargeControl
75+
cd ChargeControl
5776
```
58-
2. Run the build script:
77+
2. Build the app:
5978
```bash
6079
./build.sh
80+
./package.sh # To generate the DMG
6181
```
62-
The built application will be located at `build/ChargeControl.app`.
82+
3. Move `build/ChargeControl.app` to `/Applications`.
6383

64-
### 2. Install to Applications
84+
---
6585

66-
For the background daemon to work reliably with macOS security policies (`SMAppService`), it is recommended to move the app to your `/Applications` folder:
86+
## 🛡️ Security & Permissions
6787

68-
```bash
69-
cp -R build/ChargeControl.app /Applications/
70-
```
88+
Because ChargeControl is currently distributed independently and interacts with low-level system hardware (SMC), you will likely encounter macOS security warnings.
89+
90+
### 1. "Unidentified Developer" Warning
91+
When you first try to open the app, macOS may block it because it isn't signed with an Apple Developer Certificate.
92+
- **The Fix:** Don't just double-click it. **Right-click (or Control-click)** the app icon and select **Open**. This will present a dialog with an "Open" button that isn't usually there, allowing you to bypass the check.
93+
94+
### 2. Administrator Password
95+
Once opened, the app needs to install a background helper daemon (`ChargeControlDaemon`) to talk to your battery hardware.
96+
- **The Fix:** You will be prompted for your **Administrator Password**. This is required for the app to enforce your battery limits while your Mac is asleep or on the lock screen.
7197

72-
### 3. Install the CLI (Optional)
98+
### 3. Background Items
99+
You may see a system notification that "ChargeControl" has added a background item. This is normal and necessary for the daemon to stay active.
100+
101+
---
102+
103+
## ⌨️ Installing the CLI (Optional)
104+
105+
The `cc` command-line tool allows you to control the app from the terminal.
106+
- If you installed via **Homebrew** or the **One-Liner**, the CLI is already installed!
107+
- If you installed via the **DMG** or built from source, you can symlink it manually:
73108

74-
To use the CLI from anywhere, symlink the binary to your path:
75109
```bash
76110
sudo ln -s /Applications/ChargeControl.app/Contents/MacOS/cc /usr/local/bin/cc
77111
```
78112

79-
### 4. First Run & Permissions
80-
81-
1. Open `ChargeControl.app` from your `/Applications` folder.
82-
2. The app will attempt to register its privileged helper tool (`ChargeControlDaemon`).
83-
3. **Password Prompt:** macOS will prompt you for your administrator password to authorize the background service.
84-
85113
---
86114

87115
## 📖 Usage

install.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
set -e
3+
4+
REPO="will2022/ChargeControl"
5+
APP_NAME="ChargeControl.app"
6+
APP_DEST="/Applications/ChargeControl.app"
7+
8+
echo "🚀 Installing ChargeControl..."
9+
10+
# 1. Fetch latest release info
11+
echo "Step 1: Finding latest version..."
12+
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest")
13+
DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | grep "browser_download_url.*ChargeControl.dmg" | cut -d '"' -f 4)
14+
15+
if [ -z "$DOWNLOAD_URL" ]; then
16+
echo "❌ Error: Could not find the latest DMG release on GitHub."
17+
exit 1
18+
fi
19+
20+
# 2. Download DMG
21+
echo "Step 2: Downloading ChargeControl.dmg..."
22+
curl -L -o /tmp/ChargeControl.dmg "$DOWNLOAD_URL"
23+
24+
# 3. Mount DMG
25+
echo "Step 3: Mounting Disk Image..."
26+
MOUNT_POINT=$(hdiutil attach /tmp/ChargeControl.dmg -nobrowse | grep /Volumes | awk '{print $3}')
27+
28+
# 4. Install App
29+
echo "Step 4: Installing to /Applications..."
30+
if [ -d "$APP_DEST" ]; then
31+
echo "⚠️ Existing version found. Replacing..."
32+
sudo rm -rf "$APP_DEST"
33+
fi
34+
sudo cp -R "$MOUNT_POINT/$APP_NAME" /Applications/
35+
36+
# 5. Cleanup
37+
echo "Step 5: Cleaning up..."
38+
hdiutil detach "$MOUNT_POINT"
39+
rm /tmp/ChargeControl.dmg
40+
41+
# 6. Optional: Link CLI
42+
echo "Step 6: Setting up 'cc' command..."
43+
if [ ! -L /usr/local/bin/cc ]; then
44+
sudo ln -s "$APP_DEST/Contents/MacOS/cc" /usr/local/bin/cc
45+
echo "✅ 'cc' command linked to /usr/local/bin/cc"
46+
fi
47+
48+
echo "🎉 Finished! You can now open ChargeControl from your Applications folder."

package.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Configuration
5+
APP_NAME="ChargeControl"
6+
BUILD_DIR="build"
7+
DMG_NAME="${APP_NAME}.dmg"
8+
DMG_ROOT="dmg_root"
9+
10+
echo "📦 Packaging $APP_NAME into $DMG_NAME..."
11+
12+
# 1. Ensure we have a fresh build
13+
if [ ! -d "$BUILD_DIR/${APP_NAME}.app" ]; then
14+
echo "⚠️ Build not found. Running build.sh first..."
15+
./build.sh
16+
fi
17+
18+
# 2. Setup DMG root folder
19+
echo "Step 1: Setting up temporary packaging folder..."
20+
rm -rf "$DMG_ROOT"
21+
mkdir -p "$DMG_ROOT"
22+
23+
# 3. Copy the compiled app
24+
echo "Step 2: Copying $APP_NAME.app..."
25+
cp -R "$BUILD_DIR/${APP_NAME}.app" "$DMG_ROOT/"
26+
27+
# 4. Create a symlink to /Applications for the user
28+
echo "Step 3: Creating /Applications symlink..."
29+
ln -s /Applications "$DMG_ROOT/Applications"
30+
31+
# 5. Create the DMG using hdiutil
32+
echo "Step 4: Building the Disk Image (hdiutil)..."
33+
rm -f "$DMG_NAME"
34+
hdiutil create -volname "$APP_NAME" -srcfolder "$DMG_ROOT" -ov -format UDZO "$DMG_NAME"
35+
36+
# 6. Cleanup
37+
echo "Step 5: Cleaning up..."
38+
rm -rf "$DMG_ROOT"
39+
40+
echo "✅ Success! $DMG_NAME is ready for release."

0 commit comments

Comments
 (0)