mirror of
https://github.com/bolucat/Archive.git
synced 2026-04-23 00:17:16 +08:00
40 lines
1.1 KiB
Swift
40 lines
1.1 KiB
Swift
#if os(macOS)
|
|
|
|
import Library
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
public struct InstallSystemExtensionButton: View {
|
|
@State private var alert: Alert?
|
|
private let callback: () async -> Void
|
|
public init(_ callback: @escaping () async -> Void) {
|
|
self.callback = callback
|
|
}
|
|
|
|
public var body: some View {
|
|
FormButton {
|
|
Task {
|
|
await installSystemExtension()
|
|
}
|
|
} label: {
|
|
Label("Install System Extension", systemImage: "lock.doc.fill")
|
|
}
|
|
.alertBinding($alert)
|
|
}
|
|
|
|
private func installSystemExtension() async {
|
|
do {
|
|
if let result = try await SystemExtension.install() {
|
|
if result == .willCompleteAfterReboot {
|
|
alert = Alert(errorMessage: String(localized: "Need Reboot"))
|
|
}
|
|
}
|
|
await callback()
|
|
} catch {
|
|
alert = Alert(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|