forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureFlagNotifier.swift
More file actions
36 lines (31 loc) · 1.32 KB
/
FeatureFlagNotifier.swift
File metadata and controls
36 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Combine
import SwiftUI
public struct FeatureFlags: Hashable, Codable {
public var rt: Bool
public var sn: Bool
public var chat: Bool
public var xc: Bool?
}
public protocol FeatureFlagNotifier {
var featureFlags: FeatureFlags { get }
var featureFlagsDidChange: PassthroughSubject<FeatureFlags, Never> { get }
func handleFeatureFlagNotification(_ featureFlags: FeatureFlags)
}
public class FeatureFlagNotifierImpl: FeatureFlagNotifier {
public var featureFlags: FeatureFlags
public static let shared = FeatureFlagNotifierImpl()
public var featureFlagsDidChange: PassthroughSubject<FeatureFlags, Never>
init(featureFlags: FeatureFlags = FeatureFlags(rt: false, sn: false, chat: false),
featureFlagsDidChange: PassthroughSubject<FeatureFlags, Never> = PassthroughSubject<FeatureFlags, Never>()) {
self.featureFlags = featureFlags
self.featureFlagsDidChange = featureFlagsDidChange
}
public func handleFeatureFlagNotification(_ featureFlags: FeatureFlags) {
self.featureFlags = featureFlags
self.featureFlags.chat = featureFlags.chat == true && featureFlags.xc == true
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.featureFlagsDidChange.send(self.featureFlags)
}
}
}