2020-07-04 16:03:35 +02:00
|
|
|
//
|
|
|
|
// SettingsModel.swift
|
|
|
|
// Multiplatform iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 7/4/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2020-07-09 12:44:53 +02:00
|
|
|
import Account
|
2020-07-04 16:03:35 +02:00
|
|
|
|
|
|
|
class SettingsModel: ObservableObject {
|
|
|
|
|
|
|
|
enum HelpSites {
|
2020-08-13 02:24:54 +02:00
|
|
|
case netNewsWireHelp, netNewsWire, supportNetNewsWire, github, bugTracker, technotes, netNewsWireSlack, releaseNotes, none
|
2020-07-04 16:03:35 +02:00
|
|
|
|
|
|
|
var url: URL? {
|
|
|
|
switch self {
|
|
|
|
case .netNewsWireHelp:
|
|
|
|
return URL(string: "https://ranchero.com/netnewswire/help/ios/5.0/en/")!
|
|
|
|
case .netNewsWire:
|
|
|
|
return URL(string: "https://ranchero.com/netnewswire/")!
|
|
|
|
case .supportNetNewsWire:
|
2020-07-26 11:47:02 +02:00
|
|
|
return URL(string: "https://github.com/brentsimmons/NetNewsWire/blob/main/Technotes/HowToSupportNetNewsWire.markdown")!
|
2020-07-04 16:03:35 +02:00
|
|
|
case .github:
|
|
|
|
return URL(string: "https://github.com/brentsimmons/NetNewsWire")!
|
|
|
|
case .bugTracker:
|
|
|
|
return URL(string: "https://github.com/brentsimmons/NetNewsWire/issues")!
|
|
|
|
case .technotes:
|
2020-07-26 11:47:02 +02:00
|
|
|
return URL(string: "https://github.com/brentsimmons/NetNewsWire/tree/main/Technotes")!
|
2020-07-04 16:03:35 +02:00
|
|
|
case .netNewsWireSlack:
|
|
|
|
return URL(string: "https://ranchero.com/netnewswire/slack")!
|
2020-08-13 02:24:54 +02:00
|
|
|
case .releaseNotes:
|
2020-08-15 09:01:00 +02:00
|
|
|
return URL.releaseNotes
|
2020-07-04 16:03:35 +02:00
|
|
|
case .none:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Published var presentSheet: Bool = false
|
2020-07-09 12:44:53 +02:00
|
|
|
var accounts: [Account] {
|
|
|
|
get {
|
|
|
|
AccountManager.shared.sortedAccounts
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 17:20:43 +02:00
|
|
|
var activeAccounts: [Account] {
|
|
|
|
get {
|
|
|
|
AccountManager.shared.sortedActiveAccounts
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 12:44:53 +02:00
|
|
|
// MARK: Init
|
|
|
|
|
|
|
|
init() {
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange), name: .DisplayNameDidChange, object: nil)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddAccount), name: .UserDidAddAccount, object: nil)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(userDidDeleteAccount), name: .UserDidDeleteAccount, object: nil)
|
|
|
|
}
|
|
|
|
|
2020-07-04 16:03:35 +02:00
|
|
|
var selectedWebsite: HelpSites = .none {
|
|
|
|
didSet {
|
|
|
|
if selectedWebsite == .none {
|
|
|
|
presentSheet = false
|
|
|
|
} else {
|
|
|
|
presentSheet = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-09 12:44:53 +02:00
|
|
|
|
|
|
|
func refreshAccounts() {
|
|
|
|
objectWillChange.self.send()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK:- Notifications
|
|
|
|
|
|
|
|
@objc func displayNameDidChange() {
|
|
|
|
refreshAccounts()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func userDidAddAccount() {
|
|
|
|
refreshAccounts()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func userDidDeleteAccount() {
|
|
|
|
refreshAccounts()
|
|
|
|
}
|
2020-07-04 16:03:35 +02:00
|
|
|
}
|