mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-10 11:37:23 +01:00
Add main actor trampolines
This commit is contained in:
17
Sources/Secretive/Helpers/MainActorWrappers.swift
Normal file
17
Sources/Secretive/Helpers/MainActorWrappers.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
import Foundation
|
||||
|
||||
func mainActorWrapped(_ f: @escaping @MainActor () -> Void) -> () -> Void {
|
||||
return {
|
||||
DispatchQueue.main.async {
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mainActorWrapped<T: Sendable>(_ f: @escaping @MainActor (T) -> Void) -> (T) -> Void {
|
||||
return { x in
|
||||
DispatchQueue.main.async {
|
||||
f(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
showing = false
|
||||
}
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Button("Create", action: save)
|
||||
Button("Create", action: mainActorWrapped(save))
|
||||
.disabled(name.isEmpty)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Delete", action: delete)
|
||||
Button("Delete", action: mainActorWrapped(delete))
|
||||
.disabled(confirm != secret.name)
|
||||
.keyboardShortcut(.delete)
|
||||
Button("Don't Delete") {
|
||||
|
||||
@@ -28,7 +28,7 @@ struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Rename", action: rename)
|
||||
Button("Rename", action: mainActorWrapped(rename))
|
||||
.disabled(newName.count == 0)
|
||||
.keyboardShortcut(.return)
|
||||
Button("Cancel") {
|
||||
|
||||
@@ -31,8 +31,8 @@ struct StoreListView: View {
|
||||
store: store,
|
||||
secret: secret,
|
||||
activeSecret: $activeSecret,
|
||||
deletedSecret: self.secretDeleted,
|
||||
renamedSecret: self.secretRenamed
|
||||
deletedSecret: mainActorWrapped(self.secretDeleted),
|
||||
renamedSecret: mainActorWrapped(self.secretRenamed)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user