Skip to content

zgfeng115/CPUMonitor

Repository files navigation

CPU Monitor for macOS

一款简洁优雅的 macOS CPU 监控应用,实时显示 CPU 占用率最高的进程。

A clean and elegant macOS CPU monitoring app that displays the highest CPU-consuming process in real-time.

Platform Swift License

截图 / Screenshots

悬浮窗 / Floating Window 菜单 / Menu 设置 / Settings
Floating Window Menu Settings

开发原因 / Why This App

在 macOS 日常使用中,经常会有进程因内存泄漏或其他原因长时间占用 CPU,但我们往往无法及时发现,直到:

  • CPU 温度过高
  • 系统性能明显下降
  • 电脑变得异常卡顿

这款小工具就是为了解决这个问题而生。它以简洁的悬浮窗形式,实时显示当前 CPU 占用最高的进程,让你能第一时间发现并处理问题。

On macOS, processes often consume excessive CPU due to memory leaks or other issues without our immediate awareness, leading to:

  • High CPU temperatures
  • Significant system performance degradation
  • Sluggish computer response

This lightweight tool was created to solve this problem. With its simple floating window, it displays the highest CPU-consuming process in real-time, allowing you to detect and address issues immediately.


功能特性 / Features

  • 圆形悬浮窗 - 美观的玻璃拟态设计,实时显示 CPU 占用率

    Circular Floating Window - Beautiful glassmorphism design showing real-time CPU usage

  • 智能边缘吸附 - 自动吸附到屏幕边缘,支持多显示器

    Smart Edge Snapping - Auto-snap to screen edges, multi-display support

  • 位置记忆 - 自动保存窗口位置,重启后恢复

    Position Memory - Automatically saves and restores window position

  • 菜单栏图标 - 轻量级菜单栏显示,支持深色/浅色主题

    Menu Bar Icon - Lightweight menu bar display with dark/light theme support

  • 右键菜单 - 悬浮窗右键快速访问设置和退出

    Context Menu - Right-click on floating window for quick settings and quit

  • 自动隐藏 - 全屏应用时自动隐藏悬浮窗

    Auto-hide - Automatically hide when any app enters fullscreen

  • 阈值警告 - 可配置 CPU 警告阈值(绿色/黄色/红色状态指示)

    Threshold Warning - Configurable CPU warning threshold (green/yellow/red status)

  • 双击打开活动监视器 - 快速跳转到系统活动监视器

    Double-click to open Activity Monitor - Quick access to system Activity Monitor

  • 调试日志 - 可选的调试日志功能,方便排查问题

    Debug Logging - Optional debug logging for troubleshooting


系统要求 / System Requirements

  • macOS 13.0 (Ventura) 或更高版本
  • macOS 13.0 (Ventura) or later

安装 / Installation

方式 1: 下载预构建版本 / Download Pre-built

  1. Releases 页面下载最新版本
  2. CPUMonitor.app 拖入 /Applications 文件夹
  3. 首次运行需要在 系统设置 → 隐私与安全 中允许打开

1. Download from Releases 2. Drag CPUMonitor.app to /Applications folder 3. First launch requires allowing in System Settings → Privacy & Security

方式 2: 从源码构建 / Build from Source

# 克隆仓库 / Clone repository
git clone https://github.com/yourusername/CPUMonitor.git
cd CPUMonitor

# 构建 / Build
swift build

# 运行 / Run
swift run

# 或安装到应用程序文件夹 / Or install to Applications
cp -r .build/debug/CPUMonitor.app /Applications/

使用说明 / Usage

  • 拖动悬浮窗 - 按住鼠标左键拖动到任意位置
  • 边缘吸附 - 将窗口拖到屏幕边缘会自动吸附
  • 右键菜单 - 右键点击悬浮窗显示设置和退出选项
  • 菜单栏 - 点击菜单栏图标显示更多选项
  • 双击 - 双击悬浮窗打开活动监视器

Drag floating window - Hold left mouse button to drag anywhere
Edge snap - Drag window to screen edge to auto-snap
Context menu - Right-click floating window for settings and quit
Menu bar - Click menu bar icon for more options
Double-click - Double-click floating window to open Activity Monitor


技术栈 / Tech Stack

  • Swift 5.9
  • SwiftUI - 用户界面 / User interface
  • AppKit - macOS 原生功能(NSStatusBar、NSWindow 等)
  • Combine - 响应式数据流 / Reactive data flow
  • top 命令 - CPU 数据采集 / CPU data collection

项目结构 / Project Structure

CPUMonitor/
├── Sources/
│   ├── CPUMonitorApp.swift          # 应用入口 / App entry
│   ├── CPUMonitor.swift             # CPU 数据采集 / CPU monitoring
│   ├── FloatingWindowController.swift   # 悬浮窗控制器
│   ├── FloatingView.swift           # 悬浮窗视图 / Floating view
│   ├── StatusBarController.swift    # 菜单栏控制器 / Menu bar
│   ├── SettingsView.swift           # 设置面板 / Settings
│   ├── FullscreenDetector.swift     # 全屏检测 / Fullscreen detection
│   └── AutoLaunchHelper.swift       # 开机自启 / Auto-launch
├── Resources/
│   └── Assets.xcassets/             # 图标资源 / Icons
└── Package.swift                    # Swift Package 配置

许可证 / License

本项目采用 MIT License 开源协议。

This project is licensed under the MIT License.


致谢 / Acknowledgments

  • CPU 数据采集基于 macOS top 命令,与系统活动监视器数据一致
  • 玻璃拟态设计灵感来自 macOS 原生 HUD 风格

CPU data collection based on macOS top command, consistent with system Activity Monitor Glassmorphism design inspired by native macOS HUD style

About

macOS CPU 监控小工具 - 实时显示最高 CPU 占用进程

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors