mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-22 21:08:15 +01:00
Fix EnvironmentObject related crash on macOS + iPad
This commit is contained in:
parent
382ebcf8f7
commit
dd6483dd37
@ -5,7 +5,9 @@ import Env
|
||||
import Status
|
||||
import DesignSystem
|
||||
import Lists
|
||||
import AppAccount
|
||||
|
||||
@MainActor
|
||||
extension View {
|
||||
func withAppRouteur() -> some View {
|
||||
self.navigationDestination(for: RouteurDestinations.self) { destination in
|
||||
@ -39,23 +41,41 @@ extension View {
|
||||
switch destination {
|
||||
case let .replyToStatusEditor(status):
|
||||
StatusEditorView(mode: .replyTo(status: status))
|
||||
.withEnvironments()
|
||||
case let .newStatusEditor(visibility):
|
||||
StatusEditorView(mode: .new(vivibilty: visibility))
|
||||
.withEnvironments()
|
||||
case let .editStatusEditor(status):
|
||||
StatusEditorView(mode: .edit(status: status))
|
||||
.withEnvironments()
|
||||
case let .quoteStatusEditor(status):
|
||||
StatusEditorView(mode: .quote(status: status))
|
||||
.withEnvironments()
|
||||
case let .mentionStatusEditor(account, visibility):
|
||||
StatusEditorView(mode: .mention(account: account, visibility: visibility))
|
||||
.withEnvironments()
|
||||
case let .listEdit(list):
|
||||
ListEditView(list: list)
|
||||
.withEnvironments()
|
||||
case let .listAddAccount(account):
|
||||
ListAddAccountView(account: account)
|
||||
.withEnvironments()
|
||||
case .addAccount:
|
||||
AddAccountView()
|
||||
.withEnvironments()
|
||||
case .addRemoteLocalTimeline:
|
||||
AddRemoteTimelineView()
|
||||
.withEnvironments()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func withEnvironments() -> some View {
|
||||
self
|
||||
.environmentObject(CurrentAccount.shared)
|
||||
.environmentObject(UserPreferences.shared)
|
||||
.environmentObject(CurrentInstance.shared)
|
||||
.environmentObject(Theme.shared)
|
||||
.environmentObject(AppAccountsManager.shared)
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ struct IceCubesApp: App {
|
||||
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@StateObject private var appAccountsManager = AppAccountsManager.shared
|
||||
@StateObject private var currentInstance = CurrentInstance()
|
||||
@StateObject private var currentAccount = CurrentAccount()
|
||||
@StateObject private var userPreferences = UserPreferences()
|
||||
@StateObject private var currentInstance = CurrentInstance.shared
|
||||
@StateObject private var currentAccount = CurrentAccount.shared
|
||||
@StateObject private var userPreferences = UserPreferences.shared
|
||||
@StateObject private var watcher = StreamWatcher()
|
||||
@StateObject private var quickLook = QuickLook()
|
||||
@StateObject private var theme = Theme()
|
||||
@StateObject private var theme = Theme.shared
|
||||
|
||||
@State private var selectedTab: Tab = .timeline
|
||||
@State private var selectSidebarItem: Tab? = .timeline
|
||||
|
@ -54,7 +54,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
bestAttemptContent.userInfo["plaintext"] = plaintextData
|
||||
bestAttemptContent.sound = UNNotificationSound.init(named: UNNotificationSoundName(rawValue: "glass.wav"))
|
||||
|
||||
let preferences = UserPreferences()
|
||||
let preferences = UserPreferences.shared
|
||||
preferences.pushNotificationsCount += 1
|
||||
|
||||
bestAttemptContent.badge = .init(integerLiteral: preferences.pushNotificationsCount)
|
||||
|
@ -14,18 +14,18 @@ class ShareViewController: UIViewController {
|
||||
super.viewDidLoad()
|
||||
|
||||
let client = AppAccountsManager.shared.currentClient
|
||||
let account = CurrentAccount()
|
||||
let instance = CurrentInstance()
|
||||
let account = CurrentAccount.shared
|
||||
let instance = CurrentInstance.shared
|
||||
account.setClient(client: client)
|
||||
instance.setClient(client: client)
|
||||
let colorScheme = traitCollection.userInterfaceStyle
|
||||
let theme = Theme()
|
||||
let theme = Theme.shared
|
||||
theme.setColor(withName: colorScheme == .dark ? .iceCubeDark : .iceCubeLight)
|
||||
|
||||
if let item = extensionContext?.inputItems.first as? NSExtensionItem {
|
||||
if let attachments = item.attachments {
|
||||
let view = StatusEditorView(mode: .shareExtension(items: attachments))
|
||||
.environmentObject(UserPreferences())
|
||||
.environmentObject(UserPreferences.shared)
|
||||
.environmentObject(client)
|
||||
.environmentObject(account)
|
||||
.environmentObject(theme)
|
||||
|
@ -80,7 +80,9 @@ public class Theme: ObservableObject {
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
public init() {
|
||||
public static let shared = Theme()
|
||||
|
||||
private init() {
|
||||
selectedSet = storedSet
|
||||
|
||||
// If theme is never set before set the default store. This should only execute once after install.
|
||||
|
@ -10,7 +10,9 @@ public class CurrentAccount: ObservableObject {
|
||||
|
||||
private var client: Client?
|
||||
|
||||
public init() { }
|
||||
static public let shared = CurrentAccount()
|
||||
|
||||
private init() { }
|
||||
|
||||
public func setClient(client: Client) {
|
||||
self.client = client
|
||||
|
@ -8,9 +8,9 @@ public class CurrentInstance: ObservableObject {
|
||||
|
||||
private var client: Client?
|
||||
|
||||
public init() {
|
||||
|
||||
}
|
||||
static public let shared = CurrentInstance()
|
||||
|
||||
private init() { }
|
||||
|
||||
public func setClient(client: Client) {
|
||||
self.client = client
|
||||
|
@ -6,6 +6,7 @@ import Network
|
||||
@MainActor
|
||||
public class UserPreferences: ObservableObject {
|
||||
public static let sharedDefault = UserDefaults.init(suiteName: "group.icecubesapps")
|
||||
public static let shared = UserPreferences()
|
||||
|
||||
private var client: Client?
|
||||
|
||||
@ -24,7 +25,7 @@ public class UserPreferences: ObservableObject {
|
||||
|
||||
@Published public var serverPreferences: ServerPreferences?
|
||||
|
||||
public init() { }
|
||||
private init() { }
|
||||
|
||||
public func setClient(client: Client) {
|
||||
self.client = client
|
||||
|
Loading…
Reference in New Issue
Block a user