forked from shadowfacts/Tusker
50 lines
1.3 KiB
Swift
50 lines
1.3 KiB
Swift
//
|
|
// Environment.swift
|
|
// ComposeUI
|
|
//
|
|
// Created by Shadowfacts on 8/10/24.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Pachyderm
|
|
|
|
//@propertyWrapper
|
|
//struct RequiredEnvironment<Value>: DynamicProperty {
|
|
// private let keyPath: KeyPath<EnvironmentValues, Value?>
|
|
// @Environment private var value: Value?
|
|
//
|
|
// init(_ keyPath: KeyPath<EnvironmentValues, Value?>) {
|
|
// self.keyPath = keyPath
|
|
// self._value = Environment(keyPath)
|
|
// }
|
|
//
|
|
// var wrappedValue: Value {
|
|
// guard let value else {
|
|
// preconditionFailure("Missing required environment value for \(keyPath)")
|
|
// }
|
|
// return value
|
|
// }
|
|
//}
|
|
|
|
private struct ComposeMastodonContextKey: EnvironmentKey {
|
|
static let defaultValue: (any ComposeMastodonContext)? = nil
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
var mastodonController: (any ComposeMastodonContext)? {
|
|
get { self[ComposeMastodonContextKey.self] }
|
|
set { self[ComposeMastodonContextKey.self] = newValue }
|
|
}
|
|
}
|
|
|
|
private struct CurrentAccountKey: EnvironmentKey {
|
|
static let defaultValue: (any AccountProtocol)? = nil
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
var currentAccount: (any AccountProtocol)? {
|
|
get { self[CurrentAccountKey.self] }
|
|
set { self[CurrentAccountKey.self] = newValue }
|
|
}
|
|
}
|