Skip to content
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ managed Git worktrees. Requires the `timber` CLI and an Xcode toolchain.
- Failures post a macOS notification; never silently.
- Keyboard: Up/Down move, Return activates, Esc closes form / clears
filter, Ctrl+U clears.
- Right-click (or Ctrl-click) the menubar icon for a Quit menu;
- Right-click (or Ctrl-click) the menubar icon for an Open at Login toggle
and Quit;
left-click toggles the popover.

Notes on parity: enumeration is implemented natively with FileManager
Expand Down
23 changes: 23 additions & 0 deletions Sources/Timber/TimberApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,36 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
guard let button = statusItem?.button, let popover else { return }
popover.performClose(nil)
let menu = NSMenu()
let loginItem = NSMenuItem(
title: "Open at Login",
action: #selector(toggleOpenAtLogin(_:)),
keyEquivalent: ""
)
loginItem.target = self
loginItem.state = TimberLoginItem.isEnabled ? .on : .off
menu.addItem(loginItem)
menu.addItem(.separator())
menu.addItem(NSMenuItem(
title: "Quit Timber",
action: #selector(NSApplication.terminate(_:)),
keyEquivalent: "q"
))
menu.popUp(positioning: nil, at: NSPoint(x: 0, y: button.bounds.height), in: button)
}

@objc private func toggleOpenAtLogin(_ sender: NSMenuItem) {
let enabled = sender.state != .on
do {
try TimberLoginItem.setEnabled(enabled)
sender.state = enabled ? .on : .off
} catch {
TimberCommand.notify(
subject: enabled ? "open at login" : "remove from login",
detail: error.localizedDescription,
failure: true
)
}
}
}

// Note: there is deliberately no SwiftUI App scene here. The entry point
Expand Down
20 changes: 20 additions & 0 deletions Sources/Timber/TimberLoginItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import ServiceManagement

/// Login-item wrapper around SMAppService.mainApp so the status-item menu
/// can offer an "Open at Login" toggle. Thin on purpose: the only
/// behavior is reading the current status and (un)registering, with
/// errors propagated so callers can notify instead of failing silently.
enum TimberLoginItem {
static var isEnabled: Bool {
SMAppService.mainApp.status == .enabled
}

static func setEnabled(_ enabled: Bool) throws {
if enabled {
try SMAppService.mainApp.register()
} else {
try SMAppService.mainApp.unregister()
}
}
}
Loading