Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 6 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ iOSInjectionProject/

.DS_Store
*.swp

# Swift Package Manager (root Package.swift is for tests; build artifacts are local)
.build/
.swiftpm/
Package.resolved

/sparkle/framework/bin
/sparkle/framework/CHANGELOG
/sparkle/framework/INSTALL
Expand Down
12 changes: 12 additions & 0 deletions 12 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- "Launch at Login" preference, backed by `SMAppService.mainApp`.
- "Allow Mac to run with lid closed" preference. When enabled, Caffeine additionally holds a `kIOPMAssertionTypePreventSystemSleep` assertion so a portable Mac on AC power keeps running with the lid closed.
- Traditional Chinese (zh-Hant) localization.
- Traditional Chinese README (`README.zh-Hant.md`) with a step-by-step tutorial for the two new toggles.
- Swift Package (`Package.swift`) + `swift test` unit tests covering the new launch-item and power-assertion wiring.
- `scripts/integration-test.sh` that builds the app and verifies `pmset -g assertions` reflects the expected types.

### Changed

- Sleep prevention now also holds `kIOPMAssertPreventUserIdleSystemSleep` (previously display-idle only), so the whole system stays awake during idle — not just the display.
- Bumped the IOPMAssertion timeout from 8 s to 30 s so the 10 s refresh window always overlaps (the previous values left a 2 s gap every cycle).
- Rewrote `README.md` to point at this fork's releases and issue tracker; removed third-party support and download URLs.
- Improved Ukrainian translation.

### Fixed
Expand Down
37 changes: 37 additions & 0 deletions 37 Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// swift-tools-version: 6.0
//
// Side Swift Package for automated unit tests of Caffeine's testable model code.
//
// The Xcode project (`src/Caffeine.xcodeproj`) is the source of truth for the
// shipping app. This package compiles a subset of the model files into a
// separate `CaffeineCore` library so that `swift test` can run unit tests
// against them without touching the Xcode project. Xcode and SPM compile the
// same .swift files independently — there is no conflict because each build
// system produces its own artifacts.

import PackageDescription

let package = Package(
name: "CaffeineCore",
platforms: [.macOS(.v14)],
products: [
.library(name: "CaffeineCore", targets: ["CaffeineCore"]),
],
targets: [
.target(
name: "CaffeineCore",
path: "src/Caffeine/Classes/Models",
sources: [
"LaunchAtLoginManager.swift",
"LaunchItemBackend.swift",
"PowerAssertionBackend.swift",
"SleepPreventionManager.swift",
]
),
.testTarget(
name: "CaffeineCoreTests",
dependencies: ["CaffeineCore"],
path: "Tests/CaffeineCoreTests"
),
]
)
108 changes: 86 additions & 22 deletions 108 README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,110 @@
<img src="https://github.caffeine-app.net/assets/icon.png" alt="Icon" width="239"/>
<img src="assets/Cup.png" alt="Caffeine cup icon" width="160"/>

# Caffeine
### Don't let your Mac fall asleep.

Caffeine is a tiny program that keeps your Mac awake, useful for ensuring that long running tasks aren't interrupted by your computer going to sleep.
### Keep your Mac awake — including with the lid closed.

### Installation
[English](README.md) • [繁體中文](README.zh-Hant.md)

