mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 08:17:16 +00:00
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>
96 lines
3.5 KiB
Swift
96 lines
3.5 KiB
Swift
//
|
|
// UIViewController-Extensions.swift
|
|
// NetNewsWire-iOS
|
|
//
|
|
// Created by Maurice Parker on 1/16/20.
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SwiftUI
|
|
import RSCore
|
|
import Account
|
|
|
|
extension UIViewController {
|
|
|
|
/// Size of form sheets on iPad.
|
|
static let formSheetSize = CGSize(width: 460, height: 400)
|
|
|
|
/// The sheet for updating an account's credentials, or nil if its type has none.
|
|
static func credentialsViewController(for account: Account) -> UIViewController? {
|
|
if account.type == .miniflux {
|
|
return UIHostingController(rootView: MinifluxAccountView(account: account, didAddAccount: nil))
|
|
}
|
|
guard CredentialsAccountView.accountTypes.contains(account.type) else {
|
|
return nil
|
|
}
|
|
return UIHostingController(rootView: CredentialsAccountView(accountType: account.type, account: account, didAddAccount: nil))
|
|
}
|
|
|
|
func presentError(_ error: Error, dismiss: (() -> Void)? = nil) {
|
|
if let accountError = error as? AccountError, accountError.isCredentialsError {
|
|
presentAccountError(accountError, dismiss: dismiss)
|
|
} else if let recoverableError = error as? (RecoverableError & LocalizedError), !recoverableError.recoveryOptions.isEmpty {
|
|
presentErrorWithRecovery(error: recoverableError, dismiss: dismiss)
|
|
} else {
|
|
let errorTitle = NSLocalizedString("Error", comment: "Error")
|
|
presentError(title: errorTitle, message: error.localizedDescription, dismiss: dismiss)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private extension UIViewController {
|
|
|
|
func presentAccountError(_ error: AccountError, dismiss: (() -> Void)? = nil) {
|
|
let title = NSLocalizedString("Account Error", comment: "Account Error")
|
|
let alertController = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert)
|
|
|
|
if let account = AccountError.account(from: error), let hostingController = UIViewController.credentialsViewController(for: account) {
|
|
let credentialsTitle = NSLocalizedString("Update Credentials", comment: "Update Credentials")
|
|
let credentialsAction = UIAlertAction(title: credentialsTitle, style: .default) { [weak self] _ in
|
|
dismiss?()
|
|
|
|
hostingController.modalPresentationStyle = .formSheet
|
|
hostingController.preferredContentSize = UIViewController.formSheetSize
|
|
self?.present(hostingController, animated: true)
|
|
}
|
|
|
|
alertController.addAction(credentialsAction)
|
|
alertController.preferredAction = credentialsAction
|
|
}
|
|
|
|
let dismissTitle = NSLocalizedString("OK", comment: "OK button")
|
|
let dismissAction = UIAlertAction(title: dismissTitle, style: .default) { _ in
|
|
dismiss?()
|
|
}
|
|
alertController.addAction(dismissAction)
|
|
|
|
self.present(alertController, animated: true, completion: nil)
|
|
}
|
|
|
|
func presentErrorWithRecovery(error: RecoverableError & LocalizedError, dismiss: (() -> Void)? = nil) {
|
|
let title = error.errorDescription ?? NSLocalizedString("Error", comment: "Error")
|
|
let message = [error.failureReason, error.recoverySuggestion].compactMap { $0 }.joined(separator: " ")
|
|
|
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
|
|
// Add recovery options as buttons
|
|
for (index, option) in error.recoveryOptions.enumerated() {
|
|
let action = UIAlertAction(title: option, style: index == 0 ? .default : .cancel) { _ in
|
|
dismiss?()
|
|
_ = error.attemptRecovery(optionIndex: index)
|
|
}
|
|
alertController.addAction(action)
|
|
|
|
// Make the first option the preferred action
|
|
if index == 0 {
|
|
alertController.preferredAction = action
|
|
}
|
|
}
|
|
|
|
self.present(alertController, animated: true, completion: nil)
|
|
}
|
|
|
|
}
|