Files
sing-box-for-apple/ApplicationLibrary/Views/Dashboard/InstallSystemExtensionButton.swift
T
2023-07-26 20:38:51 +08:00

37 lines
963 B
Swift

#if os(macOS)
import Library
import SwiftUI
public struct InstallSystemExtensionButton: View {
@State private var alert: Alert?
private let callback: () -> Void
public init(_ callback: @escaping () -> Void) {
self.callback = callback
}
public var body: some View {
Button("Install SystemExtension") {
Task {
await installSystemExtension()
}
}
.alertBinding($alert)
}
private func installSystemExtension() async {
do {
if let result = try await SystemExtension.install() {
if result == .willCompleteAfterReboot {
alert = Alert(errorMessage: "Need Reboot")
}
}
callback()
} catch {
alert = Alert(error)
}
}
}
#endif