Compare commits
No commits in common. "c85836eda6b8c02a7b5e92c3782f9e62e1bcb8f0" and "b4d41ac9b749ff810d23e52f74ec1dba05ed9c33" have entirely different histories.
c85836eda6
...
b4d41ac9b7
|
@ -9,6 +9,7 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
0411610022B442870030A9B7 /* AttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041160FE22B442870030A9B7 /* AttachmentViewController.swift */; };
|
||||
0411610122B442870030A9B7 /* AttachmentViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 041160FF22B442870030A9B7 /* AttachmentViewController.xib */; };
|
||||
0427033622B30B3D000D31B6 /* Preference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033522B30B3D000D31B6 /* Preference.swift */; };
|
||||
0427033822B30F5F000D31B6 /* BehaviorPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */; };
|
||||
0427033A22B31269000D31B6 /* AdvancedPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033922B31269000D31B6 /* AdvancedPrefsView.swift */; };
|
||||
0427037C22B316B9000D31B6 /* SilentActionPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */; };
|
||||
|
@ -268,6 +269,7 @@
|
|||
/* Begin PBXFileReference section */
|
||||
041160FE22B442870030A9B7 /* AttachmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentViewController.swift; sourceTree = "<group>"; };
|
||||
041160FF22B442870030A9B7 /* AttachmentViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AttachmentViewController.xib; sourceTree = "<group>"; };
|
||||
0427033522B30B3D000D31B6 /* Preference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preference.swift; sourceTree = "<group>"; };
|
||||
0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorPrefsView.swift; sourceTree = "<group>"; };
|
||||
0427033922B31269000D31B6 /* AdvancedPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedPrefsView.swift; sourceTree = "<group>"; };
|
||||
0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPrefs.swift; sourceTree = "<group>"; };
|
||||
|
@ -874,6 +876,7 @@
|
|||
children = (
|
||||
D663626121360B1900C9CBA2 /* Preferences.swift */,
|
||||
D663626321360D2300C9CBA2 /* AvatarStyle.swift */,
|
||||
0427033522B30B3D000D31B6 /* Preference.swift */,
|
||||
D6DD353C22F28CD000A9563A /* ContentWarningCopyMode.swift */,
|
||||
D6DD353E22F502EC00A9563A /* Preferences+Notification.swift */,
|
||||
D6BC9DB4232D4CE3002CA326 /* NotificationsMode.swift */,
|
||||
|
@ -1603,6 +1606,7 @@
|
|||
D6C693EF216192C2007D6A6D /* TuskerNavigationDelegate.swift in Sources */,
|
||||
D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */,
|
||||
D6434EB3215B1856001A919A /* XCBRequest.swift in Sources */,
|
||||
0427033622B30B3D000D31B6 /* Preference.swift in Sources */,
|
||||
D663626221360B1900C9CBA2 /* Preferences.swift in Sources */,
|
||||
D6333B792139AEFD00CE884A /* Date+TimeAgo.swift in Sources */,
|
||||
D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */,
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
// Preference.swift
|
||||
// Tusker
|
||||
//
|
||||
// Created by Shadowfacts on 6/13/19.
|
||||
// Copyright © 2019 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@propertyWrapper
|
||||
struct Preference<Value> {
|
||||
let path: WritableKeyPath<Preferences, Value>
|
||||
let binding: Binding<Value>
|
||||
|
||||
init(_ path: WritableKeyPath<Preferences, Value>) {
|
||||
self.path = path
|
||||
self.binding = Binding(get: {
|
||||
return Preferences.shared[keyPath: path]
|
||||
}, set: { (newValue) in
|
||||
Preferences.shared[keyPath: path] = newValue
|
||||
})
|
||||
}
|
||||
|
||||
var wrappedValue: Value {
|
||||
get {
|
||||
return Preferences.shared[keyPath: path]
|
||||
}
|
||||
set {
|
||||
Preferences.shared[keyPath: path] = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
struct MappedPreference<Value, PrefValue> {
|
||||
let path: WritableKeyPath<Preferences, PrefValue>
|
||||
let fromPref: (PrefValue) -> Value
|
||||
let toPref: (Value) -> PrefValue
|
||||
let binding: Binding<Value>
|
||||
|
||||
init(_ path: WritableKeyPath<Preferences, PrefValue>, fromPref: @escaping (PrefValue) -> Value, toPref: @escaping (Value) -> PrefValue) {
|
||||
self.path = path
|
||||
self.fromPref = fromPref
|
||||
self.toPref = toPref
|
||||
self.binding = Binding(get: {
|
||||
return fromPref(Preferences.shared[keyPath: path])
|
||||
}, set: { (newValue) in
|
||||
Preferences.shared[keyPath: path] = toPref(newValue)
|
||||
})
|
||||
}
|
||||
|
||||
var wrappedValue: Value {
|
||||
get {
|
||||
return fromPref(Preferences.shared[keyPath: path])
|
||||
}
|
||||
set {
|
||||
Preferences.shared[keyPath: path] = toPref(newValue)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,8 +46,6 @@ class Preferences: Codable, ObservableObject {
|
|||
self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts)
|
||||
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
|
||||
self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps)
|
||||
self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
|
||||
self.inAppSafariAutomaticReaderMode = try container.decode(Bool.self, forKey: .inAppSafariAutomaticReaderMode)
|
||||
|
||||
self.showFavoriteAndReblogCounts = try container.decode(Bool.self, forKey: .showFavoriteAndReblogCounts)
|
||||
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
|
||||
|
@ -67,8 +65,6 @@ class Preferences: Codable, ObservableObject {
|
|||
try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts)
|
||||
try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode)
|
||||
try container.encode(openLinksInApps, forKey: .openLinksInApps)
|
||||
try container.encode(useInAppSafari, forKey: .useInAppSafari)
|
||||
try container.encode(inAppSafariAutomaticReaderMode, forKey: .inAppSafariAutomaticReaderMode)
|
||||
|
||||
try container.encode(showFavoriteAndReblogCounts, forKey: .showFavoriteAndReblogCounts)
|
||||
try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType)
|
||||
|
@ -77,6 +73,9 @@ class Preferences: Codable, ObservableObject {
|
|||
try container.encode(statusContentType, forKey: .statusContentType)
|
||||
}
|
||||
|
||||
typealias ObjectWillChangePublisher = PassthroughSubject<Preferences, Never>
|
||||
let objectWillChange = PassthroughSubject<Preferences, Never>()
|
||||
|
||||
// MARK: - Appearance
|
||||
@Published var showRepliesInProfiles = false
|
||||
@Published var avatarStyle = AvatarStyle.roundRect
|
||||
|
@ -87,8 +86,6 @@ class Preferences: Codable, ObservableObject {
|
|||
@Published var automaticallySaveDrafts = true
|
||||
@Published var contentWarningCopyMode = ContentWarningCopyMode.asIs
|
||||
@Published var openLinksInApps = true
|
||||
@Published var useInAppSafari = true
|
||||
@Published var inAppSafariAutomaticReaderMode = false
|
||||
|
||||
// MARK: - Digital Wellness
|
||||
@Published var showFavoriteAndReblogCounts = true
|
||||
|
@ -107,8 +104,6 @@ class Preferences: Codable, ObservableObject {
|
|||
case automaticallySaveDrafts
|
||||
case contentWarningCopyMode
|
||||
case openLinksInApps
|
||||
case useInAppSafari
|
||||
case inAppSafariAutomaticReaderMode
|
||||
|
||||
case showFavoriteAndReblogCounts
|
||||
case defaultNotificationsType
|
||||
|
|
|
@ -9,8 +9,8 @@ import SwiftUI
|
|||
import Pachyderm
|
||||
|
||||
struct AdvancedPrefsView : View {
|
||||
@ObservedObject var preferences = Preferences.shared
|
||||
|
||||
@Preference(\.statusContentType) var statusContentType: StatusContentType
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
formattingSection
|
||||
|
@ -25,7 +25,7 @@ struct AdvancedPrefsView : View {
|
|||
|
||||
var formattingSection: some View {
|
||||
Section(footer: formattingFooter) {
|
||||
Picker(selection: $preferences.statusContentType, label: Text("Post Content Type")) {
|
||||
Picker(selection: _statusContentType.binding, label: Text("Post Content Type")) {
|
||||
ForEach(StatusContentType.allCases, id: \.self) { type in
|
||||
Text(type.displayName).tag(type)
|
||||
}//.navigationBarTitle("Post Content Type")
|
||||
|
|
|
@ -8,23 +8,21 @@
|
|||
import SwiftUI
|
||||
|
||||
struct AppearancePrefsView : View {
|
||||
@ObservedObject var preferences = Preferences.shared
|
||||
|
||||
var useCircularAvatars: Binding<Bool> = Binding(get: {
|
||||
Preferences.shared.avatarStyle == .circle
|
||||
}) {
|
||||
Preferences.shared.avatarStyle = $0 ? .circle : .roundRect
|
||||
}
|
||||
|
||||
@Preference(\.showRepliesInProfiles) var showRepliesInProfiles: Bool
|
||||
@Preference(\.hideCustomEmojiInUsernames) var hideCustomEmojiInUsernames: Bool
|
||||
|
||||
@MappedPreference(\.avatarStyle, fromPref: { $0 == .circle }, toPref: { $0 ? .circle : .roundRect })
|
||||
var useCircularAvatars: Bool
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Toggle(isOn: $preferences.showRepliesInProfiles) {
|
||||
Toggle(isOn: _showRepliesInProfiles.binding) {
|
||||
Text("Show Replies in Profiles")
|
||||
}
|
||||
Toggle(isOn: useCircularAvatars) {
|
||||
Toggle(isOn: _useCircularAvatars.binding) {
|
||||
Text("Use Circular Avatars")
|
||||
}
|
||||
Toggle(isOn: $preferences.hideCustomEmojiInUsernames) {
|
||||
Toggle(isOn: _hideCustomEmojiInUsernames.binding) {
|
||||
Text("Hide Custom Emoji in Usernames")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,12 @@
|
|||
import SwiftUI
|
||||
import Pachyderm
|
||||
|
||||
struct BehaviorPrefsView: View {
|
||||
@ObservedObject var preferences = Preferences.shared
|
||||
|
||||
struct BehaviorPrefsView : View {
|
||||
@Preference(\.defaultPostVisibility) var defaultPostVisibility: Status.Visibility
|
||||
@Preference(\.automaticallySaveDrafts) var automaticallySaveDrafts: Bool
|
||||
@Preference(\.contentWarningCopyMode) var contentWarningCopyMode: ContentWarningCopyMode
|
||||
@Preference(\.openLinksInApps) var openLinksInApps: Bool
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
section1
|
||||
|
@ -21,7 +24,7 @@ struct BehaviorPrefsView: View {
|
|||
|
||||
var section1: some View {
|
||||
Section(header: Text("COMPOSING")) {
|
||||
Picker(selection: $preferences.defaultPostVisibility, label: Text("Default Post Visibility")) {
|
||||
Picker(selection: _defaultPostVisibility.binding, label: Text("Default Post Visibility")) {
|
||||
ForEach(Status.Visibility.allCases, id: \.self) { visibility in
|
||||
HStack {
|
||||
Image(systemName: visibility.imageName)
|
||||
|
@ -31,10 +34,10 @@ struct BehaviorPrefsView: View {
|
|||
}//.navigationBarTitle("Default Post Visibility")
|
||||
// navbar title on the ForEach is currently incorrectly applied when the picker is not expanded, see FB6838291
|
||||
}
|
||||
Toggle(isOn: $preferences.automaticallySaveDrafts) {
|
||||
Toggle(isOn: _automaticallySaveDrafts.binding) {
|
||||
Text("Automatically Save Drafts")
|
||||
}
|
||||
Picker(selection: $preferences.contentWarningCopyMode, label: Text("Content Warning Copy Style")) {
|
||||
Picker(selection: _contentWarningCopyMode.binding, label: Text("Content Warning Copy Style")) {
|
||||
Text("As-is").tag(ContentWarningCopyMode.asIs)
|
||||
Text("Prepend 're: '").tag(ContentWarningCopyMode.prependRe)
|
||||
Text("Don't copy").tag(ContentWarningCopyMode.doNotCopy)
|
||||
|
@ -44,15 +47,9 @@ struct BehaviorPrefsView: View {
|
|||
|
||||
var section2: some View {
|
||||
Section(header: Text("READING")) {
|
||||
Toggle(isOn: $preferences.openLinksInApps) {
|
||||
Toggle(isOn: _openLinksInApps.binding) {
|
||||
Text("Open Links in Apps")
|
||||
}
|
||||
Toggle(isOn: $preferences.useInAppSafari) {
|
||||
Text("Use In-App Safari")
|
||||
}
|
||||
Toggle(isOn: $preferences.inAppSafariAutomaticReaderMode) {
|
||||
Text("Always Use Reader Mode in In-App Safari")
|
||||
}.disabled(!preferences.useInAppSafari)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
import SwiftUI
|
||||
|
||||
struct WellnessPrefsView: View {
|
||||
@ObservedObject var preferences = Preferences.shared
|
||||
|
||||
@Preference(\.showFavoriteAndReblogCounts) var showFavoriteAndReblogCounts: Bool
|
||||
@Preference(\.defaultNotificationsMode) var defaultNotificationsMode: NotificationsMode
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
showFavAndReblogCountSection
|
||||
|
@ -21,7 +22,7 @@ struct WellnessPrefsView: View {
|
|||
|
||||
var showFavAndReblogCountSection: some View {
|
||||
Section(footer: showFavAndReblogCountFooter) {
|
||||
Toggle(isOn: $preferences.showFavoriteAndReblogCounts) {
|
||||
Toggle(isOn: _showFavoriteAndReblogCounts.binding) {
|
||||
Text("Show Favorite and Reblog Counts")
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +34,7 @@ struct WellnessPrefsView: View {
|
|||
|
||||
var notificationsModeSection: some View {
|
||||
Section(footer: notificationsModeFooter) {
|
||||
Picker(selection: $preferences.defaultNotificationsMode, label: Text("Default Notifications Mode")) {
|
||||
Picker(selection: _defaultNotificationsMode.binding, label: Text("Default Notifications Mode")) {
|
||||
ForEach(NotificationsMode.allCases, id: \.self) { type in
|
||||
Text(type.displayName).tag(type)
|
||||
}
|
||||
|
|
|
@ -74,24 +74,14 @@ extension TuskerNavigationDelegate where Self: UIViewController {
|
|||
}
|
||||
|
||||
func selected(url: URL) {
|
||||
func openSafari() {
|
||||
if Preferences.shared.useInAppSafari {
|
||||
let config = SFSafariViewController.Configuration()
|
||||
config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode
|
||||
present(SFSafariViewController(url: url, configuration: config), animated: true)
|
||||
} else {
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
}
|
||||
}
|
||||
|
||||
if (Preferences.shared.openLinksInApps) {
|
||||
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in
|
||||
if (!success) {
|
||||
openSafari()
|
||||
self.present(SFSafariViewController(url: url), animated: true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
openSafari()
|
||||
present(SFSafariViewController(url: url), animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue