Skip to content

Commit

Permalink
Release 1.0.0 (#1)
Browse files Browse the repository at this point in the history
* Changelog

* Wire up plugin config

* Plugin config for Android

* Latest proxy

* update pod file

* Fix
  • Loading branch information
rlepinski authored Mar 22, 2024
1 parent e55f3ab commit dfa64cf
Show file tree
Hide file tree
Showing 17 changed files with 1,649 additions and 66 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Capacitor Plugin Changelog

## Version 1.0.0 March 22, 2024

Initial capacitor plugin release
2 changes: 1 addition & 1 deletion UaCapacitorAirship.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '14.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
s.dependency "AirshipFrameworkProxy", "5.3.0"
s.dependency "AirshipFrameworkProxy", "5.4.1"
end
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ repositories {
}

dependencies {
def proxyVersion = '5.4.0'
def proxyVersion = '5.4.1'
def airshipVersion = '17.7.3'
def kotlinVersion = project.hasProperty('kotlinVersion') ? rootProject.ext.kotlinVersion : '1.8.20'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlinx.coroutines.plus
import org.json.JSONArray
import org.json.JSONObject

@CapacitorPlugin(name = "AirshipPlugin")
@CapacitorPlugin(name = "Airship")
class AirshipPlugin : Plugin() {
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Main) + SupervisorJob()

Expand Down
12 changes: 12 additions & 0 deletions android/src/main/java/com/airship/capacitor/CapacitorAutopilot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ package com.airship.capacitor

import android.content.Context
import android.util.Log
import com.getcapacitor.CapConfig
import com.urbanairship.AirshipConfigOptions
import com.urbanairship.UAirship
import com.urbanairship.analytics.Analytics
import com.urbanairship.android.framework.proxy.BaseAutopilot
import com.urbanairship.android.framework.proxy.ProxyConfig
import com.urbanairship.android.framework.proxy.ProxyStore
import com.urbanairship.android.framework.proxy.applyProxyConfig
import com.urbanairship.json.JsonValue

class CapacitorAutopilot : BaseAutopilot() {

Expand All @@ -18,7 +23,14 @@ class CapacitorAutopilot : BaseAutopilot() {

// TODO capacitor
airship.analytics.registerSDKExtension(Analytics.EXTENSION_CORDOVA, AirshipCapacitorVersion.version)
}

override fun createConfigBuilder(context: Context): AirshipConfigOptions.Builder {
val pluginConfig = CapConfig.loadDefault(context).getPluginConfiguration("Airship")
val proxyConfig = ProxyConfig(JsonValue.wrapOpt(pluginConfig.getObject("config")).optMap())
val builder = AirshipConfigOptions.newBuilder().applyDefaultProperties(context)
builder.applyProxyConfig(context, proxyConfig)
return builder
}

override fun onMigrateData(context: Context, proxyStore: ProxyStore) {
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
namespace "com.example.plugin"
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.example.plugin"
applicationId "com.urbanairship.sample"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
Expand Down
4 changes: 4 additions & 0 deletions example/ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
504EC3111FED79650016851F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
504EC3131FED79650016851F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
50B271D01FEDC1A000F3C39B /* public */ = {isa = PBXFileReference; lastKnownFileType = folder; path = public; sourceTree = "<group>"; };
6EBCF9A32BAE46C200C6F6A9 /* App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = App.entitlements; sourceTree = "<group>"; };
AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.debug.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -73,6 +74,7 @@
504EC3061FED79650016851F /* App */ = {
isa = PBXGroup;
children = (
6EBCF9A32BAE46C200C6F6A9 /* App.entitlements */,
50379B222058CBB4000EE86E /* capacitor.config.json */,
504EC3071FED79650016851F /* AppDelegate.swift */,
504EC30B1FED79650016851F /* Main.storyboard */,
Expand Down Expand Up @@ -345,6 +347,7 @@
baseConfigurationReference = FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = PGJV57GD94;
Expand All @@ -366,6 +369,7 @@
baseConfigurationReference = AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = PGJV57GD94;
Expand Down
8 changes: 8 additions & 0 deletions example/ios/App/App/App.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
85 changes: 43 additions & 42 deletions example/src/js/capacitor-welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ window.customElements.define(
super();

SplashScreen.hide();
window.Airship = Airship;

const root = this.attachShadow({ mode: 'open' });

Expand Down Expand Up @@ -79,9 +80,9 @@ window.customElements.define(
This demo shows how to call Capacitor plugins. Say cheese!
</p>
<p>
<button class="button" id="call-plugin">Call plugin</button>
<button class="button" id="enable-push">Toggle push</button>
</p>
<p id="plugin-result">
<p id="status-event">
</p>
</main>
</div>
Expand All @@ -91,56 +92,56 @@ window.customElements.define(
connectedCallback() {
const self = this;

self.shadowRoot.querySelector('#call-plugin').addEventListener('click', async function (e) {
try {
await Airship.onDeepLink(event => {
console.log("onDeepLink", JSON.stringify(event))
})
self.shadowRoot.querySelector('#enable-push').addEventListener('click', async function (e) {
const isEnabled = await Airship.push.isUserNotificationsEnabled()
await Airship.push.setUserNotificationsEnabled(!isEnabled)
});
}
}
);

await Airship.push.onNotificationResponse(event => {
console.log("push.onNotificationResponse", JSON.stringify(event))
})
window.onload = async function() {
await Airship.onDeepLink(event => {
console.log("onDeepLink", JSON.stringify(event))
});

await Airship.push.onNotificationStatusChanged(event => {
console.log("push.onNotificationStatusChanged", JSON.stringify(event))
})
await Airship.push.onNotificationResponse(event => {
console.log("push.onNotificationResponse", JSON.stringify(event))
});

await Airship.push.onPushReceived(event => {
console.log("push.onPushReceived", JSON.stringify(event))
})
await Airship.push.onNotificationStatusChanged(event => {
console.log("push.onNotificationStatusChanged", JSON.stringify(event))
});

await Airship.push.onPushTokenReceived(event => {
console.log("push.onPushTokenReceived", JSON.stringify(event))
})
await Airship.push.onPushReceived(event => {
console.log("push.onPushReceived", JSON.stringify(event))
});

await Airship.channel.onChannelCreated(event => {
console.log("channel.onChannelCreated", JSON.stringify(event))
})
await Airship.push.onPushTokenReceived(event => {
console.log("push.onPushTokenReceived", JSON.stringify(event))
});

await Airship.messageCenter.onUpdated(event => {
console.log("messageCenter.onUpdated", JSON.stringify(event))
})
await Airship.channel.onChannelCreated(event => {
console.log("channel.onChannelCreated", JSON.stringify(event))
});

await Airship.messageCenter.onDisplay(event => {
console.log("messageCenter.onDisplay", JSON.stringify(event))
})
await Airship.messageCenter.onUpdated(event => {
console.log("messageCenter.onUpdated", JSON.stringify(event))
});

await Airship.preferenceCenter.onDisplay(event => {
console.log("preferenceCenter.onDisplay", JSON.stringify(event))
})
await Airship.messageCenter.onDisplay(event => {
console.log("messageCenter.onDisplay", JSON.stringify(event))
});

await Airship.push.iOS.onAuthorizedSettingsChanged(event => {
console.log("push.onAuthorizedSettingsChanged", JSON.stringify(event))
})
await Airship.preferenceCenter.onDisplay(event => {
console.log("preferenceCenter.onDisplay", JSON.stringify(event))
});

await Airship.push.iOS.onAuthorizedSettingsChanged(event => {
console.log("push.onAuthorizedSettingsChanged", JSON.stringify(event))
});
};

window.Airship = Airship
} catch (e) {
console.warn('User cancelled', e);
}
});
}
}
);

window.customElements.define(
'capacitor-welcome-titlebar',
Expand Down
20 changes: 16 additions & 4 deletions ios/Plugin/AirshipCapacitorAutopilot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import AirshipKit
import AirshipFrameworkProxy
import Capacitor

@objc
public final class AirshipCapacitorAutopilot: NSObject {
Expand All @@ -16,6 +17,8 @@ public final class AirshipCapacitorAutopilot: NSObject {
@MainActor
private var launchOptions: [UIApplication.LaunchOptionsKey : Any]?

fileprivate var pluginConfig: PluginConfig?

/*
* In Capacitor 5, the order of initialization is:
* - AppDelegate#applicationDidFinishLaunching
Expand Down Expand Up @@ -43,8 +46,9 @@ public final class AirshipCapacitorAutopilot: NSObject {
}

@MainActor
public func onPluginInitialized() {
public func onPluginInitialized(pluginConfig: PluginConfig?) {
self.pluginInitialized = true
self.pluginConfig = pluginConfig
if self.pluginInitialized, self.applicationDidFinishLaunching {
try? AirshipProxy.shared.attemptTakeOff(
launchOptions: self.launchOptions
Expand All @@ -62,11 +66,19 @@ public final class AirshipCapacitorAutopilot: NSObject {
}

extension AirshipCapacitorAutopilot: AirshipProxyDelegate {
public func migrateData(store: AirshipFrameworkProxy.ProxyStore) {
}
public func migrateData(store: AirshipFrameworkProxy.ProxyStore) {}

public func loadDefaultConfig() -> AirshipConfig {
return AirshipConfig.default()
let airshipConfig = AirshipConfig.default()
if let config = self.pluginConfig?.getObject("config") {
do {
let proxyConfig: ProxyConfig = try AirshipJSON.wrap(config).decode()
airshipConfig.applyProxyConfig(proxyConfig: proxyConfig)
} catch {
AirshipLogger.error("Failed to parse config: \(error)")
}
}
return airshipConfig
}

@MainActor
Expand Down
2 changes: 1 addition & 1 deletion ios/Plugin/AirshipPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

// Define the plugin using the CAP_PLUGIN Macro, and
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
CAP_PLUGIN(AirshipPlugin, "AirshipPlugin",
CAP_PLUGIN(AirshipPlugin, "Airship",
CAP_PLUGIN_METHOD(perform, CAPPluginReturnPromise);
)
4 changes: 3 additions & 1 deletion ios/Plugin/AirshipPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class AirshipPlugin: CAPPlugin {

@MainActor
public override func load() {
AirshipCapacitorAutopilot.shared.onPluginInitialized()
AirshipCapacitorAutopilot.shared.onPluginInitialized(
pluginConfig: self.getConfig()
)

Task {
for await _ in await AirshipProxyEventEmitter.shared.pendingEventAdded {
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def capacitor_pods
use_frameworks!
pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../node_modules/@capacitor/ios'
pod 'AirshipFrameworkProxy', '5.3.0'
pod 'AirshipFrameworkProxy', '5.4.1'
end

target 'Plugin' do
Expand Down
Loading

0 comments on commit dfa64cf

Please sign in to comment.