Download Caffeine at https://caffeine-app.net and drag it into your Applications folder, then double-click the icon to launch it.
Caffeine is a small menu-bar utility that prevents your Mac from going to sleep, dimming the display, or starting the screensaver. This fork of [`domzilla/Caffeine`](https://github.com/domzilla/Caffeine) adds an **"Allow Mac to run with lid closed"** option (Amphetamine-parity on AC power) and a **"Launch at Login"** toggle, plus Traditional Chinese localization.

### Usage
---

Caffeine puts a coffee cup icon in the right side of your menu bar. Click the cup to toggle whether Caffeine is active or not -- a full cup means Caffeine will prevent your Mac from automatically going to sleep, dimming the screen or starting screen savers. An empty cup means your Mac will sleep normally.
## Quickstart

<img src="https://github.caffeine-app.net/assets/menubar.png" alt="Menubar" width="277"/>
1. Download the latest `Caffeine.app` from the [Releases](https://github.com/bubbleee030/Caffeine/releases) page.
2. Drag it into `~/Applications` (or `/Applications`).
3. Double-click to launch. A coffee-cup icon appears at the right side of the menu bar.
4. **Click** the cup to toggle sleep prevention. **Right-click** (or ⌃-click) for the menu.

For more control, right-click (or ⌘-click) the icon to show the menu. From here, you can access the preferences window or set a timeout if you only need Caffeine to prevent sleep for a little while.
## Features

<img src="https://github.caffeine-app.net/assets/menu.png" alt="Menu" width="293"/>
| Feature | What it does |
| --- | --- |
| **Toggle** | Click the menu-bar cup. A full cup = active. An empty cup = your Mac sleeps normally. |
| **Timed activation** | Right-click → *Activate for* → pick 5 min ‥ 5 hours, or *Indefinitely*. |
| **Launch at Login** *(new)* | Preferences → *Launch at Login*. Uses `SMAppService`, sandbox-safe, no helper. |
| **Allow Mac to run with lid closed** *(new)* | Preferences → *Allow Mac to run with lid closed*. Holds an additional `PreventSystemSleep` IOPMAssertion so a portable Mac stays running with the lid closed **on AC power**. On battery, macOS may still sleep — this is enforced by the system. |
| **Keep apps active** | Simulates HID activity so apps like Teams or Slack stop marking you as "Away". |
| **Deactivate on manual sleep** | Stops Caffeine when you put your Mac to sleep via the Apple menu. |

Caffeine is intended to be simple, yet powerful. Options you can configure include whether to start Caffeine automatically every time you start up your Mac, whether Caffeine should activate every time it starts, and a default duration if you always want Caffeine to turn itself off after a set time.
## Tutorial: the two new toggles

<img src="https://github.caffeine-app.net/assets/preferences.png" alt="Preferences" width="645"/>
### Launch at Login

### FAQ
Open Preferences (right-click cup → *Preferences…*) and switch on **Launch at Login**. macOS registers Caffeine as a login item; you can also see it under **System Settings → General → Login Items & Extensions**. Toggling either side keeps the state in sync — Caffeine re-reads `SMAppService.mainApp.status` when its Preferences window opens.

##### Is this the same Caffeine that I've used before?
### Allow Mac to run with lid closed

Yes! Tomas Franzén of Lighthead Software originally developed Caffeine in 2006, and it has been a well known and loved utility for Mac users for many years. Its simplicity has allowed it to continue working perfectly long after active development had ceased.
Switch on **Allow Mac to run with lid closed**, then activate Caffeine (click the cup). On AC power, you can now close the lid and the Mac will keep running — useful for downloads, long renders, or streaming to an external display while the laptop is shut.

In 2018, Michael Jones (IntelliScape Computer Solutions) reached out to Tomas to inquire if they could continue development of Caffeine.
To verify it's working, in Terminal:

Tomas has graciously provided the source code under an open source license, allowing IntelliScape Computer Solutions to continue developing Caffeine where he left off.
```bash
pmset -g assertions | grep -i caffeine
```

You should see all three assertion types while active with the toggle on:

```
pid 12345(Caffeine): … PreventUserIdleDisplaySleep …
pid 12345(Caffeine): … PreventUserIdleSystemSleep …
pid 12345(Caffeine): … PreventSystemSleep …
```

If you turn the lid-close toggle off, the third line disappears.

> ⚠️ macOS's closed-lid sleep policy is enforced by the kernel. On battery, the system may still sleep when the lid closes regardless of any assertion. Connect to power for reliable lid-closed operation.

## Languages

Caffeine ships with 14 localizations:

> English · 繁體中文 · 简体中文 · 日本語 · 한국어 · Deutsch · Español · Français · Italiano · Nederlands · Português (BR) · Português (PT) · Русский · Українська

The European and Slavic translations of the two new strings are best-effort and welcome native-speaker review — open an issue or PR if a phrasing reads oddly in your language.

## Requirements

- macOS 14.6 (Sonoma) or later
- Apple silicon or Intel

## Building from source

```bash
git clone git@github.com:bubbleee030/Caffeine.git
cd Caffeine
xcodebuild -project src/Caffeine.xcodeproj -scheme Caffeine \
-destination 'platform=macOS' build CODE_SIGNING_ALLOWED=NO
swift test # runs the unit tests for the manager classes
scripts/integration-test.sh # builds and verifies pmset assertion types
```

## FAQ

##### Is this the same Caffeine I've used before?

Yes — it's a feature fork. Tomas Franzén shipped the original in 2006, Michael Jones (IntelliScape) revived it in 2018 under an open-source license, and Dominic Rodemer ([domzilla/Caffeine](https://github.com/domzilla/Caffeine)) rewrote it in SwiftUI in 2025. This fork adds Launch at Login and lid-close support on top of that.

##### Does this work with macOS 10.x?

No, this version requires at least macOS 11 (Big Sur). Caffeine for macOS Yosemite or later (including Catalina) is available at: https://www.intelliscapesolutions.com/apps/caffeine/
No, this version requires at least macOS 14.6 (Sonoma). The upstream `domzilla/Caffeine` builds against macOS 11+; older systems are unsupported.

##### How is Caffeine different or better than alternatives (such as Amphetamine, KeepingYouAwake, etc.)?

The point of this fork is to bring Caffeine's signature simplicity *plus* Amphetamine's lid-close behaviour into one menu-bar app. If you already love Amphetamine's session/trigger system, stick with it. If you want a one-click cup with a tiny preferences pane that also keeps your laptop running with the lid shut, this is for you.

## Support

Found a bug or have a feature request? Open an issue on GitHub:

##### How is Caffeine different or better than alternatives (such as Amphetamine, KeepingYouAwake, etc)?
> **<https://github.com/bubbleee030/Caffeine/issues>**

Due to the long period of inactivity for Caffeine, a lot of different and great options have been developed. While the alternatives are great apps and definitely worth your consideration, we believe that Caffeine's power lies in its simplicity and ease of use.
## Credits

### Support
- © 2006 **Tomas Franzén** — original Caffeine
- © 2018 **Michael Jones** (IntelliScape) — revived and open-sourced
- © 2022 **Dominic Rodemer** — SwiftUI rewrite, Sparkle updates, multi-language work
- 2026 **[@bubbleee030](https://github.com/bubbleee030)** — Launch at Login, lid-close support, Traditional Chinese

If you have questions, comments or other feedback get in touch at https://caffeine-app.net/support.
See [`CHANGELOG.md`](CHANGELOG.md) for the full version history.
110 changes: 110 additions & 0 deletions 110 README.zh-Hant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<img src="assets/Cup.png" alt="Caffeine 咖啡杯圖示" width="160"/>

# Caffeine

### 讓你的 Mac 保持清醒 — 連闔上蓋子也行。

[English](README.md) • [繁體中文](README.zh-Hant.md)

Caffeine 是一個小巧的選單列工具,可以防止 Mac 進入睡眠、暗螢幕或啟動螢幕保護程式。本 fork(基於 [`domzilla/Caffeine`](https://github.com/domzilla/Caffeine))新增了 **「闔蓋時保持運作」**(在接通電源時可達到 Amphetamine 等價效果)與 **「登入時啟動」** 開關,並補上繁體中文在地化。

---

## 快速開始

1. 從 [Releases](https://github.com/bubbleee030/Caffeine/releases) 頁面下載最新的 `Caffeine.app`。
2. 拖到 `~/Applications` 或 `/Applications`。
3. 點兩下啟動,選單列右側會出現一個咖啡杯圖示。
4. **點按** 杯子切換啟用狀態,**按右鍵**(或 ⌃-點按)顯示完整選單。

## 功能

| 功能 | 說明 |
| --- | --- |
| **切換啟用** | 點按選單列的咖啡杯。滿杯=啟用中,空杯=Mac 正常睡眠。 |
| **計時啟用** | 右鍵選單 → *啟用時長* → 選擇 5 分鐘 ‥ 5 小時,或 *無限期*。 |
| **登入時啟動** *(新)* | 偏好設定 → *登入時啟動*。使用 `SMAppService`,App Sandbox 友善,不需 helper bundle。 |
| **闔蓋時保持運作** *(新)* | 偏好設定 → *闔蓋時保持運作*。額外建立 `PreventSystemSleep` 的 IOPMAssertion,讓筆電在 **接通電源** 時闔上蓋子也保持運作。電池模式下,macOS 仍會強制睡眠 — 這是系統層面決定的。 |
| **保持 App 活躍** | 模擬 HID 活動,避免 Teams、Slack 等把你標為「離開」。 |
| **手動睡眠時停用** | 從 Apple 選單手動進入睡眠時停止 Caffeine。 |

## 教學:兩個新開關

### 登入時啟動

打開偏好設定(右鍵杯子 → *偏好設定…*),開啟 **登入時啟動**。macOS 會將 Caffeine 註冊為登入項目;你也可以在 **系統設定 → 一般 → 登入項目與擴充功能** 中看到它。從任一邊切換狀態都會同步 — 偏好設定視窗開啟時 Caffeine 會重新讀取 `SMAppService.mainApp.status`。

### 闔蓋時保持運作

開啟 **闔蓋時保持運作**,然後啟用 Caffeine(點杯子)。接通電源時,你可以闔上蓋子,Mac 會繼續執行 — 適合下載中、長時間轉檔,或把筆電當主機接外接螢幕時闔起來放著。

要確認有沒有真的生效,可以在 Terminal 執行:

```bash
pmset -g assertions | grep -i caffeine
```

啟用且開關開啟時,應該會看到三條:

```
pid 12345(Caffeine): … PreventUserIdleDisplaySleep …
pid 12345(Caffeine): … PreventUserIdleSystemSleep …
pid 12345(Caffeine): … PreventSystemSleep …
```

把闔蓋開關關掉,第三條就會消失。

> ⚠️ macOS 的「闔蓋即睡眠」策略是 kernel 強制執行的。電池模式下,無論任何 IOPMAssertion,系統仍可能在闔蓋後進入睡眠。要可靠地闔蓋運作,請接上電源。

## 支援的語言

Caffeine 內建 14 種語系:

> English · 繁體中文 · 简体中文 · 日本語 · 한국어 · Deutsch · Español · Français · Italiano · Nederlands · Português (BR) · Português (PT) · Русский · Українська

歐語與斯拉夫語的兩個新字串為盡力翻譯,歡迎母語人士透過 issue 或 PR 校稿。

## 系統需求

- macOS 14.6(Sonoma)或更新版本
- Apple Silicon 或 Intel 處理器

## 從原始碼建構

```bash
git clone git@github.com:bubbleee030/Caffeine.git
cd Caffeine
xcodebuild -project src/Caffeine.xcodeproj -scheme Caffeine \
-destination 'platform=macOS' build CODE_SIGNING_ALLOWED=NO
swift test # 跑 manager 類別的單元測試
scripts/integration-test.sh # 建構並驗證 pmset assertion 類型
```

## 常見問題

##### 這是我以前用過的那個 Caffeine 嗎?

是 — 這是它的功能 fork。Tomas Franzén 在 2006 年釋出最初版本,2018 年由 Michael Jones(IntelliScape)以開源授權復活,2025 年 Dominic Rodemer([domzilla/Caffeine](https://github.com/domzilla/Caffeine))用 SwiftUI 重寫。本 fork 在這個基礎上加入登入時啟動與闔蓋支援。

##### 可以在 macOS 10.x 上跑嗎?

不行,本版本需要 macOS 14.6(Sonoma)或更新。上游 `domzilla/Caffeine` 支援 macOS 11+;更舊的系統不再支援。

##### 跟 Amphetamine、KeepingYouAwake 這些有什麼不一樣?

本 fork 的重點是保留 Caffeine 一貫的簡潔,再加上 Amphetamine 的闔蓋功能。如果你喜歡 Amphetamine 的工作階段/觸發器系統,那個比較適合。如果你只想要一個點一下就清醒的咖啡杯、再加上闔蓋繼續跑,那就是本作。

## 支援

發現 bug 或想許願功能?請到 GitHub 開 issue:

> **<https://github.com/bubbleee030/Caffeine/issues>**

## 致謝

- © 2006 **Tomas Franzén** — 最初的 Caffeine
- © 2018 **Michael Jones**(IntelliScape)— 復活並開源
- © 2022 **Dominic Rodemer** — SwiftUI 重寫、Sparkle 更新、多語系
- 2026 **[@bubbleee030](https://github.com/bubbleee030)** — 登入時啟動、闔蓋支援、繁體中文

完整版本歷史見 [`CHANGELOG.md`](CHANGELOG.md)。
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.