Skip to content

Commit

Permalink
fix: SwiftUI convenience for managing service startup (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Jan 29, 2024
1 parent 1aee051 commit f5ccc81
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Sources/Interact/Utilities/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,38 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import ServiceManagement
import SwiftUI

public struct Application {
public class Application: ObservableObject {

public static var shared = Application()

@available(macOS 13.0, *)
@available(iOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
@MainActor public var openAtLogin: Bool {
get {
return SMAppService.mainApp.status == .enabled
}
set {
objectWillChange.send()
do {
if newValue {
if SMAppService.mainApp.status == .enabled {
try? SMAppService.mainApp.unregister()
}
try SMAppService.mainApp.register()
} else {
try SMAppService.mainApp.unregister()
}
} catch {
print("Failed to update service with error \(error).")
}
}
}

public static func open(_ url: URL) {
#if os(macOS)
Expand Down

0 comments on commit f5ccc81

Please sign in to comment.