Add auto-start on login via osascript subprocess
Some checks are pending
CI / semgrep (push) Waiting to run

This commit is contained in:
AgentSeal 2026-04-24 13:50:32 +02:00
parent b3b0dfbf60
commit f893c964cc

View file

@ -1,7 +1,6 @@
import SwiftUI
import AppKit
import Observation
import ServiceManagement
private let refreshIntervalSeconds: UInt64 = 15
private let nanosPerSecond: UInt64 = 1_000_000_000
@ -136,13 +135,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate {
}
private func registerLoginItemIfNeeded() {
let service = SMAppService.mainApp
if service.status == .notRegistered {
do {
try service.register()
} catch {
NSLog("CodeBurn: Login item registration failed: \(error)")
let key = "codeburn.loginItemRegistered"
guard !UserDefaults.standard.bool(forKey: key) else { return }
let appPath = Bundle.main.bundlePath
let script = "tell application \"System Events\" to make login item at end with properties {path:\"\(appPath)\", hidden:false}"
let process = Process()
process.launchPath = "/usr/bin/osascript"
process.arguments = ["-e", script]
process.standardOutput = FileHandle.nullDevice
process.standardError = FileHandle.nullDevice
do {
try process.run()
process.waitUntilExit()
if process.terminationStatus == 0 {
UserDefaults.standard.set(true, forKey: key)
}
} catch {
NSLog("CodeBurn: Login item registration failed: \(error)")
}
}