Skip to content

Commit 056d06f

Browse files
committed
fix: decrypter view file picker doesn't work anymore
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent f4b839d commit 056d06f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sushitrain/DecrypterView.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import SwiftUI
77
@preconcurrency import SushitrainCore
88

99
#if os(macOS)
10-
1110
struct DecrypterView: View {
1211
private enum PickerFor {
1312
case source
1413
case dest
1514
}
1615

16+
// The 'showPicker' variable controls fileImporter visibility, and showPickerFor decides what it is picking for.
17+
// We can't just use Binding.isNotNull(showPickerFor) for fileImporter visibility, because it is set to nil before
18+
// the callback is able to determine its value.
1719
@State private var showPickerFor: PickerFor? = nil
18-
@State private var showDestPicker: Bool = false
20+
@State private var showPicker: Bool = false
21+
1922
@State private var error: Error? = nil
2023
@State private var loading: Bool = false
2124
@State private var sourceURL: URL? = nil
@@ -41,6 +44,7 @@ import SwiftUI
4144
Text(sourceURL?.lastPathComponent ?? "")
4245
Button("Select...") {
4346
showPickerFor = .source
47+
showPicker = true
4448
}
4549
}
4650
}
@@ -65,6 +69,7 @@ import SwiftUI
6569
Text(destURL?.lastPathComponent ?? "")
6670
Button("Select...") {
6771
showPickerFor = .dest
72+
showPicker = true
6873
}
6974
}
7075
}
@@ -110,7 +115,7 @@ import SwiftUI
110115
}.frame(minWidth: 400, maxWidth: .infinity, maxHeight: .infinity)
111116
}
112117
.frame(maxWidth: .infinity, maxHeight: .infinity)
113-
.fileImporter(isPresented: Binding.isNotNil($showPickerFor), allowedContentTypes: [.directory]) { (result) in
118+
.fileImporter(isPresented: $showPicker, allowedContentTypes: [.directory]) { (result) in
114119
switch (result, showPickerFor) {
115120
case (.success(let url), .source):
116121
self.sourceURL = url
@@ -129,6 +134,7 @@ import SwiftUI
129134
default:
130135
break
131136
}
137+
self.showPicker = false
132138
self.showPickerFor = nil
133139
}
134140
.navigationTitle(self.sourceURL?.lastPathComponent ?? String(localized: "Decrypt folder"))

0 commit comments

Comments
 (0)