Add Welcome screen

This commit is contained in:
Arkadiusz Fal
2021-10-18 01:06:00 +02:00
parent 0d1eaaca5c
commit ec395ff2e0
16 changed files with 187 additions and 42 deletions

View File

@@ -0,0 +1,27 @@
import SwiftUI
struct OpenSettingsButton: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject<NavigationModel> private var navigation
var body: some View {
Button {
dismiss()
#if os(macOS)
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
#else
navigation.presentingSettings = true
#endif
} label: {
Label("Open Settings", systemImage: "gearshape.2")
}
.buttonStyle(.borderedProminent)
}
}
struct OpenSettingsButton_Previews: PreviewProvider {
static var previews: some View {
OpenSettingsButton()
}
}

View File

@@ -50,29 +50,16 @@ struct SignInRequiredView<Content: View>: View {
#if !os(tvOS)
if instances.isEmpty {
openSettingsButton
OpenSettingsButton()
}
#endif
#if os(tvOS)
openSettingsButton
OpenSettingsButton()
#endif
}
.frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
}
var openSettingsButton: some View {
Button(action: {
#if os(macOS)
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
#else
navigation.presentingSettings = true
#endif
}) {
Text("Open Settings")
}
.buttonStyle(.borderedProminent)
}
}
struct SignInRequiredView_Previews: PreviewProvider {

View File

@@ -0,0 +1,63 @@
import SwiftUI
struct WelcomeScreen: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
var body: some View {
VStack {
Spacer()
Text("Welcome")
.font(.largeTitle)
.padding(.bottom, 10)
if accounts.all.isEmpty {
Text("To start, configure your Instances in Settings")
.foregroundColor(.secondary)
} else {
Text("To start, pick one of your accounts:")
.foregroundColor(.secondary)
#if os(tvOS)
AccountSelectionView(showHeader: false)
Button {
dismiss()
} label: {
Text("Start")
}
.opacity(accounts.account.isNil ? 0 : 1)
.disabled(accounts.account.isNil)
#else
AccountsMenuView()
.onChange(of: accounts.account) { _ in
dismiss()
}
#if os(macOS)
.frame(maxWidth: 280)
#endif
#endif
}
Spacer()
OpenSettingsButton()
Spacer()
}
.interactiveDismissDisabled()
#if os(macOS)
.frame(minWidth: 400, minHeight: 400)
#endif
}
}
struct WelcomeScreen_Previews: PreviewProvider {
static var previews: some View {
WelcomeScreen()
.injectFixtureEnvironmentObjects()
}
}