|
import Katana |
|
import Ramen |
|
import SBundle |
|
import Storages |
|
import Tempura |
|
|
|
final class DependenciesContainer: RamenAppDelegate, SBundleProvider, Provider, <#Other app specific protocols#> { |
|
|
|
// MARK: - Basic Dependencies Container requirements |
|
let dispatch: StoreDispatch |
|
let promisableDispatch: PromisableStoreDispatch |
|
var getAppState: () -> AppState |
|
var navigator: Navigator = Navigator() |
|
var getState: () -> State { self.getAppState } |
|
|
|
// MARK: - SBundle |
|
var applicationBundle: Bundle = Bundle.main |
|
let sbundle = SBundle(bundle: Bundle.main, decryptionKey: SBundle.key) |
|
var appName: String { |
|
(self.applicationBundle.localizedInfoDictionary?[kCFBundleNameKey as String] as? String) |
|
?? (self.sbundle.infoDictionary[kCFBundleNameKey as String] as? String) |
|
?? <#App Name#> |
|
} |
|
|
|
<#Add here other specific managers and providers#> |
|
|
|
// MARK: - Ramen |
|
var ramen: ManagersContainer = ManagersContainer() |
|
|
|
init(dispatch: @escaping PromisableStoreDispatch, getAppState: @escaping () -> AppState) { |
|
self.dispatch = { dispatchable in |
|
_ = dispatch(dispatchable) |
|
} |
|
self.promisableDispatch = dispatch |
|
self.getAppState = getAppState |
|
|
|
super.init() |
|
|
|
self.ramen.start(with: RamenManagerConfiguration( |
|
analyticsConfiguration: self.analyticsConfiguration, |
|
appSetupConfiguration: self.appSetupConfiguration, |
|
customerSupportConfiguration: self.customerSupportConfiguration, |
|
localizationConfiguration: self.localizationConfiguration, |
|
monetizationConfiguration: self.monetizationConfiguration, |
|
remoteContentConfiguration: self.remoteContentConfiguration, |
|
reviewConfiguration: self.reviewConfiguration, |
|
sbundle: self.sbundle, |
|
secretMenuConfiguration: self.secretMenuConfiguration, |
|
systemSingletons: self.systemSingletonsConfiguration, |
|
storagesConfiguration: self.storagesConfiguration, |
|
thirdPartiesConfiguration: self.thirdPartiesConfiguration |
|
)) |
|
} |
|
} |
|
|
|
/// Analytics Configuration |
|
extension DependenciesContainer: AnalyticsConfigurationDelegate { |
|
func isPremium(state: State) -> [String: Bool] { |
|
guard let state = state as? AppState else { return [:] } |
|
return [ |
|
<#Custom Logic#> |
|
// e.g. |
|
// Metrics.UserInfo.Keys.isFreeUser.rawValue: state.isFreeUser, |
|
// Metrics.UserInfo.Keys.hasSubscribed.rawValue: state.isSubscribed, |
|
// Metrics.UserInfo.Keys.hasFreeAccess.rawValue: state.hasFreeAccess, |
|
] |
|
} |
|
|
|
var analyticsConfiguration: RamenManagerConfiguration.AnalyticsConfiguration { |
|
RamenManagerConfiguration.AnalyticsConfiguration( |
|
installedBeforePico: false, |
|
trackingServices: [ConsoleLoggerTrackingService(sbundle: self.sbundle)], |
|
trackingTasks: Metrics.all, |
|
delegate: self |
|
) |
|
} |
|
} |
|
|
|
/// AppSetup Configuration |
|
extension DependenciesContainer { |
|
var appSetupConfiguration: RamenManagerConfiguration.AppSetupConfiguration { |
|
RamenManagerConfiguration.AppSetupConfiguration() |
|
} |
|
} |
|
|
|
/// CustomerSupport Configuration |
|
extension DependenciesContainer { |
|
var customerSupportConfiguration: RamenManagerConfiguration.CustomerSupportConfiguration { |
|
RamenManagerConfiguration.CustomerSupportConfiguration() |
|
} |
|
} |
|
|
|
/// Localization Configuration |
|
extension DependenciesContainer { |
|
var localizationConfiguration: RamenManagerConfiguration.LocalizationConfiguration { |
|
RamenManagerConfiguration.LocalizationConfiguration(availableLanguages: [], startingScreen: Screen.appSetup.rawValue) |
|
} |
|
} |
|
|
|
/// Monetization Configuration |
|
extension DependenciesContainer: MonetizationConfigurationDelegate { |
|
func availableProductIDs(allIDs: [Models.Monetization.ProductID]) -> ([Models.Monetization.ProductID]) { |
|
[] |
|
} |
|
|
|
var monetizationConfiguration: RamenManagerConfiguration.MonetizationConfiguration { |
|
RamenManagerConfiguration.MonetizationConfiguration(delegate: self) |
|
} |
|
} |
|
|
|
/// RemoteContent Configuration |
|
extension DependenciesContainer: RemoteContentConfigurationDelegate { |
|
var remoteContentConfiguration: RamenManagerConfiguration.RemoteContentConfiguration { |
|
RamenManagerConfiguration.RemoteContentConfiguration( |
|
minDeployVersionSupported: 11, |
|
registeredResources: [ |
|
<#Custom App Resources#> |
|
// e.g. |
|
// MusicGenreResource.self, |
|
// AudioTrackResource.self, |
|
// StickerGroupResource.self, |
|
// StickerResource.self, |
|
], |
|
delegate: self |
|
) |
|
} |
|
} |
|
|
|
/// ReviewConfiguration Configuration |
|
extension DependenciesContainer { |
|
var reviewConfiguration: RamenManagerConfiguration.ReviewConfiguration { |
|
RamenManagerConfiguration.ReviewConfiguration() |
|
} |
|
} |
|
|
|
/// SecretMenu Configuration |
|
extension DependenciesContainer: SecretMenuConfigurationDelegate { |
|
var window: UIWindow { |
|
// It crashed at app start using keyWindow |
|
return UIApplication.shared.delegate!.window!! |
|
} |
|
|
|
func publicItems(state: State) -> [Models.SecretMenu.MenuItem] { |
|
[ |
|
<#Custom Public Items. Remove if not needed#> |
|
] |
|
} |
|
|
|
func debugItems(state: State) -> [Models.SecretMenu.MenuItem] { |
|
[ |
|
<#Custom Private Items. Remove if not needed#> |
|
] |
|
} |
|
|
|
var secretMenuConfiguration: RamenManagerConfiguration.SecretMenuConfiguration { |
|
RamenManagerConfiguration.SecretMenuConfiguration(delegate: self) |
|
} |
|
} |
|
|
|
/// Storages Configuration |
|
extension DependenciesContainer { |
|
var storagesConfiguration: RamenManagerConfiguration.StoragesConfiguration { |
|
RamenManagerConfiguration.StoragesConfiguration(secretsStorage: SecretsStorage(sbundle: self.sbundle)) |
|
} |
|
} |
|
|
|
/// SystemSingletons Configuration |
|
extension DependenciesContainer { |
|
var systemSingletonsConfiguration: RamenManagerConfiguration.SystemSingletons { |
|
RamenManagerConfiguration.SystemSingletons() |
|
} |
|
} |
|
|
|
/// ThirdParties Configuration |
|
extension DependenciesContainer: ThirdPartiesConfigurationDelegate { |
|
var thirdPartiesConfiguration: RamenManagerConfiguration.ThirdPartiesConfiguration { |
|
RamenManagerConfiguration.ThirdPartiesConfiguration(delegate: self) |
|
} |
|
} |
|
|
|
extension DependenciesContainer { |
|
convenience init(dispatch: @escaping PromisableStoreDispatch, getState: @escaping () -> State) { |
|
let getAppState: () -> AppState = { |
|
guard let state = getState() as? AppState else { |
|
fatalError("Wrong State Type") |
|
} |
|
return state |
|
} |
|
|
|
self.init(dispatch: dispatch, getAppState: getAppState) |
|
} |
|
} |
|
|
|
// MARK: - Promoted IAPs |
|
import StoreKit |
|
extension DependenciesContainer: SideEffectDependencyContainer { |
|
func transactionPaymentQueue(_ queue: SKPaymentQueue, |
|
shouldAddStorePayment payment: SKPayment, |
|
for product: SKProduct) -> Bool { |
|
if self.getAppState().isSubscribed { return false } |
|
|
|
_ = self.promisableDispatch(MonetizationActions.PromotedProductIdChanged(productIdentifier: product.productIdentifier)) |
|
return true |
|
} |
|
} |