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

@@ -3,7 +3,6 @@ import SwiftUI
struct AccountsMenuView: View {
@EnvironmentObject<AccountsModel> private var model
@EnvironmentObject<InstancesModel> private var instancesModel
@Default(.instances) private var instances

View File

@@ -37,7 +37,12 @@ struct AppSidebarNavigation: View {
.toolbar { toolbarContent }
.frame(minWidth: sidebarMinWidth)
Text("Select section")
VStack {
Image(systemName: "play.tv")
.renderingMode(.original)
.font(.system(size: 60))
.foregroundColor(.accentColor)
}
}
.environment(\.navigationStyle, .sidebar)
}

View File

@@ -39,6 +39,11 @@ struct ContentView: View {
.environmentObject(recents)
.environmentObject(search)
.environmentObject(subscriptions)
.sheet(isPresented: $navigation.presentingWelcomeScreen) {
WelcomeScreen()
.environmentObject(accounts)
.environmentObject(navigation)
}
#if os(iOS)
.fullScreenCover(isPresented: $player.presentingPlayer) {
VideoPlayerView()
@@ -68,8 +73,9 @@ struct ContentView: View {
PlaylistFormView(playlist: $navigation.editedPlaylist)
.environmentObject(playlists)
}
.sheet(isPresented: $navigation.presentingSettings) {
.sheet(isPresented: $navigation.presentingSettings, onDismiss: openWelcomeScreenIfAccountEmpty) {
SettingsView()
.environmentObject(accounts)
.environmentObject(instances)
}
#endif
@@ -78,17 +84,29 @@ struct ContentView: View {
func configure() {
SiestaLog.Category.enabled = .common
// TODO: Remove when piped supports videos information
if let account = instances.defaultAccount ??
// TODO: Remove when piped supports videos information
accounts.all.first(where: { $0.instance.app == .invidious })
{
accounts.setAccount(account)
}
if accounts.account.isNil {
navigation.presentingWelcomeScreen = true
}
player.accounts = accounts
playlists.accounts = accounts
search.accounts = accounts
subscriptions.accounts = accounts
}
func openWelcomeScreenIfAccountEmpty() {
guard accounts.isEmpty else {
return
}
navigation.presentingWelcomeScreen = true
}
}
struct ContentView_Previews: PreviewProvider {

View File

@@ -7,14 +7,16 @@ struct Sidebar: View {
var body: some View {
ScrollViewReader { scrollView in
List {
mainNavigationLinks
if !accounts.isEmpty {
mainNavigationLinks
AppSidebarRecents()
.id("recentlyOpened")
AppSidebarRecents()
.id("recentlyOpened")
if accounts.signedIn {
AppSidebarSubscriptions()
AppSidebarPlaylists()
if accounts.signedIn {
AppSidebarSubscriptions()
AppSidebarPlaylists()
}
}
}
.onChange(of: navigation.sidebarSectionChanged) { _ in

View File

@@ -139,7 +139,7 @@ struct PlaybackBar: View {
}
private func availableStreamsForInstance(_ instance: Instance) -> [Stream.Kind: [Stream]] {
let streams = player.availableStreams.filter { $0.instance == instance }.sorted(by: player.streamsSorter)
let streams = player.availableStreamsSorted.filter { $0.instance == instance }
return Dictionary(grouping: streams, by: \.kind!)
}

View File

@@ -36,17 +36,23 @@ struct Player: UIViewControllerRepresentable {
#if os(tvOS)
var streamingQualityMenu: UIMenu {
UIMenu(
title: "Streaming quality",
title: "Streams",
image: UIImage(systemName: "antenna.radiowaves.left.and.right"),
children: streamingQualityMenuActions
)
}
var streamingQualityMenuActions: [UIAction] {
player.availableStreamsSorted.map { stream in
let image = player.streamSelection == stream ? UIImage(systemName: "checkmark") : nil
guard !player.availableStreams.isEmpty else {
return [ // swiftlint:disable:this implicit_return
UIAction(title: "Empty", attributes: .disabled) { _ in }
]
}
return UIAction(title: stream.description, image: image) { _ in
return player.availableStreamsSorted.map { stream in
let state = player.streamSelection == stream ? UIAction.State.on : .off
return UIAction(title: stream.description, state: state) { _ in
self.player.streamSelection = stream
self.player.upgradeToStream(stream)
}

View File

@@ -4,7 +4,7 @@ import SwiftUI
struct InstancesSettingsView: View {
@Default(.instances) private var instances
@EnvironmentObject<InvidiousAPI> private var api
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<InstancesModel> private var instancesModel
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<PlaylistsModel> private var playlists
@@ -55,6 +55,9 @@ struct InstancesSettingsView: View {
private func removeInstanceButton(_ instance: Instance) -> some View {
Button("Remove", role: .destructive) {
if accounts.account?.instance == instance {
accounts.setAccount(nil)
}
instancesModel.remove(instance)
}
}

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()
}
}