Skip to content
Open
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
4 changes: 3 additions & 1 deletion PRODUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Avoid SaaS dashboard gradients, decorative glassmorphism, vague neon palettes, o
- Prefer native macOS and WidgetKit behavior over custom machinery.
- The default Summer theme uses ocean teal, sky blue, warm sand, and sunlit amber over deep coastal surfaces.
- Use teal for selection and primary actions, amber for warmth and attention, and semantic system colors for status.
- First run uses one aligned setup sheet with explicit Codex access, background refresh, and widget-registration requirements. Setup remains replayable from Help.
- First run uses one aligned setup sheet with explicit Codex access and widget-registration requirements. Setup remains replayable from Help.
- Refresh from local source events while Runway and ChatGPT or Codex are running, plus explicit launch, foreground, and manual actions. Keep cached usage readable after either app quits without scheduled background work.
- Widgets keep their last observation between changed snapshots. Optional reset alerts require a confirming refresh; automatic alerts require Runway and ChatGPT or Codex to be running.
- The app icon and decorative symbols may use restrained beach, sun, wave, and palm motifs without competing with the data.
- Widget surfaces stay restrained and instrument-like while respecting WidgetKit monochrome and tinted rendering.
- Label graph scaling explicitly: each chart is normalized to the largest visible day, shown as its peak value rather than an unexplained percentage.
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ These previews use an anonymous ad-hoc signature and are not Apple-notarized. Ho

## See the app

![Runway appearance and background monitoring settings in Runway Glass](docs/screenshots/runway-settings.png)
![Runway appearance and monitoring settings in Runway Glass](docs/screenshots/runway-settings.png)

![Runway appearance and monitoring settings in the Graphite theme](docs/screenshots/runway-dark-settings.png)

Screenshots show local preview builds. Empty queues and standby states are shown where applicable.
Screenshots show local preview builds and may include retired controls. Empty queues and standby states are shown where applicable.


## Forks and attribution
Expand Down Expand Up @@ -90,10 +90,19 @@ are available in the release downloads. The native macOS app retains the full wi
- Top model today, seven days, this month, and lifetime
- Headroom tokens saved, savings rate, and estimated cost avoided
- Live account five-hour and weekly Codex limits, reset times, pace, and local seven-day history
- A native menu bar meter with percentage, meter, and reset-countdown modes
- Background widget snapshots every minute while the app is closed
- A native menu bar meter with percentage, meter, and reset-time modes
- Event-driven usage updates while Runway and ChatGPT or Codex are running; cached widgets remain readable after either app quits
- Independent settings for small, medium, and large widgets

Runway has no periodic background refresh service. Open Runway to resume automatic
updates, or refresh manually at any time. Widgets retain their last observation
until Runway publishes a changed snapshot. Optional desktop and iPhone reset alerts
depend on a refresh confirming the reset; automatic alerts require Runway and
ChatGPT or Codex to be running.

App updates are checked manually with **Runway → Check for Updates…**; there are
no scheduled update checks.

## Privacy

Runway reads local Codex logs and the local Headroom database. When
Expand Down
5 changes: 3 additions & 2 deletions Runway/AppUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ final class AppUpdater: ObservableObject {

private init() {
controller = SPUStandardUpdaterController(
startingUpdater: true,
startingUpdater: false,
updaterDelegate: nil,
userDriverDelegate: nil
)
controller.updater.checkForUpdatesInBackground()
controller.updater.automaticallyChecksForUpdates = false
controller.startUpdater()
controller.updater.publisher(for: \.canCheckForUpdates)
.assign(to: &$canCheckForUpdates)
}
Expand Down
129 changes: 27 additions & 102 deletions Runway/BackgroundRefreshAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,9 @@ struct BackgroundRefreshRecord: Codable, Equatable {
}
}

struct BackgroundRefreshAgentStatus: Sendable {
var enabled: Bool
var installed: Bool
var loaded: Bool
var lastSuccess: Date?

var detail: String {
if !enabled { return "Off" }
if !BackgroundRefreshAgent.isStableInstall {
return installed ? "Managed by the installed app" : "Move the app to Applications first"
}
if !installed || !loaded { return "Needs repair" }
guard let lastSuccess else { return "Scheduled every minute" }
return "Last refreshed \(lastSuccess.formatted(date: .omitted, time: .shortened))"
}
}

