UI improvements

This commit is contained in:
Arkadiusz Fal 2021-11-07 17:52:42 +01:00
parent 63406a2933
commit 7d247bddb3
11 changed files with 71 additions and 45 deletions

View File

@ -58,6 +58,15 @@ final class PlayerModel: ObservableObject {
var playingInPictureInPicture = false var playingInPictureInPicture = false
@Published var presentingErrorDetails = false
var playerError: Error? { didSet {
#if !os(tvOS)
if !playerError.isNil {
presentingErrorDetails = true
}
#endif
}}
init(accounts: AccountsModel? = nil, instances: InstancesModel? = nil) { init(accounts: AccountsModel? = nil, instances: InstancesModel? = nil) {
self.accounts = accounts ?? AccountsModel() self.accounts = accounts ?? AccountsModel()
self.instances = instances ?? InstancesModel() self.instances = instances ?? InstancesModel()
@ -123,6 +132,7 @@ final class PlayerModel: ObservableObject {
of video: Video, of video: Video,
preservingTime: Bool = false preservingTime: Bool = false
) { ) {
playerError = nil
resetSegments() resetSegments()
sponsorBlock.loadSegments(videoID: video.videoID, categories: Defaults[.sponsorBlockCategories]) sponsorBlock.loadSegments(videoID: video.videoID, categories: Defaults[.sponsorBlockCategories])
@ -298,8 +308,7 @@ final class PlayerModel: ObservableObject {
self.play() self.play()
} }
case .failed: case .failed:
print("item error: \(String(describing: item.error))") self.playerError = item.error
print((item.asset as! AVURLAsset).url)
default: default:
return return

View File

@ -1,15 +0,0 @@
:root {
color-scheme: light dark;
}
body {
width: 100px;
padding: 10px;
font-family: system-ui;
text-align: center;
}
@media (prefers-color-scheme: dark) {
/* Dark Mode styles go here. */
}

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="popup.css">
<script type="module" src="popup.js"></script>
</head>
<body>
<strong>Hello World!</strong>
</body>
</html>

View File

@ -1 +0,0 @@
console.log("Hello World!", browser);

View File

@ -17,7 +17,7 @@ function redirect() {
} }
function replaceContentWithLink() { function replaceContentWithLink() {
document.querySelector('body').innerHTML = yatteeLink(); document.querySelector('body').innerHTML = '<h1>' + yatteeLink() + '</h1>';
} }
function redirectAndReplaceContentWithLink(){ function redirectAndReplaceContentWithLink(){

View File

@ -11,6 +11,24 @@
} }
}, },
"idiom" : "universal" "idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.263",
"green" : "0.290",
"red" : "0.859"
}
},
"idiom" : "universal"
} }
], ],
"info" : { "info" : {

View File

@ -10,24 +10,37 @@ struct FavoritesView: View {
@State private var dragging: FavoriteItem? @State private var dragging: FavoriteItem?
@State private var presentingEditFavorites = false @State private var presentingEditFavorites = false
@State private var favoritesChanged = false
var favoritesObserver: Any?
#if !os(tvOS)
@Default(.favorites) private var favorites
#endif
var body: some View { var body: some View {
PlayerControlsView { PlayerControlsView {
ScrollView(.vertical, showsIndicators: false) { ScrollView(.vertical, showsIndicators: false) {
if !accounts.current.isNil { if !accounts.current.isNil {
ForEach(Defaults[.favorites]) { item in
FavoriteItemView(item: item, dragging: $dragging)
}
#if os(tvOS) #if os(tvOS)
Button { ForEach(Defaults[.favorites]) { item in
presentingEditFavorites = true FavoriteItemView(item: item, dragging: $dragging)
} label: { }
Text("Edit Favorites...") #else
ForEach(favorites) { item in
FavoriteItemView(item: item, dragging: $dragging)
} }
#endif #endif
} }
} }
.redrawOn(change: presentingEditFavorites) .onAppear {
Defaults.observe(.favorites) { _ in
favoritesChanged.toggle()
}
.tieToLifetime(of: accounts)
}
.redrawOn(change: favoritesChanged)
#if os(tvOS) #if os(tvOS)
.sheet(isPresented: $presentingEditFavorites) { .sheet(isPresented: $presentingEditFavorites) {
EditFavorites() EditFavorites()

View File

@ -26,7 +26,7 @@ struct Sidebar: View {
} }
.navigationTitle("Yattee") .navigationTitle("Yattee")
#if os(iOS) #if os(iOS)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
#endif #endif
} }

View File

@ -34,6 +34,14 @@ struct PlaybackBar: View {
Image(systemName: "dot.radiowaves.left.and.right") Image(systemName: "dot.radiowaves.left.and.right")
} else if player.isLoadingAvailableStreams || player.isLoadingStream { } else if player.isLoadingAvailableStreams || player.isLoadingStream {
Image(systemName: "bolt.horizontal.fill") Image(systemName: "bolt.horizontal.fill")
} else if !player.playerError.isNil {
Button {
player.presentingErrorDetails = true
} label: {
Image(systemName: "exclamationmark.circle.fill")
.foregroundColor(.red)
}
.buttonStyle(.plain)
} }
streamControl streamControl
@ -57,6 +65,9 @@ struct PlaybackBar: View {
Spacer() Spacer()
} }
} }
.alert(player.playerError?.localizedDescription ?? "", isPresented: $player.presentingErrorDetails) {
Button("OK") {}
}
.environment(\.colorScheme, .dark) .environment(\.colorScheme, .dark)
.frame(minWidth: 0, maxWidth: .infinity) .frame(minWidth: 0, maxWidth: .infinity)
.padding(4) .padding(4)

View File

@ -55,6 +55,12 @@ struct SettingsView: View {
List { List {
#if os(tvOS) #if os(tvOS)
AccountSelectionView() AccountSelectionView()
Section(header: SettingsHeader(text: "Favorites")) {
NavigationLink("Edit favorites...") {
EditFavorites()
}
}
#endif #endif
InstancesSettings() InstancesSettings()
BrowsingSettings() BrowsingSettings()

View File

@ -11,11 +11,6 @@ struct EditFavorites: View {
var body: some View { var body: some View {
VStack { VStack {
ScrollView { ScrollView {
Text("Edit Favorites")
.font(.system(size: 40))
.fontWeight(.bold)
.foregroundColor(.secondary)
ForEach(favorites) { item in ForEach(favorites) { item in
HStack { HStack {
Text(label(item)) Text(label(item))
@ -75,6 +70,7 @@ struct EditFavorites: View {
} }
.frame(width: 1000, alignment: .leading) .frame(width: 1000, alignment: .leading)
} }
.navigationTitle("Edit Favorites")
} }
func label(_ item: FavoriteItem) -> String { func label(_ item: FavoriteItem) -> String {