Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Mar 1, 2024
1 parent 4788c1a commit 6b457fb
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 240 deletions.
2 changes: 1 addition & 1 deletion urbanairship-cordova/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="AirshipFrameworkProxy" spec="5.2.0" />
<pod name="AirshipFrameworkProxy" spec="5.2.1" />
</pods>
</podspec>
</platform>
Expand Down
45 changes: 27 additions & 18 deletions urbanairship-cordova/src/android/AirshipCordova.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ class AirshipCordova : CordovaPlugin() {
}
}
"push#android#setNotificationConfig" -> callback.resolveResult(method) { proxy.push.setNotificationConfig(arg) }
"push#android#setForegroundNotificationsEnabled" -> callback.resolveResult(method) {
proxy.push.isForegroundNotificationsEnabled = arg.requireBoolean()
return@resolveResult Unit
}
"push#android#isForegroundNotificationsEnabled" -> callback.resolveResult(method) {
proxy.push.isForegroundNotificationsEnabled
}

// In-App
"inApp#setPaused" -> callback.resolveResult(method) { proxy.inApp.setPaused(arg.getBoolean(false)) }
"inApp#isPaused" -> callback.resolveResult(method) { proxy.inApp.isPaused() }
Expand All @@ -214,10 +222,10 @@ class AirshipCordova : CordovaPlugin() {
"analytics#trackScreen" -> callback.resolveResult(method) { proxy.analytics.trackScreen(arg.optString()) }
"analytics#addEvent" -> callback.resolveResult(method) { proxy.analytics.addEvent(arg) }
"analytics#associateIdentifier" -> {
val args = arg.requireStringList()
val associatedIdentifierArgs = arg.requireStringList()
proxy.analytics.associateIdentifier(
args[0],
args.getOrNull(1)
associatedIdentifierArgs[0],
associatedIdentifierArgs.getOrNull(1)
)
}

Expand All @@ -227,16 +235,17 @@ class AirshipCordova : CordovaPlugin() {
}
"messageCenter#dismiss" -> callback.resolveResult(method) { proxy.messageCenter.dismiss() }
"messageCenter#display" -> callback.resolveResult(method) { proxy.messageCenter.display(arg.optString()) }
"messageCenter#showMessageView" -> callback.resolveResult(method) { proxy.messageCenter.showMessageView(arg.requireString()) }
"messageCenter#markMessageRead" -> callback.resolveResult(method) { proxy.messageCenter.markMessageRead(arg.requireString()) }
"messageCenter#deleteMessage" -> callback.resolveResult(method) { proxy.messageCenter.deleteMessage(arg.requireString()) }
"messageCenter#getUnreadMessageCount" -> callback.resolveResult(method) { proxy.messageCenter.getUnreadMessagesCount() }
"messageCenter#setAutoLaunch" -> callback.resolveResult(method) { proxy.messageCenter.setAutoLaunchDefaultMessageCenter(arg.requireBoolean()) }
"messageCenter#refreshMessages" -> callback.resolveDeferred(method) { callback ->
"messageCenter#refreshMessages" -> callback.resolveDeferred(method) { resolveCallback ->
proxy.messageCenter.refreshInbox().addResultCallback {
if (it == true) {
callback(null, null)
resolveCallback(null, null)
} else {
callback(null, Exception("Failed to refresh"))
resolveCallback(null, Exception("Failed to refresh"))
}
}
}
Expand All @@ -245,10 +254,10 @@ class AirshipCordova : CordovaPlugin() {
"preferenceCenter#display" -> callback.resolveResult(method) { proxy.preferenceCenter.displayPreferenceCenter(arg.requireString()) }
"preferenceCenter#getConfig" -> callback.resolvePending(method) { proxy.preferenceCenter.getPreferenceCenterConfig(arg.requireString()) }
"preferenceCenter#setAutoLaunch" -> callback.resolveResult(method) {
val args = arg.requireList()
val autoLaunchArgs = arg.requireList()
proxy.preferenceCenter.setAutoLaunchPreferenceCenter(
args.get(0).requireString(),
args.get(1).getBoolean(false)
autoLaunchArgs.get(0).requireString(),
autoLaunchArgs.get(1).getBoolean(false)
)
}

Expand All @@ -265,42 +274,42 @@ class AirshipCordova : CordovaPlugin() {
"locale#clearLocaleOverride" -> callback.resolveResult(method) { proxy.locale.clearLocale() }

// Actions
"actions#run" -> callback.resolveDeferred(method) { callback ->
"actions#run" -> callback.resolveDeferred(method) { resolveCallback ->
val actionArgs = arg.requireList()
val name= actionArgs.get(0).requireString()
val value: JsonValue? = if (actionArgs.size() == 2) { actionArgs.get(1) } else { null }

proxy.actions.runAction(name, value)
.addResultCallback { actionResult ->
if (actionResult != null && actionResult.status == ActionResult.STATUS_COMPLETED) {
callback(actionResult.value, null)
resolveCallback(actionResult.value, null)
} else {
callback(null, Exception("Action failed ${actionResult?.status}"))
resolveCallback(null, Exception("Action failed ${actionResult?.status}"))
}
}
}

// Feature Flag
"featureFlagManager#flag" -> callback.resolveDeferred(method) { callback ->
"featureFlagManager#flag" -> callback.resolveDeferred(method) { resolveCallback ->
scope.launch {
try {
val flag = proxy.featureFlagManager.flag(arg.requireString())
callback(flag, null)
resolveCallback(flag, null)
} catch (e: Exception) {
callback(null, e)
resolveCallback(null, e)
}
}
}

"featureFlagManager#trackInteraction" -> {
callback.resolveDeferred(method) { callback ->
callback.resolveDeferred(method) { resolveCallback ->
scope.launch {
try {
val featureFlagProxy = FeatureFlagProxy(arg)
proxy.featureFlagManager.trackInteraction(flag = featureFlagProxy)
callback(null, null)
resolveCallback(null, null)
} catch (e: Exception) {
callback(null, e)
resolveCallback(null, e)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion urbanairship-cordova/src/android/AirshipCordovaVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package com.urbanairship.cordova

object AirshipCordovaVersion {
var version = "16.0.0"
var version = "15.0.0"
}
11 changes: 3 additions & 8 deletions urbanairship-cordova/src/android/CordovaAutopilot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import com.urbanairship.UAirship
import com.urbanairship.analytics.Analytics
import com.urbanairship.android.framework.proxy.BaseAutopilot
import com.urbanairship.android.framework.proxy.ProxyStore
import com.urbanairship.android.framework.proxy.proxies.AirshipProxy


class CordovaAutopilot : BaseAutopilot() {

companion object {
private val PREFERENCE_FILE = "com.urbanairship.ua_plugin_shared_preferences"
private const val PREFERENCE_FILE = "com.urbanairship.ua_plugin_shared_preferences"
private const val PROCESSED_NOTIFICATIONS_OPTED_OUT_FLAG = "com.urbanairship.PROCESSED_NOTIFICATIONS_OPTED_OUT_FLAG"
}

Expand Down Expand Up @@ -70,11 +68,8 @@ class CordovaAutopilot : BaseAutopilot() {

override fun onMigrateData(context: Context, proxyStore: ProxyStore) {
val settings = settings(context)
val migrator = ProxyDataMigrator(preferences(context))
migrator.migrate(proxyStore, settings)

// TODO
// proxyStore.defaultAutoLaunchMessageCenter = settings?.autoLaunchMessageCenter ?: true
ProxyDataMigrator(preferences(context)).migrate(proxyStore, settings)
proxyStore.defaultAutoLaunchMessageCenter = settings.autoLaunchMessageCenter ?: true
}

override fun createConfigBuilder(context: Context): AirshipConfigOptions.Builder {
Expand Down
8 changes: 3 additions & 5 deletions urbanairship-cordova/src/android/ProxyDataMigrator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.urbanairship.android.framework.proxy.NotificationConfig
import com.urbanairship.android.framework.proxy.ProxyConfig
import com.urbanairship.android.framework.proxy.ProxyStore

internal class ProxyDataMigrator(val preferences: SharedPreferences) {
internal class ProxyDataMigrator(private val preferences: SharedPreferences) {

companion object {
private const val PRODUCTION_KEY = "com.urbanairship.production_app_key"
Expand Down Expand Up @@ -65,8 +65,7 @@ internal class ProxyDataMigrator(val preferences: SharedPreferences) {
if (development != null || production != null) {
store.airshipConfig = ProxyConfig(
productionEnvironment = production,
developmentEnvironment = development,
site = settings.cloudSite
developmentEnvironment = development
)

preferences.edit {
Expand All @@ -92,8 +91,7 @@ internal class ProxyDataMigrator(val preferences: SharedPreferences) {
return
}

// TODO
// store.showForegroundNotifications = preferences.getBoolean(FOREGROUND_NOTIFICATIONS, true)
store.isForegroundNotificationsEnabled = preferences.getBoolean(FOREGROUND_NOTIFICATIONS, true)
preferences.edit { this.remove(FOREGROUND_NOTIFICATIONS) }
}

Expand Down
3 changes: 1 addition & 2 deletions urbanairship-cordova/src/android/build-extras.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dependencies {
ext.airship_framework_proxy_version = '5.2.0'
api "com.urbanairship.android:airship-framework-proxy:$airship_framework_proxy_version"
api "com.urbanairship.android:airship-framework-proxy:5.2.1"
}

cdvPluginPostBuildExtras.push({
Expand Down
11 changes: 10 additions & 1 deletion urbanairship-cordova/src/ios/AirshipCordova.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public final class AirshipCordova: CDVPlugin {
.notificationStatusChanged: "airship.event.notification_status_changed"
]


@MainActor
public override func pluginInitialize() {
let settings = AirshipCordovaPluginSettings.from(
Expand Down Expand Up @@ -417,6 +416,16 @@ public final class AirshipCordova: CDVPlugin {
)
return nil

case "messageCenter#showMessageView":
try AirshipProxy.shared.messageCenter.showMessageView(
messageID: try command.requireStringArg()
)
return nil

case "messageCenter#dismiss":
try AirshipProxy.shared.messageCenter.dismiss()
return nil

case "messageCenter#markMessageRead":
try await AirshipProxy.shared.messageCenter.markMessageRead(
messageID: command.requireStringArg()
Expand Down
12 changes: 4 additions & 8 deletions urbanairship-cordova/src/ios/AirshipCordovaAutopilot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ final class AirshipCordovaAutopilot {
launchOptions: self.launchOptions
)
}

}

extension AirshipCordovaAutopilot: AirshipProxyDelegate {
public func migrateData(store: AirshipFrameworkProxy.ProxyStore) {
AirshipCordovaProxyDataMigrator().migrateData(
store: store,
settings: settings
)

/// TODO update proxy to set defaults
// store.defaultPresentationOptions = settings?.presentationOptions ?? []
// store.defaultAutoLaunchMessageCenter = settings?.autoLaunchMessageCenter ?? true
AirshipCordovaProxyDataMigrator().migrateData(store: store)
store.defaultPresentationOptions = settings?.presentationOptions ?? []
store.defaultAutoDisplayMessageCenter = settings?.autoLaunchMessageCenter ?? true
}

public func loadDefaultConfig() -> AirshipConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct AirshipCordovaPluginSettings: Decodable, Sendable {
var initialConfigURL: String?
var presentationOptions: UNNotificationPresentationOptions
var autoLaunchMessageCenter: Bool?
var messageCenterStyleConfig: String?

enum CodingKeys: String, CodingKey, CaseIterable {
case productionAppKey = "com.urbanairship.production_app_key"
Expand All @@ -74,8 +75,9 @@ struct AirshipCordovaPluginSettings: Decodable, Sendable {
case badgePresentationOption = "com.urbanairship.ios_foreground_notification_presentation_badge"
case soundPresentationOption = "com.urbanairship.ios_foreground_notification_presentation_sound"
case autoLaunchMessageCenter = "com.urbanairship.auto_launch_message_center"
case messageCenterStyleConfig = "com.urbanairship.message.center.style.file"
}

static func from(settings: [AnyHashable: Any]?) -> AirshipCordovaPluginSettings? {
guard let settings = settings else { return nil }
let knownKeys = CodingKeys.allCases.map { $0.rawValue }
Expand Down Expand Up @@ -108,6 +110,7 @@ struct AirshipCordovaPluginSettings: Decodable, Sendable {
self.initialConfigURL = try container.decodeIfPresent(String.self, forKey: .initialConfigURL)
self.analyticsEnabled = try container.decodeIfPresent(String.self, forKey: .analyticsEnabled)?.asBool
self.autoLaunchMessageCenter = try container.decodeIfPresent(String.self, forKey: .autoLaunchMessageCenter)?.asBool
self.messageCenterStyleConfig = try container.decodeIfPresent(String.self, forKey: .messageCenterStyleConfig)


let alert = try container.decodeIfPresent(String.self, forKey: .alertPresentationOption)?.asBool
Expand Down Expand Up @@ -172,6 +175,9 @@ struct AirshipCordovaPluginSettings: Decodable, Sendable {
config.isAnalyticsEnabled = analyticsEnabled
}

if let messageCenterStyleConfig = self.messageCenterStyleConfig {
config.messageCenterStyleConfig = messageCenterStyleConfig
}
}
}

Expand Down
22 changes: 16 additions & 6 deletions urbanairship-cordova/src/ios/AirshipCordovaProxyDataMigrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ struct AirshipCordovaProxyDataMigrator {
private static let site = "com.urbanairship.site"
private static let developmentAppKey = "com.urbanairship.development_app_key"
private static let developmentAppSecret = "com.urbanairship.development_app_secret"

private static let messageCenterStyleConfigKey = "com.urbanairship.message.center.style.file"
private static let autoLaunchMessageCenterKey = "com.urbanairship.auto_launch_message_center"

private static let autoLaunchPreferenceCenterPrefix = "com.urbanairship.preference_"
private static let autoLaunchPreferenceCenterSuffix = "_custom_ui"

private static let notificationPresentationAlertKey = "com.urbanairship.ios_foreground_notification_presentation_alert"
private static let notificationPresentationBadgeKey = "com.urbanairship.ios_foreground_notification_presentation_badge"
private static let notificationPresentationSoundKey = "com.urbanairship.ios_foreground_notification_presentation_sound"

func migrateData(store: ProxyStore, settings: AirshipCordovaPluginSettings?) {
migrateConfig(store: store, settings: settings)

func migrateData(store: ProxyStore) {
migrateConfig(store: store)
migrateAutoLaunchMessageCenter(store: store)
migrateAutoLaunchPreferenceCenter(store: store)
migratePresentationOptions(store: store)
}

private func migrateConfig(store: ProxyStore, settings: AirshipCordovaPluginSettings?) {
private func migrateConfig(store: ProxyStore) {

let productionAppKey = defaults.string(forKey: Self.productionAppKey)
let productionAppSecret = defaults.string(forKey: Self.productionAppSecret)
let developmentAppKey = defaults.string(forKey: Self.developmentAppKey)
let developmentAppSecret = defaults.string(forKey: Self.developmentAppSecret)
let messageCenterStyleConfig = defaults.string(forKey: Self.messageCenterStyleConfigKey)

let site: ProxyConfig.Site? = if let string = defaults.string(forKey: Self.site) {
AirshipCordovaSite(rawValue: string)?.proxyValue
} else {
Expand All @@ -44,7 +50,7 @@ struct AirshipCordovaProxyDataMigrator {
var production: ProxyConfig.Environment?
if let productionAppKey, let productionAppSecret {
production = ProxyConfig.Environment(
logLevel: settings?.productionLogLevel?.proxyValue,
logLevel: nil,
appKey: productionAppKey,
appSecret: productionAppSecret
)
Expand All @@ -53,7 +59,7 @@ struct AirshipCordovaProxyDataMigrator {
var development: ProxyConfig.Environment?
if let developmentAppKey, let developmentAppSecret {
development = ProxyConfig.Environment(
logLevel: settings?.developmentLogLevel?.proxyValue,
logLevel: nil,
appKey: developmentAppKey,
appSecret: developmentAppSecret
)
Expand All @@ -63,11 +69,15 @@ struct AirshipCordovaProxyDataMigrator {
store.config = ProxyConfig(
productionEnvironment: production,
developmentEnvironment: development,
site: site ?? settings?.site?.proxyValue ?? .us
ios: ProxyConfig.PlatformConfig(
messageCenterStyleConfig: messageCenterStyleConfig
),
site: site
)
}

[
Self.messageCenterStyleConfigKey,
Self.productionAppKey,
Self.productionAppSecret,
Self.developmentAppKey,
Expand Down
Loading

0 comments on commit 6b457fb

Please sign in to comment.