enum BackgroundRefreshAgent {
static let identifier = "com.codexusage.Runway.refresh"
static let legacyIdentifier = "com.codexusage.CodexUsageMonitor.refresh"
static let interval: TimeInterval = 60

static var isStableInstall: Bool {
let path = Bundle.main.bundleURL.standardizedFileURL.path
Expand All @@ -50,61 +32,20 @@ enum BackgroundRefreshAgent {
return path.hasPrefix("/Applications/") || path.hasPrefix(homeApplications + "/")
}

static func installIfEnabled() {
if CodexUsageSettingsStore.load().settings.backgroundRefreshEnabled {
_ = install()
} else {
_ = uninstall()
}
}

@discardableResult
static func setEnabled(_ enabled: Bool) -> Bool {
return enabled ? install() : uninstall()
}

@discardableResult
static func install() -> Bool {
guard canManageInstalledAgents,
removeAgent(identifier: legacyIdentifier),
OnboardingStateStore.hasCurrentCodexDataAccess(),
let executable = Bundle.main.executableURL
else {
return false
}
let fileManager = FileManager.default
let directory = plistURL.deletingLastPathComponent()
let plist: [String: Any] = [
"Label": identifier,
"ProgramArguments": [executable.path, "--background-refresh"],
"RunAtLoad": true,
"StartInterval": Int(interval),
"ThrottleInterval": 60,
"ProcessType": "Background",
"LowPriorityIO": true,
"Nice": 10,
"AbandonProcessGroup": true
]

do {
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
let data = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)
if (try? Data(contentsOf: plistURL)) == data, isLoaded { return true }
if isLoaded { _ = launchctl(["bootout", domain, plistURL.path]) }
try data.write(to: plistURL, options: .atomic)
guard launchctl(["bootstrap", domain, plistURL.path]) == 0 else { return false }
return isLoaded
} catch {
return false
}
}

@discardableResult
static func uninstall() -> Bool {
guard canManageInstalledAgents else { return false }
let legacyRemoved = removeAgent(identifier: legacyIdentifier)
let currentRemoved = removeAgent(identifier: identifier)
return legacyRemoved && currentRemoved
let ownService = ProcessInfo.processInfo.environment["XPC_SERVICE_NAME"]
// A launchd-invoked migration must boot out its own job last: that terminates this process.
let labels: [String] = ownService == legacyIdentifier
? [identifier, legacyIdentifier] : [legacyIdentifier, identifier]
var removed = true
for label in labels {
let result = removeAgent(identifier: label, directory: plistURL.deletingLastPathComponent(),
domain: domain, allowed: true, isOwnService: label == ownService, run: launchctl)
removed = result && removed
}
return removed
}

static func canManageAgents(bundleIdentifier: String?, isStableInstall: Bool) -> Bool {
Expand All @@ -115,27 +56,32 @@ enum BackgroundRefreshAgent {
canManageAgents(bundleIdentifier: Bundle.main.bundleIdentifier, isStableInstall: isStableInstall)
}

private static func removeAgent(identifier: String) -> Bool {
removeAgent(identifier: identifier, directory: plistURL.deletingLastPathComponent(),
domain: domain, allowed: canManageInstalledAgents, run: launchctl)
}

/// Use the service label so upgrades can stop a loaded job whose plist was moved or removed.
/// Keep its registration file intact if launchctl cannot confirm the job was stopped.
static func removeAgent(identifier: String, directory: URL, domain: String,
allowed: Bool, run: ([String]) -> Int32) -> Bool {
allowed: Bool, isOwnService: Bool = false, run: ([String]) -> Int32) -> Bool {
guard allowed else { return false }
let service = "\(domain)/\(identifier)"
let status = run(["print", service])
// `launchctl print` uses 113 for a missing service; other failures do not prove it is gone.
let serviceNotFound: Int32 = 113
guard status == 0 || status == serviceNotFound else { return false }
let registrationURL = directory.appendingPathComponent("\(identifier).plist")
let registration = isOwnService ? try? Data(contentsOf: registrationURL) : nil
if isOwnService && FileManager.default.fileExists(atPath: registrationURL.path) {
// Self-bootout may never return, so remove the recurring registration first.
guard registration != nil else { return false }
do { try FileManager.default.removeItem(at: registrationURL) } catch { return false }
}
if status == 0 {
guard run(["bootout", service]) == 0,
run(["print", service]) == serviceNotFound else { return false }
run(["print", service]) == serviceNotFound else {
if isOwnService, let registration { try? registration.write(to: registrationURL, options: .atomic) }
return false
}
}
do {
try FileManager.default.removeItem(at: directory.appendingPathComponent("\(identifier).plist"))
try FileManager.default.removeItem(at: registrationURL)
return true
} catch let error as CocoaError where error.code == .fileNoSuchFile {
return true
Expand All @@ -144,24 +90,16 @@ enum BackgroundRefreshAgent {
}
}

static func status() -> BackgroundRefreshAgentStatus {
BackgroundRefreshAgentStatus(
enabled: CodexUsageSettingsStore.load().settings.backgroundRefreshEnabled,
installed: isStableInstall
? targetsCurrentExecutable
: FileManager.default.fileExists(atPath: plistURL.path),
loaded: isLoaded,
lastSuccess: loadRecord()?.lastSuccess
)
}

static func saveRecord(_ record: BackgroundRefreshRecord) {
do {
try FileManager.default.createDirectory(
at: CodexUsageSnapshotStore.backgroundStatusURL.deletingLastPathComponent(),
withIntermediateDirectories: true
)
try JSONEncoder().encode(record).write(to: CodexUsageSnapshotStore.backgroundStatusURL, options: .atomic)
DispatchQueue.main.async {
NotificationCenter.default.post(name: .codexUsageSnapshotDidChange, object: nil)
}
} catch {
// Status is diagnostic only; a failed status write must not fail refresh.
}
Expand All @@ -177,20 +115,7 @@ enum BackgroundRefreshAgent {
.appendingPathComponent("Library/LaunchAgents/\(identifier).plist")
}

private static var targetsCurrentExecutable: Bool {
guard let executable = Bundle.main.executableURL?.standardizedFileURL.path,
let data = try? Data(contentsOf: plistURL),
let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
let arguments = plist["ProgramArguments"] as? [String]
else {
return false
}
return arguments.first.map { URL(fileURLWithPath: $0).standardizedFileURL.path } == executable
}

private static var domain: String { "gui/\(getuid())" }
private static var service: String { "\(domain)/\(identifier)" }
private static var isLoaded: Bool { launchctl(["print", service]) == 0 }

private static func launchctl(_ arguments: [String]) -> Int32 {
let process = Process()
Expand Down
7 changes: 0 additions & 7 deletions Runway/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct DetailedContentView: View {
@State private var refreshRecord = BackgroundRefreshAgent.loadRecord()
@State private var isRefreshing = false
@State private var presentsDataHealth = false
private let snapshotTimer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()

private var health: SnapshotHealth {
SnapshotHealth(snapshot: snapshot, record: refreshRecord, isRefreshing: isRefreshing)
Expand Down Expand Up @@ -86,10 +85,6 @@ struct DetailedContentView: View {
snapshot = SnapshotDisplay.load() ?? snapshot
refreshRecord = BackgroundRefreshAgent.loadRecord()
}
.onReceive(snapshotTimer) { _ in
snapshot = SnapshotDisplay.load() ?? snapshot
refreshRecord = BackgroundRefreshAgent.loadRecord()
}
}
}

Expand All @@ -114,7 +109,6 @@ struct ContentView: View {
@State private var refreshRecord = BackgroundRefreshAgent.loadRecord()
@State private var showsRefreshFailure = false
@State private var refreshFailureMessage = ""
private let timer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()

private var activity: CodexSessionActivity? {
snapshot.sessionActivity.first { $0.id == selectedSessionID }
Expand Down Expand Up @@ -147,7 +141,6 @@ struct ContentView: View {
.hidden().accessibilityHidden(true)
}
}
.onReceive(timer) { _ in reload() }
.onReceive(NotificationCenter.default.publisher(for: .codexUsageSnapshotDidChange)) { _ in reload() }
.onExitCommand(perform: dismissRail)
.alert("Refresh failed", isPresented: $showsRefreshFailure) {
Expand Down
2 changes: 1 addition & 1 deletion Runway/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<key>NSAppDataUsageDescription</key>
<string>Reads local Codex and Headroom usage files to update your statistics and widgets. Nothing is uploaded.</string>
<key>SUEnableAutomaticChecks</key>
<true/>
<false/>
<key>SUScheduledCheckInterval</key>
<integer>86400</integer>
<key>SUAutomaticallyUpdate</key>
Expand Down
33 changes: 2 additions & 31 deletions Runway/LimitViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,16 @@ struct LimitPreferencesView: View {
var showsMonitoring = true
var showsNotifications = true
@EnvironmentObject private var settingsModel: CodexUsageSettingsModel
@State private var agentStatus = BackgroundRefreshAgentStatus(
enabled: CodexUsageSettingsStore.load().settings.backgroundRefreshEnabled,
installed: false,
loaded: false,
lastSuccess: nil
)
@State private var phoneTopicURL: String?
@State private var phoneTestStatus: String?

var body: some View {
VStack(alignment: .leading, spacing: 10) {
if showsMonitoring {
Toggle("Continue monitoring after you quit", isOn: $settingsModel.settings.backgroundRefreshEnabled)
.onChange(of: settingsModel.settings.backgroundRefreshEnabled) { _, enabled in
updateAgentStatus { _ = BackgroundRefreshAgent.setEnabled(enabled) }
}
Text(agentStatus.detail)
Text("Updates follow local changes while Runway and ChatGPT or Codex are running. Widgets keep their last snapshot after either app quits. You can refresh manually at any time.")
.font(.system(size: 10))
.foregroundStyle(.secondary)

if settingsModel.settings.backgroundRefreshEnabled && (!agentStatus.installed || !agentStatus.loaded) {
Button("Repair background refresh") {
updateAgentStatus { _ = BackgroundRefreshAgent.install() }
}
.buttonStyle(.link)
}

LabeledContent("Menu bar") {
Picker("Menu bar", selection: $settingsModel.settings.menuBarDisplayMode) {
ForEach(MenuBarDisplayMode.allCases) { mode in
Expand Down Expand Up @@ -196,15 +179,13 @@ struct LimitPreferencesView: View {
.onChange(of: settingsModel.settings.phoneNotificationsEnabled) { _, enabled in
if enabled {
phoneTopicURL = PhoneResetNotificationManager.ensureTopic().map { "https://ntfy.sh/\($0)" }
settingsModel.settings.backgroundRefreshEnabled = true
updateAgentStatus { _ = BackgroundRefreshAgent.install() }
} else {
Task { await PhoneResetNotificationManager.cancelScheduled() }
}
}

if settingsModel.settings.phoneNotificationsEnabled {
Text("Install ntfy on your iPhone, then subscribe to this private topic. The topic is stored in Keychain.")
Text("Automatic reset alerts require Runway and ChatGPT or Codex to be running. Install ntfy on your iPhone, then subscribe to this private topic. The topic is stored in Keychain.")
.font(.system(size: 10))
.foregroundStyle(.secondary)
if let phoneTopicURL {
Expand Down Expand Up @@ -247,19 +228,9 @@ struct LimitPreferencesView: View {
}
}
.onAppear {
updateAgentStatus()
if settingsModel.settings.phoneNotificationsEnabled {
phoneTopicURL = PhoneResetNotificationManager.topicURL
}
}
}

private func updateAgentStatus(action: @escaping @Sendable () -> Void = {}) {
Task {
agentStatus = await Task.detached(priority: .utility) {
action()
return BackgroundRefreshAgent.status()
}.value
}
}
}
Loading
Loading