Files
NetNewsWire/Mac/Preferences/Accounts/AddAccountsView.swift
T
Dave MarquardandIngmar Stein ba63d58712 Add native Miniflux account type and sync support
Adds Miniflux as a first-class account type alongside Feedbin, Feedly,
NewsBlur, and Reader API accounts, on both macOS and iOS.

Refreshes are incremental: the changed_after parameter means read and
starred status ride along with the entries in a single pass instead of
needing separate status scans. Articles missing locally are backfilled by
ID via GET /v1/entries/{id}; a 404 means the entry is gone server-side, so
its statuses are deleted and it is not requested again on every refresh.
Starred changes go out as idempotent batch updates.

Requires Miniflux 2.0.49 or newer. The server version is detected at
runtime via GET /v1/version and persisted in AccountSettings. Servers
older than 2.3.2 have no /v1/entries/ids and no batch starred updates, so
those paths fall back transparently to paged /v1/entries and per-entry
bookmark toggles.

Both HTTP Basic and API-token authentication are supported, selectable in
the account sheet on either platform. Entered URLs are normalized (scheme
added, trailing slash and /v1 suffix stripped), and adding a second
account for a server that already has one is rejected.

Tests cover folder sync, model decoding, version parsing, the pre-2.3.2
fallback paths, and duplicate-endpoint detection, with JSON fixtures for
the API responses.

The runtime version detection and the duplicate-endpoint check were
informed by IngmarStein's independent Miniflux implementation in #5335.

Written with help from Claude Code.

Co-Authored-By: Ingmar Stein <490610+IngmarStein@users.noreply.github.com>
2026-11-22 07:06:11 -08:00

268 lines
6.8 KiB
Swift

