Skip to content

Commit

Permalink
fix: autostart not toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaiibuzzle committed Jan 12, 2024
1 parent 0094fd3 commit 3960c0d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions USBNotifier/Core/LaunchAtStartup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import Foundation
import ServiceManagement

struct LaunchAtStartup {
fileprivate static let observable = Observable()
static public var shared = LaunchAtStartup()

public static var status: Bool {
fileprivate let observable = Observable()

public var status: Bool {
get { SMAppService.mainApp.status == .enabled }
set {
observable.objectWillChange.send()
if newValue {
setItemLaunchAtLogin()
} else {
Expand All @@ -23,7 +24,7 @@ struct LaunchAtStartup {
}
}

private static func setItemLaunchAtLogin() {
private func setItemLaunchAtLogin() {
// Use SMAppService.register because Apple is Apple.
do {
if status == true {
Expand All @@ -35,7 +36,7 @@ struct LaunchAtStartup {
}
}

private static func unsetItemLaunchAtLogin() {
private func unsetItemLaunchAtLogin() {
do {
try SMAppService.mainApp.unregister()
} catch {
Expand All @@ -47,9 +48,10 @@ struct LaunchAtStartup {
extension LaunchAtStartup {
final class Observable: ObservableObject {
var status: Bool {
get { LaunchAtStartup.status }
get { LaunchAtStartup.shared.status }
set {
LaunchAtStartup.status = newValue
LaunchAtStartup.shared.status = newValue
objectWillChange.send()
}
}
}
Expand Down

0 comments on commit 3960c0d

Please sign in to comment.