- 清理:应用缓存、日志、浏览器缓存、Xcode/模拟器/npm 缓存、下载残留、安装包、废纸篓; 白名单目录 + 安全守卫,运行中的应用自动跳过,执行前逐项复核,操作日志 - 系统维护:刷新 DNS 缓存、释放内存(辅助工具或管理员授权) - 面板:去掉打开后的二次调整高度与窗口高度动画,内容放得下时不回弹, 修复点击菜单栏图标关闭时被重新打开 - 更换应用图标,面板与关于页使用应用图标作为 Logo - 清理未使用的组件、格式化方法、设计 token 与辅助工具接口
48 lines
2.2 KiB
Swift
48 lines
2.2 KiB
Swift
import Foundation
|
|
|
|
public enum HelperConstants {
|
|
public static let machServiceName = "com.openstats.helper"
|
|
public static let launchdPlistName = "com.openstats.helper.plist"
|
|
public static let appBundleIdentifier = "com.openstats.app"
|
|
/// 与 App 版本同步;App 发现辅助工具版本不一致时提示重新安装
|
|
public static let protocolVersion = 2
|
|
|
|
/// 用 Developer ID 签名后填入 Team ID,辅助工具会据此严格校验调用方。
|
|
/// 为空时只校验 bundle identifier,仅适用于本地开发。
|
|
public static let teamIdentifier = ""
|
|
|
|
public static var clientRequirement: String {
|
|
let identifier = "identifier \"\(appBundleIdentifier)\""
|
|
guard !teamIdentifier.isEmpty else { return identifier }
|
|
return identifier + " and anchor apple generic and certificate leaf[subject.OU] = \"\(teamIdentifier)\""
|
|
}
|
|
}
|
|
|
|
/// 辅助工具以 root 运行,只暴露固定的少量操作,不提供任意命令执行能力。
|
|
/// 所有回调中的 `String?` 为错误描述,nil 表示成功。
|
|
@objc public protocol OpenStatsHelperProtocol {
|
|
func protocolVersion(reply: @escaping @Sendable (Int) -> Void)
|
|
func setFanTarget(fan: Int, rpm: Double, reply: @escaping @Sendable (String?) -> Void)
|
|
func setFanAutomatic(fan: Int, reply: @escaping @Sendable (String?) -> Void)
|
|
func resetAllFans(reply: @escaping @Sendable (String?) -> Void)
|
|
func setSleepDisabled(_ disabled: Bool, reply: @escaping @Sendable (String?) -> Void)
|
|
func flushDNSCache(reply: @escaping @Sendable (String?) -> Void)
|
|
func purgeMemory(reply: @escaping @Sendable (String?) -> Void)
|
|
}
|
|
|
|
/// 需要管理员权限的系统维护命令。辅助工具与未安装辅助工具时的授权回退共用同一份固定命令
|
|
public enum MaintenanceCommand: String, Sendable, CaseIterable {
|
|
case flushDNS, purgeMemory
|
|
|
|
public var steps: [(path: String, arguments: [String])] {
|
|
switch self {
|
|
case .flushDNS: [("/usr/bin/dscacheutil", ["-flushcache"]), ("/usr/bin/killall", ["-HUP", "mDNSResponder"])]
|
|
case .purgeMemory: [("/usr/sbin/purge", [])]
|
|
}
|
|
}
|
|
|
|
public var shellCommand: String {
|
|
steps.map { ([$0.path] + $0.arguments).joined(separator: " ") }.joined(separator: "; ")
|
|
}
|
|
}
|