Files
damus/damus/damusApp.swift
2023-02-18 09:34:50 -08:00

50 lines
1.0 KiB
Swift

//
// damusApp.swift
// damus
//
// Created by William Casarin on 2022-04-01.
//
import SwiftUI
@main
struct damusApp: App {
var body: some Scene {
WindowGroup {
MainView()
}
}
}
struct MainView: View {
@State var needs_setup = false;
@State var keypair: Keypair? = nil;
var body: some View {
Group {
if let kp = keypair, !needs_setup {
ContentView(keypair: kp)
} else {
SetupView()
.onReceive(handle_notify(.login)) { notif in
needs_setup = false
keypair = get_saved_keypair()
}
}
}
.dynamicTypeSize(.xSmall ... .xxxLarge)
.onReceive(handle_notify(.logout)) { _ in
try? clear_keypair()
keypair = nil
}
.onAppear {
keypair = get_saved_keypair()
}
}
}
func needs_setup() -> Keypair? {
return get_saved_keypair()
}