Skip to content

Commit 3a520d5

Browse files
authored
fix: canvas preview panic in Xcode resolved (#82)
The preview was panicking because the app state had an optional base URL, which is getting unwrapped elsewhere. This creates an app state and then 'logs in' to set the base URL, reenabling the preview. Change-Id: I8d6a19063a13f772dc409bc5e523e1af9c109bee Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 5b4b174 commit 3a520d5

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Coder Desktop/Coder Desktop/State.swift

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppState: ObservableObject {
2525
// Stored in Keychain
2626
@Published private(set) var sessionToken: String? {
2727
didSet {
28+
guard persistent else { return }
2829
keychainSet(sessionToken, for: Keys.sessionToken)
2930
}
3031
}

Coder Desktop/Coder Desktop/Views/LoginForm.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,6 @@ enum LoginField: Hashable {
221221
#if DEBUG
222222
#Preview {
223223
LoginForm()
224-
.environmentObject(AppState())
224+
.environmentObject(AppState(persistent: false))
225225
}
226226
#endif

Coder Desktop/Coder Desktop/Views/VPNMenu.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ func openSystemExtensionSettings() {
104104

105105
#if DEBUG
106106
#Preview {
107-
VPNMenu<PreviewVPN>().frame(width: 256)
107+
let appState = AppState(persistent: false)
108+
appState.login(baseAccessURL: URL(string: "http://127.0.0.1:8080")!, sessionToken: "")
109+
// appState.clearSession()
110+
111+
return VPNMenu<PreviewVPN>().frame(width: 256)
108112
.environmentObject(PreviewVPN())
109-
.environmentObject(AppState(persistent: false))
113+
.environmentObject(appState)
110114
}
111115
#endif

0 commit comments

Comments
 (0)