2018-08-28 23:16:17 +00:00
|
|
|
//
|
|
|
|
// Preferences.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/28/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2022-04-02 23:28:10 +00:00
|
|
|
import UIKit
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2019-06-14 00:53:17 +00:00
|
|
|
import Combine
|
2018-08-28 23:16:17 +00:00
|
|
|
|
2019-08-06 03:08:00 +00:00
|
|
|
class Preferences: Codable, ObservableObject {
|
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-09-14 16:15:40 +00:00
|
|
|
required init(from decoder: Decoder) throws {
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
2019-12-31 05:12:18 +00:00
|
|
|
self.theme = try container.decode(UIUserInterfaceStyle.self, forKey: .theme)
|
2019-09-14 16:15:40 +00:00
|
|
|
self.avatarStyle = try container.decode(AvatarStyle.self, forKey: .avatarStyle)
|
|
|
|
self.hideCustomEmojiInUsernames = try container.decode(Bool.self, forKey: .hideCustomEmojiInUsernames)
|
2020-06-17 21:45:34 +00:00
|
|
|
self.showIsStatusReplyIcon = try container.decode(Bool.self, forKey: .showIsStatusReplyIcon)
|
2020-06-17 22:00:13 +00:00
|
|
|
self.alwaysShowStatusVisibilityIcon = try container.decode(Bool.self, forKey: .alwaysShowStatusVisibilityIcon)
|
2022-04-08 22:42:15 +00:00
|
|
|
self.hideActionsInTimeline = try container.decodeIfPresent(Bool.self, forKey: .hideActionsInTimeline) ?? false
|
2019-09-14 16:15:40 +00:00
|
|
|
|
|
|
|
self.defaultPostVisibility = try container.decode(Status.Visibility.self, forKey: .defaultPostVisibility)
|
2022-11-05 16:20:30 +00:00
|
|
|
self.defaultReplyVisibility = try container.decodeIfPresent(ReplyVisibility.self, forKey: .defaultReplyVisibility) ?? .sameAsPost
|
2019-09-14 16:15:40 +00:00
|
|
|
self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts)
|
2020-01-18 02:55:21 +00:00
|
|
|
self.requireAttachmentDescriptions = try container.decode(Bool.self, forKey: .requireAttachmentDescriptions)
|
2020-01-20 04:23:00 +00:00
|
|
|
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
|
2020-01-20 04:48:36 +00:00
|
|
|
self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger)
|
2022-11-22 16:06:21 +00:00
|
|
|
self.useTwitterKeyboard = try container.decodeIfPresent(Bool.self, forKey: .useTwitterKeyboard) ?? false
|
2020-06-17 21:38:00 +00:00
|
|
|
|
2019-11-17 17:52:42 +00:00
|
|
|
self.blurAllMedia = try container.decode(Bool.self, forKey: .blurAllMedia)
|
2022-11-05 17:20:55 +00:00
|
|
|
self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true
|
2020-02-22 18:12:28 +00:00
|
|
|
self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs)
|
2020-06-17 21:38:00 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps)
|
2019-11-15 00:53:27 +00:00
|
|
|
self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
|
|
|
|
self.inAppSafariAutomaticReaderMode = try container.decode(Bool.self, forKey: .inAppSafariAutomaticReaderMode)
|
2020-11-03 20:39:02 +00:00
|
|
|
self.expandAllContentWarnings = try container.decodeIfPresent(Bool.self, forKey: .expandAllContentWarnings) ?? false
|
|
|
|
self.collapseLongPosts = try container.decodeIfPresent(Bool.self, forKey: .collapseLongPosts) ?? true
|
|
|
|
self.oppositeCollapseKeywords = try container.decodeIfPresent([String].self, forKey: .oppositeCollapseKeywords) ?? []
|
2021-04-05 21:48:03 +00:00
|
|
|
self.confirmBeforeReblog = try container.decodeIfPresent(Bool.self, forKey: .confirmBeforeReblog) ?? false
|
2019-09-14 16:15:40 +00:00
|
|
|
|
2019-09-14 18:55:30 +00:00
|
|
|
self.showFavoriteAndReblogCounts = try container.decode(Bool.self, forKey: .showFavoriteAndReblogCounts)
|
2019-09-14 17:02:33 +00:00
|
|
|
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
|
2020-11-03 20:39:02 +00:00
|
|
|
self.grayscaleImages = try container.decodeIfPresent(Bool.self, forKey: .grayscaleImages) ?? false
|
2021-06-26 03:28:14 +00:00
|
|
|
self.disableInfiniteScrolling = try container.decodeIfPresent(Bool.self, forKey: .disableInfiniteScrolling) ?? false
|
2022-04-01 23:23:49 +00:00
|
|
|
self.hideDiscover = try container.decodeIfPresent(Bool.self, forKey: .hideDiscover) ?? false
|
2019-09-14 17:02:33 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
self.statusContentType = try container.decode(StatusContentType.self, forKey: .statusContentType)
|
2021-08-07 18:39:01 +00:00
|
|
|
|
|
|
|
self.hasShownLocalTimelineDescription = try container.decodeIfPresent(Bool.self, forKey: .hasShownLocalTimelineDescription) ?? false
|
|
|
|
self.hasShownFederatedTimelineDescription = try container.decodeIfPresent(Bool.self, forKey: .hasShownFederatedTimelineDescription) ?? false
|
2019-09-14 16:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func encode(to encoder: Encoder) throws {
|
|
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
2019-12-31 05:12:18 +00:00
|
|
|
try container.encode(theme, forKey: .theme)
|
2019-09-14 16:15:40 +00:00
|
|
|
try container.encode(avatarStyle, forKey: .avatarStyle)
|
|
|
|
try container.encode(hideCustomEmojiInUsernames, forKey: .hideCustomEmojiInUsernames)
|
2020-06-17 21:45:34 +00:00
|
|
|
try container.encode(showIsStatusReplyIcon, forKey: .showIsStatusReplyIcon)
|
2020-06-17 22:00:13 +00:00
|
|
|
try container.encode(alwaysShowStatusVisibilityIcon, forKey: .alwaysShowStatusVisibilityIcon)
|
2022-04-08 22:42:15 +00:00
|
|
|
try container.encode(hideActionsInTimeline, forKey: .hideActionsInTimeline)
|
2019-09-14 16:15:40 +00:00
|
|
|
|
|
|
|
try container.encode(defaultPostVisibility, forKey: .defaultPostVisibility)
|
2022-11-05 16:20:30 +00:00
|
|
|
try container.encode(defaultReplyVisibility, forKey: .defaultReplyVisibility)
|
2019-09-14 16:15:40 +00:00
|
|
|
try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts)
|
2020-01-18 02:55:21 +00:00
|
|
|
try container.encode(requireAttachmentDescriptions, forKey: .requireAttachmentDescriptions)
|
2020-01-20 04:23:00 +00:00
|
|
|
try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode)
|
2020-01-20 04:48:36 +00:00
|
|
|
try container.encode(mentionReblogger, forKey: .mentionReblogger)
|
2022-11-22 16:06:21 +00:00
|
|
|
try container.encode(useTwitterKeyboard, forKey: .useTwitterKeyboard)
|
2020-06-17 21:38:00 +00:00
|
|
|
|
2019-11-17 17:52:42 +00:00
|
|
|
try container.encode(blurAllMedia, forKey: .blurAllMedia)
|
2022-11-05 17:20:55 +00:00
|
|
|
try container.encode(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning)
|
2020-02-22 18:12:28 +00:00
|
|
|
try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs)
|
2020-06-17 21:38:00 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
try container.encode(openLinksInApps, forKey: .openLinksInApps)
|
2019-11-15 00:53:27 +00:00
|
|
|
try container.encode(useInAppSafari, forKey: .useInAppSafari)
|
|
|
|
try container.encode(inAppSafariAutomaticReaderMode, forKey: .inAppSafariAutomaticReaderMode)
|
2020-09-16 01:37:08 +00:00
|
|
|
try container.encode(expandAllContentWarnings, forKey: .expandAllContentWarnings)
|
|
|
|
try container.encode(collapseLongPosts, forKey: .collapseLongPosts)
|
2020-11-03 20:39:02 +00:00
|
|
|
try container.encode(oppositeCollapseKeywords, forKey: .oppositeCollapseKeywords)
|
2021-04-05 21:48:03 +00:00
|
|
|
try container.encode(confirmBeforeReblog, forKey: .confirmBeforeReblog)
|
2019-09-14 16:15:40 +00:00
|
|
|
|
2019-09-14 18:55:30 +00:00
|
|
|
try container.encode(showFavoriteAndReblogCounts, forKey: .showFavoriteAndReblogCounts)
|
2019-09-14 17:02:33 +00:00
|
|
|
try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType)
|
2020-11-01 18:59:58 +00:00
|
|
|
try container.encode(grayscaleImages, forKey: .grayscaleImages)
|
2021-06-26 03:28:14 +00:00
|
|
|
try container.encode(disableInfiniteScrolling, forKey: .disableInfiniteScrolling)
|
2022-04-01 23:23:49 +00:00
|
|
|
try container.encode(hideDiscover, forKey: .hideDiscover)
|
2019-09-14 17:02:33 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
try container.encode(statusContentType, forKey: .statusContentType)
|
2021-08-07 18:39:01 +00:00
|
|
|
|
|
|
|
try container.encode(hasShownLocalTimelineDescription, forKey: .hasShownLocalTimelineDescription)
|
|
|
|
try container.encode(hasShownFederatedTimelineDescription, forKey: .hasShownFederatedTimelineDescription)
|
2019-09-14 16:15:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 21:38:00 +00:00
|
|
|
// MARK: Appearance
|
2019-12-31 05:12:18 +00:00
|
|
|
@Published var theme = UIUserInterfaceStyle.unspecified
|
2019-09-14 16:15:40 +00:00
|
|
|
@Published var avatarStyle = AvatarStyle.roundRect
|
|
|
|
@Published var hideCustomEmojiInUsernames = false
|
2020-06-17 21:45:34 +00:00
|
|
|
@Published var showIsStatusReplyIcon = false
|
2020-06-17 22:00:13 +00:00
|
|
|
@Published var alwaysShowStatusVisibilityIcon = false
|
2022-04-08 22:42:15 +00:00
|
|
|
@Published var hideActionsInTimeline = false
|
2022-11-27 01:13:16 +00:00
|
|
|
@Published var leadingStatusSwipeActions: [StatusSwipeAction] = [.favorite, .reblog]
|
|
|
|
@Published var trailingStatusSwipeActions: [StatusSwipeAction] = [.reply, .share]
|
2018-08-29 01:18:58 +00:00
|
|
|
|
2020-06-17 21:38:00 +00:00
|
|
|
// MARK: Composing
|
2019-09-14 16:15:40 +00:00
|
|
|
@Published var defaultPostVisibility = Status.Visibility.public
|
2022-11-05 16:20:30 +00:00
|
|
|
@Published var defaultReplyVisibility = ReplyVisibility.sameAsPost
|
2019-09-14 16:15:40 +00:00
|
|
|
@Published var automaticallySaveDrafts = true
|
2020-01-18 02:55:21 +00:00
|
|
|
@Published var requireAttachmentDescriptions = false
|
2020-01-20 04:23:00 +00:00
|
|
|
@Published var contentWarningCopyMode = ContentWarningCopyMode.asIs
|
2020-01-20 04:48:36 +00:00
|
|
|
@Published var mentionReblogger = false
|
2022-11-22 16:06:21 +00:00
|
|
|
@Published var useTwitterKeyboard = false
|
2020-06-17 21:38:00 +00:00
|
|
|
|
|
|
|
// MARK: Media
|
2022-11-05 17:20:55 +00:00
|
|
|
@Published var blurAllMedia = false {
|
|
|
|
didSet {
|
|
|
|
if blurAllMedia {
|
|
|
|
blurMediaBehindContentWarning = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Published var blurMediaBehindContentWarning = true
|
2020-02-22 18:12:28 +00:00
|
|
|
@Published var automaticallyPlayGifs = true
|
2020-06-17 21:38:00 +00:00
|
|
|
|
|
|
|
// MARK: Behavior
|
2019-09-14 16:15:40 +00:00
|
|
|
@Published var openLinksInApps = true
|
2019-11-15 00:53:27 +00:00
|
|
|
@Published var useInAppSafari = true
|
|
|
|
@Published var inAppSafariAutomaticReaderMode = false
|
2020-09-16 01:37:08 +00:00
|
|
|
@Published var expandAllContentWarnings = false
|
|
|
|
@Published var collapseLongPosts = true
|
2020-11-03 20:39:02 +00:00
|
|
|
@Published var oppositeCollapseKeywords: [String] = []
|
2021-04-05 21:48:03 +00:00
|
|
|
@Published var confirmBeforeReblog = false
|
2018-10-23 02:09:11 +00:00
|
|
|
|
2020-06-17 21:38:00 +00:00
|
|
|
// MARK: Digital Wellness
|
2019-09-14 18:55:30 +00:00
|
|
|
@Published var showFavoriteAndReblogCounts = true
|
2019-09-14 17:02:33 +00:00
|
|
|
@Published var defaultNotificationsMode = NotificationsMode.allNotifications
|
2020-11-01 18:59:58 +00:00
|
|
|
@Published var grayscaleImages = false
|
2021-06-26 03:28:14 +00:00
|
|
|
@Published var disableInfiniteScrolling = false
|
2022-04-01 23:23:49 +00:00
|
|
|
@Published var hideDiscover = false
|
2019-09-14 17:02:33 +00:00
|
|
|
|
2020-06-17 21:38:00 +00:00
|
|
|
// MARK: Advanced
|
2019-09-14 16:15:40 +00:00
|
|
|
@Published var statusContentType: StatusContentType = .plain
|
2022-10-30 22:17:53 +00:00
|
|
|
@Published var reportErrorsAutomatically = true
|
2021-08-07 18:39:01 +00:00
|
|
|
|
|
|
|
// MARK:
|
|
|
|
@Published var hasShownLocalTimelineDescription = false
|
|
|
|
@Published var hasShownFederatedTimelineDescription = false
|
|
|
|
|
2020-11-01 18:59:58 +00:00
|
|
|
private enum CodingKeys: String, CodingKey {
|
2019-12-31 05:12:18 +00:00
|
|
|
case theme
|
2019-09-14 16:15:40 +00:00
|
|
|
case avatarStyle
|
|
|
|
case hideCustomEmojiInUsernames
|
2020-06-17 21:45:34 +00:00
|
|
|
case showIsStatusReplyIcon
|
2020-06-17 22:00:13 +00:00
|
|
|
case alwaysShowStatusVisibilityIcon
|
2022-04-08 22:42:15 +00:00
|
|
|
case hideActionsInTimeline
|
2019-06-14 00:53:17 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
case defaultPostVisibility
|
2022-11-05 16:20:30 +00:00
|
|
|
case defaultReplyVisibility
|
2019-09-14 16:15:40 +00:00
|
|
|
case automaticallySaveDrafts
|
2020-01-18 02:55:21 +00:00
|
|
|
case requireAttachmentDescriptions
|
2020-01-20 04:23:00 +00:00
|
|
|
case contentWarningCopyMode
|
2020-01-20 04:48:36 +00:00
|
|
|
case mentionReblogger
|
2022-11-22 16:06:21 +00:00
|
|
|
case useTwitterKeyboard
|
2020-06-17 21:38:00 +00:00
|
|
|
|
2019-11-17 17:52:42 +00:00
|
|
|
case blurAllMedia
|
2022-11-05 17:20:55 +00:00
|
|
|
case blurMediaBehindContentWarning
|
2020-02-22 18:12:28 +00:00
|
|
|
case automaticallyPlayGifs
|
2020-06-17 21:38:00 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
case openLinksInApps
|
2019-11-15 00:53:27 +00:00
|
|
|
case useInAppSafari
|
|
|
|
case inAppSafariAutomaticReaderMode
|
2020-09-16 01:37:08 +00:00
|
|
|
case expandAllContentWarnings
|
|
|
|
case collapseLongPosts
|
2020-11-03 20:39:02 +00:00
|
|
|
case oppositeCollapseKeywords
|
2021-04-05 21:48:03 +00:00
|
|
|
case confirmBeforeReblog
|
2019-09-14 16:15:40 +00:00
|
|
|
|
2019-09-14 18:55:30 +00:00
|
|
|
case showFavoriteAndReblogCounts
|
2019-09-14 17:02:33 +00:00
|
|
|
case defaultNotificationsType
|
2020-11-01 18:59:58 +00:00
|
|
|
case grayscaleImages
|
2021-06-26 03:28:14 +00:00
|
|
|
case disableInfiniteScrolling
|
2022-04-01 23:23:49 +00:00
|
|
|
case hideDiscover
|
2019-09-14 17:02:33 +00:00
|
|
|
|
2019-09-14 16:15:40 +00:00
|
|
|
case statusContentType
|
2021-08-07 18:39:01 +00:00
|
|
|
|
|
|
|
case hasShownLocalTimelineDescription
|
|
|
|
case hasShownFederatedTimelineDescription
|
2019-06-14 00:53:17 +00:00
|
|
|
}
|
2019-09-14 16:15:40 +00:00
|
|
|
|
2018-09-23 23:04:39 +00:00
|
|
|
}
|
|
|
|
|
2022-11-05 16:20:30 +00:00
|
|
|
extension Preferences {
|
|
|
|
enum ReplyVisibility: Codable, Hashable, CaseIterable {
|
|
|
|
case sameAsPost
|
|
|
|
case visibility(Status.Visibility)
|
|
|
|
|
|
|
|
static var allCases: [Preferences.ReplyVisibility] = [.sameAsPost] + Status.Visibility.allCases.map { .visibility($0) }
|
|
|
|
|
|
|
|
var resolved: Status.Visibility {
|
|
|
|
switch self {
|
|
|
|
case .sameAsPost:
|
|
|
|
return Preferences.shared.defaultPostVisibility
|
|
|
|
case .visibility(let vis):
|
|
|
|
return vis
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var displayName: String {
|
|
|
|
switch self {
|
|
|
|
case .sameAsPost:
|
|
|
|
return "Same as Default"
|
|
|
|
case .visibility(let vis):
|
|
|
|
return vis.displayName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var imageName: String? {
|
|
|
|
switch self {
|
|
|
|
case .sameAsPost:
|
|
|
|
return nil
|
|
|
|
case .visibility(let vis):
|
|
|
|
return vis.imageName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 05:12:18 +00:00
|
|
|
extension UIUserInterfaceStyle: Codable {}
|