metatext/ServiceLayer/Sources/ServiceLayer/Entities/AppEnvironment.swift

64 lines
2.2 KiB
Swift
Raw Normal View History

2020-08-02 22:23:01 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
2020-09-03 03:28:34 +00:00
import DB
2020-08-02 22:23:01 +00:00
import Foundation
2020-08-31 01:40:58 +00:00
import HTTP
2020-09-04 00:54:05 +00:00
import Keychain
2020-08-30 23:33:11 +00:00
import Mastodon
2020-09-01 07:33:49 +00:00
import UserNotifications
2020-08-02 22:23:01 +00:00
2020-08-31 10:21:01 +00:00
public struct AppEnvironment {
2020-09-23 07:04:37 +00:00
let session: URLSession
2020-08-12 09:01:21 +00:00
let webAuthSessionType: WebAuthSession.Type
2020-09-04 00:54:05 +00:00
let keychain: Keychain.Type
2020-08-18 05:13:37 +00:00
let userDefaults: UserDefaults
2020-09-01 07:33:49 +00:00
let userNotificationClient: UserNotificationClient
2020-10-22 22:16:06 +00:00
let reduceMotion: () -> Bool
2021-03-06 02:25:18 +00:00
let autoplayVideos: () -> Bool
2020-12-18 00:17:17 +00:00
let uuid: () -> UUID
2020-08-18 05:13:37 +00:00
let inMemoryContent: Bool
2020-09-08 02:12:38 +00:00
let fixtureDatabase: IdentityDatabase?
2020-08-31 10:21:01 +00:00
2020-09-23 07:04:37 +00:00
public init(session: URLSession,
2020-08-31 10:21:01 +00:00
webAuthSessionType: WebAuthSession.Type,
2020-09-04 00:54:05 +00:00
keychain: Keychain.Type,
2020-08-31 10:21:01 +00:00
userDefaults: UserDefaults,
2020-09-01 07:33:49 +00:00
userNotificationClient: UserNotificationClient,
2020-10-22 22:16:06 +00:00
reduceMotion: @escaping () -> Bool,
2021-03-06 02:25:18 +00:00
autoplayVideos: @escaping () -> Bool,
2020-09-13 00:50:22 +00:00
uuid: @escaping () -> UUID,
2020-09-01 07:33:49 +00:00
inMemoryContent: Bool,
2020-09-08 02:12:38 +00:00
fixtureDatabase: IdentityDatabase?) {
2020-08-31 10:21:01 +00:00
self.session = session
self.webAuthSessionType = webAuthSessionType
2020-09-04 00:54:05 +00:00
self.keychain = keychain
2020-08-31 10:21:01 +00:00
self.userDefaults = userDefaults
2020-09-01 07:33:49 +00:00
self.userNotificationClient = userNotificationClient
2020-10-22 22:16:06 +00:00
self.reduceMotion = reduceMotion
2021-03-06 02:25:18 +00:00
self.autoplayVideos = autoplayVideos
2020-09-13 00:50:22 +00:00
self.uuid = uuid
2020-08-31 10:21:01 +00:00
self.inMemoryContent = inMemoryContent
2020-09-08 02:12:38 +00:00
self.fixtureDatabase = fixtureDatabase
2020-08-31 10:21:01 +00:00
}
2020-08-12 07:24:39 +00:00
}
2020-08-31 10:21:01 +00:00
public extension AppEnvironment {
2020-11-09 03:07:23 +00:00
static let appGroup = "group.metabolist.metatext"
2021-03-06 02:25:18 +00:00
static func live(userNotificationCenter: UNUserNotificationCenter,
reduceMotion: @escaping () -> Bool,
autoplayVideos: @escaping () -> Bool) -> Self {
2020-09-01 07:33:49 +00:00
Self(
2020-09-23 07:04:37 +00:00
session: URLSession.shared,
2020-09-01 07:33:49 +00:00
webAuthSessionType: LiveWebAuthSession.self,
2020-09-04 00:54:05 +00:00
keychain: LiveKeychain.self,
2020-11-09 03:07:23 +00:00
userDefaults: UserDefaults(suiteName: appGroup)!,
2020-09-01 07:33:49 +00:00
userNotificationClient: .live(userNotificationCenter),
2020-10-22 22:16:06 +00:00
reduceMotion: reduceMotion,
2021-03-06 02:25:18 +00:00
autoplayVideos: autoplayVideos,
2020-09-13 00:50:22 +00:00
uuid: UUID.init,
2020-09-01 07:33:49 +00:00
inMemoryContent: false,
2020-09-08 02:12:38 +00:00
fixtureDatabase: nil)
2020-09-01 07:33:49 +00:00
}
2020-08-02 22:23:01 +00:00
}