mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
@@ -33,6 +33,7 @@ extension Defaults.Keys {
|
||||
#endif
|
||||
static let accountPickerDisplaysUsername = Key<Bool>("accountPickerDisplaysUsername", default: accountPickerDisplaysUsernameDefault)
|
||||
#endif
|
||||
static let accountPickerDisplaysAnonymousAccounts = Key<Bool>("accountPickerDisplaysAnonymousAccounts", default: true)
|
||||
#if os(iOS)
|
||||
static let lockPortraitWhenBrowsing = Key<Bool>("lockPortraitWhenBrowsing", default: UIDevice.current.userInterfaceIdiom == .phone)
|
||||
#endif
|
||||
|
@@ -7,6 +7,7 @@ struct AccountsMenuView: View {
|
||||
@Default(.accounts) private var accounts
|
||||
@Default(.instances) private var instances
|
||||
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
|
||||
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
|
||||
|
||||
@ViewBuilder var body: some View {
|
||||
if !instances.isEmpty {
|
||||
@@ -48,7 +49,8 @@ struct AccountsMenuView: View {
|
||||
}
|
||||
|
||||
private var allAccounts: [Account] {
|
||||
accounts + instances.map(\.anonymousAccount) + [model.publicAccount].compactMap { $0 }
|
||||
let anonymousAccounts = accountPickerDisplaysAnonymousAccounts ? instances.map(\.anonymousAccount) : []
|
||||
return accounts + anonymousAccounts + [model.publicAccount].compactMap { $0 }
|
||||
}
|
||||
|
||||
private func accountButtonTitle(account: Account) -> String {
|
||||
|
@@ -46,11 +46,14 @@ struct ContentView: View {
|
||||
.environmentObject(settings)
|
||||
#endif
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
subscriptions.load(force: true)
|
||||
playlists.load(force: true)
|
||||
}
|
||||
.onChange(of: accounts.signedIn) { _ in
|
||||
subscriptions.load(force: true)
|
||||
playlists.load(force: true)
|
||||
}
|
||||
|
||||
.environmentObject(accounts)
|
||||
.environmentObject(comments)
|
||||
.environmentObject(instances)
|
||||
|
@@ -63,10 +63,6 @@ struct AccountForm: View {
|
||||
#if os(macOS)
|
||||
.padding(.horizontal)
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
helpButton
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
formFields
|
||||
@@ -76,33 +72,10 @@ struct AccountForm: View {
|
||||
.onChange(of: password) { _ in validate() }
|
||||
}
|
||||
|
||||
var helpButton: some View {
|
||||
Group {
|
||||
if instance.app == .invidious {
|
||||
Button {
|
||||
openURL(URL(string: "https://github.com/yattee/yattee/wiki/Adding-Invidious-instance-and-account")!)
|
||||
} label: {
|
||||
Label("How to add Invidious account?", systemImage: "questionmark.circle")
|
||||
#if os(macOS)
|
||||
.help("How to add Invidious account?")
|
||||
.labelStyle(.iconOnly)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var formFields: some View {
|
||||
Group {
|
||||
if !instance.app.accountsUsePassword {
|
||||
TextField("Name", text: $name)
|
||||
}
|
||||
|
||||
TextField(usernamePrompt, text: $username)
|
||||
|
||||
if instance.app.accountsUsePassword {
|
||||
SecureField("Password", text: $password)
|
||||
}
|
||||
TextField("Username", text: $username)
|
||||
SecureField("Password", text: $password)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +100,6 @@ struct AccountForm: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
#if os(macOS)
|
||||
helpButton
|
||||
#endif
|
||||
|
||||
Button("Save", action: submitForm)
|
||||
.disabled(!isValid)
|
||||
#if !os(tvOS)
|
||||
@@ -148,9 +117,7 @@ struct AccountForm: View {
|
||||
isValid = false
|
||||
validationDebounce.invalidate()
|
||||
|
||||
let passwordIsValid = instance.app.accountsUsePassword ? !password.isEmpty : true
|
||||
|
||||
guard !username.isEmpty, passwordIsValid else {
|
||||
guard !username.isEmpty, !password.isEmpty else {
|
||||
validator.reset()
|
||||
return
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ struct BrowsingSettings: View {
|
||||
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
|
||||
@Default(.roundedThumbnails) private var roundedThumbnails
|
||||
#endif
|
||||
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
|
||||
#if os(iOS)
|
||||
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
||||
#endif
|
||||
@@ -37,9 +38,7 @@ struct BrowsingSettings: View {
|
||||
|
||||
private var sections: some View {
|
||||
Group {
|
||||
#if !os(tvOS)
|
||||
interfaceSettings
|
||||
#endif
|
||||
interfaceSettings
|
||||
thumbnailsSettings
|
||||
visibleSectionsSettings
|
||||
}
|
||||
@@ -61,6 +60,8 @@ struct BrowsingSettings: View {
|
||||
#if !os(tvOS)
|
||||
Toggle("Show account username", isOn: $accountPickerDisplaysUsername)
|
||||
#endif
|
||||
|
||||
Toggle("Show anonymous accounts", isOn: $accountPickerDisplaysAnonymousAccounts)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -225,11 +225,11 @@ struct SettingsView: View {
|
||||
private var windowHeight: Double {
|
||||
switch selection {
|
||||
case .browsing:
|
||||
return 390
|
||||
return 400
|
||||
case .player:
|
||||
return 420
|
||||
case .quality:
|
||||
return 400
|
||||
return 420
|
||||
case .history:
|
||||
return 480
|
||||
case .sponsorBlock:
|
||||
|
@@ -19,6 +19,7 @@ struct OpenSettingsButton: View {
|
||||
} label: {
|
||||
Label("Open Settings", systemImage: "gearshape.2")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
|
||||
button
|
||||
|
@@ -170,6 +170,8 @@ struct YatteeApp: App {
|
||||
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
|
||||
SDWebImageManager.defaultImageCache = PINCache(name: "stream.yattee.app")
|
||||
|
||||
migrateAccounts()
|
||||
|
||||
if !Defaults[.lastAccountIsPublic] {
|
||||
accounts.configureAccount()
|
||||
}
|
||||
@@ -246,4 +248,28 @@ struct YatteeApp: App {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func migrateAccounts() {
|
||||
Defaults[.accounts].forEach { account in
|
||||
if !account.username.isEmpty || !(account.password?.isEmpty ?? true) || !(account.name?.isEmpty ?? true) {
|
||||
print("Account needs migration: \(account.description)")
|
||||
if account.app == .invidious {
|
||||
if let name = account.name, !name.isEmpty {
|
||||
AccountsModel.setCredentials(account, username: name, password: "")
|
||||
}
|
||||
if !account.username.isEmpty {
|
||||
AccountsModel.setToken(account, account.username)
|
||||
}
|
||||
} else if account.app == .piped,
|
||||
!account.username.isEmpty,
|
||||
let password = account.password,
|
||||
!password.isEmpty
|
||||
{
|
||||
AccountsModel.setCredentials(account, username: account.username, password: password)
|
||||
}
|
||||
|
||||
AccountsModel.removeDefaultsCredentials(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user