Skip to content

Commit

Permalink
[MOBILE-3857] migrate config (#175)
Browse files Browse the repository at this point in the history
* [MOBILE-3857] migrate config

* Fix iOS
  • Loading branch information
rlepinski authored Aug 21, 2023
1 parent 36316cf commit e30231d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 69 deletions.
61 changes: 0 additions & 61 deletions android/src/main/kotlin/com/airship/flutter/ConfigManager.kt

This file was deleted.

33 changes: 32 additions & 1 deletion android/src/main/kotlin/com/airship/flutter/FlutterAutopilot.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package com.airship.flutter

import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.airship.flutter.AirshipBackgroundExecutor.Companion.handleBackgroundMessage
import com.urbanairship.UAirship
import com.urbanairship.analytics.Analytics
import com.urbanairship.android.framework.proxy.BaseAutopilot
import com.urbanairship.android.framework.proxy.EventType
import com.urbanairship.android.framework.proxy.ProxyConfig
import com.urbanairship.android.framework.proxy.ProxyStore
import com.urbanairship.android.framework.proxy.events.EventEmitter
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

class FlutterAutopilot : BaseAutopilot() {

Expand Down Expand Up @@ -41,6 +51,27 @@ class FlutterAutopilot : BaseAutopilot() {
}

override fun onMigrateData(context: Context, proxyStore: ProxyStore) {
// TODO
runBlocking {
context.airshipFlutterPluginStore.data.map { preferences ->
val key = preferences[APP_KEY] ?: return@map null
val secret = preferences[APP_SECRET] ?: return@map null
ProxyConfig.Environment(key, secret, null)
}.first()?.let {
context.airshipFlutterPluginStore.edit { preferences ->
preferences.clear()
}
proxyStore.airshipConfig = ProxyConfig(defaultEnvironment = it)
}
}
}


companion object {
private val APP_KEY = stringPreferencesKey("app_key")
private val APP_SECRET = stringPreferencesKey("app_secret")
}

private val Context.airshipFlutterPluginStore: DataStore<Preferences> by preferencesDataStore(
name = "airshipFlutterPlugin"
)
}
14 changes: 10 additions & 4 deletions ios/Classes/AirshipAutopilot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ extension AirshipAutopilot: AirshipProxyDelegate {
public func migrateData(store: AirshipFrameworkProxy.ProxyStore) {
guard
let defaults = UserDefaults(suiteName: "com.urbanairship.flutter"),
defaults.string(forKey: "appKey") != nil,
defaults.string(forKey: "appSecret") != nil
let appKey = defaults.string(forKey: "appKey"),
let appSecret = defaults.string(forKey: "appSecret")
else {
return
}

// TODO

store.config = ProxyConfig(
defaultEnvironment: ProxyConfig.Environment(
logLevel: nil,
appKey: appKey,
appSecret: appSecret
)
)

defaults.removeObject(forKey: "appKey")
defaults.removeObject(forKey: "appSecret")
}
Expand Down
4 changes: 1 addition & 3 deletions ios/airship_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ Airship flutter plugin.
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'

s.ios.deployment_target = "15.0"
s.ios.deployment_target = "14.0"
s.dependency "AirshipFrameworkProxy", "4.0.4"

end

0 comments on commit e30231d

Please sign in to comment.