Skip to content

Commit

Permalink
feat: Android JS Engine / Plugin (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
theproducer committed Jul 18, 2023
1 parent 25e0279 commit 1f52918
Show file tree
Hide file tree
Showing 181 changed files with 10,313 additions and 7,542 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/reusable_build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
with:
main-branch-name: 'main'

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: 'Build Packages'
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion apps/example-app/android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-status-bar')
implementation project(':ionic-enterprise-background-runner')
implementation project(':capacitor-background-runner')

}

Expand Down
4 changes: 2 additions & 2 deletions apps/example-app/android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ project(':capacitor-keyboard').projectDir = new File('../../../node_modules/.pnp
include ':capacitor-status-bar'
project(':capacitor-status-bar').projectDir = new File('../../../node_modules/.pnpm/@capacitor+status-bar@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/status-bar/android')

include ':ionic-enterprise-background-runner'
project(':ionic-enterprise-background-runner').projectDir = new File('../../../packages/capacitor-plugin/android')
include ':capacitor-background-runner'
project(':capacitor-background-runner').projectDir = new File('../../../packages/capacitor-plugin/android')
7 changes: 0 additions & 7 deletions apps/example-app/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@ project(':capacitor-cordova-android-plugins').projectDir = new File('./capacitor

apply from: 'capacitor.settings.gradle'

def androidEngineProject = new File("./android-engine")
if (!androidEngineProject.exists()) {
androidEngineProject = new File("../node_modules/@ionic-enterprise/background-runner/android/android-engine")
}

include ':android-engine'
project(':android-engine').projectDir = androidEngineProject
3 changes: 1 addition & 2 deletions apps/example-app/capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const config: CapacitorConfig = {
event: "monitorLocation",
repeat: true,
interval: 2,
autoStart: true,
// TODO: Add Android / iOS constraints
autoStart: false,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion apps/example-app/ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def capacitor_pods
pod 'CapacitorHaptics', :path => '../../../../node_modules/.pnpm/@capacitor+haptics@4.1.0_@capacitor+core@4.7.3/node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../../../node_modules/.pnpm/@capacitor+keyboard@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/keyboard'
pod 'CapacitorStatusBar', :path => '../../../../node_modules/.pnpm/@capacitor+status-bar@4.1.1_@capacitor+core@4.7.3/node_modules/@capacitor/status-bar'
pod 'IonicEnterpriseBackgroundRunner', :path => '../../../../packages/capacitor-plugin'
pod 'CapacitorBackgroundRunner', :path => '../../../../packages/capacitor-plugin'
end

target 'App' do
Expand Down
2 changes: 1 addition & 1 deletion apps/example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@capacitor/ios": "^4.7.3",
"@capacitor/keyboard": "4.1.1",
"@capacitor/status-bar": "4.1.1",
"@ionic-enterprise/background-runner": "*",
"@capacitor/background-runner": "*",
"@ionic/react": "^6.0.0",
"@ionic/react-router": "^6.0.0",
"@testing-library/dom": "^9.2.0",
Expand Down
45 changes: 28 additions & 17 deletions apps/example-app/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ addEventListener("testLastKnownLocation", async (details) => {

console.log("current location: " + JSON.stringify(location));

CapacitorNotifications.schedule({
title: "Enterprise Background Runner",
body: `Your current location: ${location.lat}, ${location.lng}`,
});
CapacitorNotifications.schedule([
{
title: "Enterprise Background Runner",
body: `Your current location: ${location.lat}, ${location.lng}`,
},
]);

CapacitorKV.set("testValue", JSON.stringify(location));

Expand Down Expand Up @@ -90,7 +92,7 @@ addEventListener("testNetworkStatus", (details) => {

addEventListener("scheduleNotification", (details) => {
let scheduleDate = new Date();
scheduleDate.setSeconds(scheduleDate.getSeconds() + 15);
scheduleDate.setSeconds(scheduleDate.getSeconds() + 30);

CapacitorNotifications.schedule([
{
Expand All @@ -100,6 +102,7 @@ addEventListener("scheduleNotification", (details) => {
scheduleAt: scheduleDate,
},
]);

details.completed();
});

Expand All @@ -122,10 +125,14 @@ addEventListener("monitorLocation", async (details) => {

CapacitorKV.set("track", JSON.stringify(track));

CapacitorNotifications.schedule({
title: "Enterprise Background Runner",
body: "Recording your current location",
});
CapacitorNotifications.schedule([
{
id: 500,
title: "Enterprise Background Runner",
body: "Recording your current location",
scheduleAt: new Date(),
},
]);

details.completed();
});
Expand All @@ -139,10 +146,12 @@ addEventListener("getSavedLocations", (details) => {
addEventListener("remoteNotification", (details) => {
console.log("received silent push notification");

CapacitorNotifications.schedule({
title: "Enterprise Background Runner",
body: "Received silent push notification",
});
CapacitorNotifications.schedule([
{
title: "Enterprise Background Runner",
body: "Received silent push notification",
},
]);

console.log(`details: ${JSON.stringify(details)}`);

Expand Down Expand Up @@ -190,10 +199,12 @@ addEventListener("WatchConnectivity_didReceiveUserInfo", (details) => {
addEventListener("WatchConnectivity_didReceiveMessage", (details) => {
const msg = details.message.result;

CapacitorNotifications.schedule({
title: "Enterprise Background Runner",
body: msg,
});
CapacitorNotifications.schedule([
{
title: "Enterprise Background Runner",
body: msg,
},
]);

console.log(`watch sent data: ${JSON.stringify(details)}`);
details.completed();
Expand Down
46 changes: 2 additions & 44 deletions apps/example-app/src/components/ExploreContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackgroundRunner } from "@ionic-enterprise/background-runner";
import { BackgroundRunner } from "@capacitor/background-runner";
import "./ExploreContainer.css";
import { IonButton } from "@ionic/react";

Expand Down Expand Up @@ -114,45 +114,6 @@ const ExploreContainer: React.FC<ContainerProps> = ({ name }) => {
}
}

const onTestCurrentLocation = async () => {
try {
await BackgroundRunner.dispatchEvent({
label: "com.example.background.task",
event: "testCurrentLocation",
details: {},
});
} catch (err) {
alert(err);
console.error(err);
}
}

const onTestStartLiveLocation = async () => {
try {
await BackgroundRunner.dispatchEvent({
label: "com.example.background.task",
event: "testStartLocationWatch",
details: {},
});
} catch (err) {
alert(err);
console.error(err);
}
}

const onTestStopLiveLocation = async () => {
try {
await BackgroundRunner.dispatchEvent({
label: "com.example.background.task",
event: "testEndLocationWatch",
details: {},
});
} catch (err) {
alert(err);
console.error(err);
}
}

const onMonitorLocation = async () => {
try {
await BackgroundRunner.dispatchEvent({
Expand Down Expand Up @@ -281,10 +242,7 @@ const ExploreContainer: React.FC<ContainerProps> = ({ name }) => {
<IonButton onClick={onTestKV}>Test KV</IonButton>
<IonButton onClick={onTestGetKV}>Test Get KV</IonButton>
<IonButton onClick={onTestNotification}>Test Notification</IonButton>
<IonButton onClick={onTestLocation}>Get Last Known Location</IonButton>
<IonButton onClick={onTestCurrentLocation}>Get Current Location</IonButton>
<IonButton onClick={onTestStartLiveLocation}>Start Live Location</IonButton>
<IonButton onClick={onTestStopLiveLocation}>Stop Live Location</IonButton>
<IonButton onClick={onTestLocation}>GetLast Known Location</IonButton>
<IonButton onClick={onMonitorLocation}>Record Location</IonButton>
<IonButton onClick={onGetTrackedLocations}>Get Location Report</IonButton>
<IonButton onClick={onCheckWatchReachable}>Check Watch Status</IonButton>
Expand Down
4 changes: 4 additions & 0 deletions packages/android-engine/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_package-name = disabled

17 changes: 7 additions & 10 deletions packages/android-engine/.gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
*.iml
.gradle
local.properties
.idea/caches
.idea/libraries
.idea/modules.xml
.idea/workspace.xml
.idea/navEditor.xml
.idea/kotlinc.xml
.idea/assetWizardSettings.xml
.idea/androidTestResultsUserPreferences.xml

/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
Expand Down
2 changes: 1 addition & 1 deletion packages/android-engine/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f52918

Please sign in to comment.