//
// AddAccountsView.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 28/10/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
import RSCore
enum AddAccountSections: Int, CaseIterable {
case local = 0
case icloud
case web
case selfhosted
case allOrdered
var sectionHeader: String {
switch self {
case .local:
return NSLocalizedString("Local", comment: "Local Account")
case .icloud:
return NSLocalizedString("iCloud", comment: "iCloud Account")
case .web:
return NSLocalizedString("Web", comment: "Web Account")
case .selfhosted:
return NSLocalizedString("Self-hosted", comment: "Self hosted Account")
case .allOrdered:
return ""
}
}
var sectionFooter: String {
switch self {
case .local:
return NSLocalizedString("Local accounts do not sync feeds across devices", comment: "Local Account")
case .icloud:
return NSLocalizedString("Your iCloud account syncs your feeds across your Mac and iOS devices", comment: "iCloud Account")
case .web:
return NSLocalizedString("Web accounts sync your feeds across all your devices", comment: "Web Account")
case .selfhosted:
return NSLocalizedString("Self-hosted accounts sync your feeds across all your devices", comment: "Self hosted Account")
case .allOrdered:
return ""
}
}
var sectionContent: [AccountType] {
switch self {
case .local:
return [.onMyMac]
case .icloud:
return [.cloudKit]
case .web:
if AppDefaults.isDeveloperBuild {
return [.bazQux, .feedbin, .feedly, .inoreader, .newsBlur, .theOldReader].filter({ $0.isDeveloperRestricted == false })
} else {
return [.bazQux, .feedbin, .feedly, .inoreader, .newsBlur, .theOldReader]
}
case .selfhosted:
return [.freshRSS, .miniflux]
case .allOrdered:
return AddAccountSections.local.sectionContent +
AddAccountSections.icloud.sectionContent +
AddAccountSections.web.sectionContent +
AddAccountSections.selfhosted.sectionContent
}
}
}
struct AddAccountsView: View {
weak var parent: NSHostingController<AddAccountsView>? // required because presentationMode.dismiss() doesn't work
var addAccountDelegate: AccountsPreferencesAddAccountDelegate?
private let chunkLimit = 4 // use this to control number of accounts in each web account column
@State private var selectedAccount: AccountType = .onMyMac
init(delegate: AccountsPreferencesAddAccountDelegate?) {
self.addAccountDelegate = delegate
}
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Choose an account type to add…")
.font(.headline)
.padding()
localAccount
if !AppDefaults.isDeveloperBuild {
icloudAccount
}
webAccounts
selfhostedAccounts
HStack(spacing: 12) {
Spacer()
Button(action: {
parent?.dismiss(nil)
}, label: {
Text("Cancel", comment: "Cancel button")
.frame(width: 76)
})
.help(Text("Cancel", comment: "Cancel button"))
.keyboardShortcut(.cancelAction)
Button(action: {
addAccountDelegate?.presentSheetForAccount(selectedAccount)
parent?.dismiss(nil)
}, label: {
Text("Continue")
.frame(width: 76)
})
.help("Add Account")
.keyboardShortcut(.defaultAction)
}
.padding(.top, 12)
.padding(.bottom, 4)
}
.pickerStyle(RadioGroupPickerStyle())
.fixedSize(horizontal: false, vertical: true)
.frame(width: 420)
.padding()
}
var localAccount: some View {
VStack(alignment: .leading) {
Text("Local")
.font(.headline)
.padding(.horizontal)
Picker(selection: $selectedAccount, label: Text(""), content: {
ForEach(AddAccountSections.local.sectionContent, id: \.self, content: { account in
HStack(alignment: .center) {
account.image()
.resizable()
.scaledToFit()
.frame(width: 20, height: 20, alignment: .center)
.padding(.leading, 4)
Text(account.displayName)
}
.tag(account)
})
})
.pickerStyle(RadioGroupPickerStyle())
.offset(x: 7.5, y: 0)
Text(AddAccountSections.local.sectionFooter).foregroundColor(.gray)
.padding(.horizontal)
.lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
}
}
var icloudAccount: some View {
VStack(alignment: .leading) {
Text("iCloud")
.font(.headline)
.padding(.horizontal)
.padding(.top, 8)
Picker(selection: $selectedAccount, label: Text(""), content: {
ForEach(AddAccountSections.icloud.sectionContent, id: \.self, content: { account in
HStack(alignment: .center) {
account.image()
.resizable()
.scaledToFit()
.frame(width: 20, height: 20, alignment: .center)
.padding(.leading, 4)
Text(account.displayName)
}
.tag(account)
})
})
.offset(x: 7.5, y: 0)
.disabled(AccountManager.shared.hasiCloudAccount)
Text(AddAccountSections.icloud.sectionFooter).foregroundColor(.gray)
.padding(.horizontal)
.lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
}
}
@ViewBuilder
var webAccounts: some View {
VStack(alignment: .leading) {
Text("Web")
.font(.headline)
.padding(.horizontal)
.padding(.top, 8)
HStack {
ForEach(0..<chunkedWebAccounts().count, id: \.self, content: { chunk in
VStack {
Picker(selection: $selectedAccount, label: Text(""), content: {
ForEach(chunkedWebAccounts()[chunk], id: \.self, content: { account in
HStack(alignment: .center) {
account.image()
.resizable()
.scaledToFit()
.frame(width: 20, height: 20, alignment: .center)
.padding(.leading, 4)
Text(account.displayName)
}
.tag(account)
})
})
Spacer()
}
})
}
.offset(x: 7.5, y: 0)
Text(AddAccountSections.web.sectionFooter).foregroundColor(.gray)
.padding(.horizontal)
.lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
}
}
var selfhostedAccounts: some View {
VStack(alignment: .leading) {
Text("Self-hosted")
.font(.headline)
.padding(.horizontal)
.padding(.top, 8)
Picker(selection: $selectedAccount, label: Text(""), content: {
ForEach(AddAccountSections.selfhosted.sectionContent, id: \.self, content: { account in
HStack(alignment: .center) {
account.image()
.resizable()
.scaledToFit()
.frame(width: 20, height: 20, alignment: .center)
.padding(.leading, 4)
Text(account.displayName)
}.tag(account)
})
})
.offset(x: 7.5, y: 0)
Text(AddAccountSections.selfhosted.sectionFooter).foregroundColor(.gray)
.padding(.horizontal)
.lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
}
}
private func chunkedWebAccounts() -> [[AccountType]] {
AddAccountSections.web.sectionContent.chunked(into: chunkLimit)
}
}
struct AddAccountsView_Previews: PreviewProvider {
static var previews: some View {
AddAccountsView(delegate: nil)
}
}