2018-08-28 23:16:17 +00:00
|
|
|
//
|
|
|
|
// Preferences.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/28/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2019-06-14 00:53:17 +00:00
|
|
|
import SwiftUI
|
|
|
|
import Combine
|
2018-08-28 23:16:17 +00:00
|
|
|
|
2019-06-14 00:53:17 +00:00
|
|
|
class Preferences: Codable, BindableObject {
|
2019-07-18 22:44:35 +00:00
|
|
|
|
2019-06-14 00:53:17 +00:00
|
|
|
static var shared: Preferences = load()
|
2018-08-28 23:16:17 +00:00
|
|
|
|
|
|
|
private static var documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
|
|
|
private static var archiveURL = Preferences.documentsDirectory.appendingPathComponent("preferences").appendingPathExtension("plist")
|
|
|
|
|
|
|
|
static func save() {
|
|
|
|
let encoder = PropertyListEncoder()
|
|
|
|
let data = try? encoder.encode(shared)
|
2018-10-23 02:09:11 +00:00
|
|
|
try? data?.write(to: archiveURL, options: .noFileProtection)
|
2018-08-28 23:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static func load() -> Preferences {
|
|
|
|
let decoder = PropertyListDecoder()
|
2018-10-23 02:09:11 +00:00
|
|
|
if let data = try? Data(contentsOf: archiveURL),
|
2018-08-28 23:16:17 +00:00
|
|
|
let preferences = try? decoder.decode(Preferences.self, from: data) {
|
|
|
|
return preferences
|
|
|
|
}
|
|
|
|
return Preferences()
|
|
|
|
}
|
|
|
|
|
2018-10-06 14:38:36 +00:00
|
|
|
private init() {}
|
2018-08-28 23:16:17 +00:00
|
|
|
|
2019-07-18 22:44:35 +00:00
|
|
|
typealias PublisherType = PassthroughSubject<Preferences, Never>
|
|
|
|
let willChange = PassthroughSubject<Preferences, Never>()
|
2019-06-14 00:53:17 +00:00
|
|
|
|
2018-10-06 14:38:36 +00:00
|
|
|
// MARK: - Appearance
|
2019-07-18 22:44:35 +00:00
|
|
|
var showRepliesInProfiles = false { willSet { willChange.send(self) } }
|
|
|
|
var avatarStyle = AvatarStyle.roundRect { willSet { willChange.send(self) } }
|
|
|
|
var hideCustomEmojiInUsernames = false { willSet { willChange.send(self) } }
|
2018-08-29 01:18:58 +00:00
|
|
|
|
2019-02-22 15:20:22 +00:00
|
|
|
// MARK: - Behavior
|
2019-07-18 22:44:35 +00:00
|
|
|
var defaultPostVisibility = Status.Visibility.public { willSet { willChange.send(self) } }
|
|
|
|
var automaticallySaveDrafts = true { willSet { willChange.send(self) } }
|
|
|
|
var openLinksInApps = true { willSet { willChange.send(self) } }
|
2018-10-23 02:09:11 +00:00
|
|
|
|
2018-10-06 14:38:36 +00:00
|
|
|
// MARK: - Advanced
|
2019-07-18 22:44:35 +00:00
|
|
|
var silentActions: [String: Permission] = [:] { willSet { willChange.send(self) } }
|
|
|
|
var statusContentType: StatusContentType = .plain { willSet { willChange.send(self) } }
|
2019-06-14 00:53:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PassthroughSubject: Codable {
|
|
|
|
public convenience init(from decoder: Decoder) throws {
|
|
|
|
self.init()
|
|
|
|
}
|
2018-09-23 23:04:39 +00:00
|
|
|
|
2019-06-14 00:53:17 +00:00
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
|
|
|
|
|
|
}
|
2018-09-23 23:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Preferences {
|
|
|
|
enum Permission: String, Codable {
|
|
|
|
case undecided, accepted, rejected
|
|
|
|
}
|
2018-08-28 23:16:17 +00:00
|
|
|
}
|