Add demo instance, remove public manifest

This commit is contained in:
Arkadiusz Fal
2022-10-26 13:11:35 +02:00
parent 8ab6a0fa89
commit 1fe01808a4
16 changed files with 488 additions and 58 deletions

View File

@@ -9,7 +9,7 @@ extension Defaults.Keys {
static let instancesManifest = Key<String>("instancesManifest", default: "")
static let countryOfPublicInstances = Key<String?>("countryOfPublicInstances")
static let instances = Key<[Instance]>("instances", default: [])
static let instances = Key<[Instance]>("instances", default: [.init(app: .demoApp, name: "Demo", apiURL: "")])
static let accounts = Key<[Account]>("accounts", default: [])
static let lastAccountID = Key<Account.ID?>("lastAccountID")
static let lastInstanceID = Key<Instance.ID?>("lastInstanceID")
@@ -21,9 +21,7 @@ extension Defaults.Keys {
static let enableReturnYouTubeDislike = Key<Bool>("enableReturnYouTubeDislike", default: false)
static let favorites = Key<[FavoriteItem]>("favorites", default: [
.init(section: .channel("UCE_M8A5yxnLfW0KghEeajjw", "Apple"))
])
static let favorites = Key<[FavoriteItem]>("favorites", default: [])
#if !os(tvOS)
#if os(macOS)

View File

@@ -54,7 +54,7 @@ struct FavoriteItemView: View {
#endif
.onAppear {
resource?.addObserver(store)
resource?.load()
resource?.loadIfNeeded()
}
#if !os(tvOS)
.onDrag {

View File

@@ -8,6 +8,7 @@ struct AccountsNavigationLink: View {
NavigationLink(instance.longDescription) {
InstanceSettings(instance: instance)
}
.disabled(instance.app == .demoApp)
.buttonStyle(.plain)
.contextMenu {
removeInstanceButton(instance)

View File

@@ -41,28 +41,30 @@ struct LocationsSettings: View {
}
@ViewBuilder var settings: some View {
Section(header: SettingsHeader(text: "Public Locations".localized()), footer: countryFooter) {
Picker("Country", selection: $countryOfPublicInstances) {
Text("Don't use public locations").tag(String?.none)
ForEach(countries, id: \.self) { country in
Text(country).tag(Optional(country))
if !InstancesManifest.shared.manifestURL.isNil {
Section(header: SettingsHeader(text: "Public Locations".localized()), footer: countryFooter) {
Picker("Country", selection: $countryOfPublicInstances) {
Text("Don't use public locations").tag(String?.none)
ForEach(countries, id: \.self) { country in
Text(country).tag(Optional(country))
}
}
}
#if os(tvOS)
.pickerStyle(.inline)
#endif
.disabled(countries.isEmpty)
#if os(tvOS)
.pickerStyle(.inline)
#endif
.disabled(countries.isEmpty)
Button {
InstancesManifest.shared.changePublicAccount(accounts, settings: model)
} label: {
if let account = accounts.current, account.isPublic {
Text("Switch to other public location")
} else {
Text("Switch to public locations")
Button {
InstancesManifest.shared.changePublicAccount(accounts, settings: model)
} label: {
if let account = accounts.current, account.isPublic {
Text("Switch to other public location")
} else {
Text("Switch to public locations")
}
}
.disabled(countryOfPublicInstances.isNil)
}
.disabled(countryOfPublicInstances.isNil)
}
Section(header: SettingsHeader(text: "Custom Locations".localized())) {
@@ -92,7 +94,8 @@ struct LocationsSettings: View {
}
func loadCountries() {
InstancesManifest.shared.instancesList.load()
InstancesManifest.shared.configure()
InstancesManifest.shared.instancesList?.load()
.onSuccess { response in
if let instances: [ManifestedInstance] = response.typedContent() {
self.countries = instances.map(\.country).unique().sorted()

View File

@@ -31,6 +31,7 @@ struct PlayerSettings: View {
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
@Default(.systemControlsCommands) private var systemControlsCommands
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlayerModel> private var player
#if os(iOS)
@@ -99,7 +100,10 @@ struct PlayerSettings: View {
keywordsToggle
showHistoryToggle
returnYouTubeDislikeToggle
if !accounts.isDemo {
returnYouTubeDislikeToggle
}
}
#if os(iOS)

View File

@@ -15,7 +15,9 @@ struct ShareButton: View {
Menu {
instanceActions
Divider()
youtubeActions
if !accounts.isDemo {
youtubeActions
}
} label: {
Label("Share...", systemImage: "square.and.arrow.up")
}

View File

@@ -67,7 +67,7 @@ struct WelcomeScreen: View {
.foregroundColor(.secondary)
}
.onAppear {
resource.load().onSuccess { response in
resource?.load().onSuccess { response in
if let instances: [ManifestedInstance] = response.typedContent() {
store = instances
}
@@ -85,7 +85,7 @@ struct WelcomeScreen: View {
store.first { $0.country == country }?.flag
}
var resource: Resource {
var resource: Resource? {
InstancesManifest.shared.instancesList
}
}

View File

@@ -174,13 +174,8 @@ struct YatteeApp: App {
accounts.configureAccount()
}
let countryOfPublicInstances = Defaults[.countryOfPublicInstances]
if accounts.current.isNil, countryOfPublicInstances.isNil {
navigation.presentingWelcomeScreen = true
}
if !countryOfPublicInstances.isNil {
InstancesManifest.shared.setPublicAccount(countryOfPublicInstances!, accounts: accounts, asCurrent: accounts.current.isNil)
if let countryOfPublicInstances = Defaults[.countryOfPublicInstances] {
InstancesManifest.shared.setPublicAccount(countryOfPublicInstances, accounts: accounts, asCurrent: accounts.current.isNil)
}
playlists.accounts = accounts