mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-04-28 06:59:37 +00:00
Add auto-start on login via osascript subprocess
Some checks are pending
CI / semgrep (push) Waiting to run
Some checks are pending
CI / semgrep (push) Waiting to run
This commit is contained in:
parent
b3b0dfbf60
commit
f893c964cc
1 changed files with 19 additions and 7 deletions
|
|
@ -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)")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue