Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Capacitor Plugin #3

Merged
merged 28 commits into from
May 16, 2023
Merged

feat: Capacitor Plugin #3

merged 28 commits into from
May 16, 2023

Conversation

theproducer
Copy link
Collaborator

@theproducer theproducer commented Apr 25, 2023

This PR wraps both iOS-engine and android-engine into a capacitor plugin.

Users define their runner configuration in their application's capacitor.config.ts file. On load, the plugin parses the config file and sets up the configurations for the defined runners, and will automatically register them with the system when the app is backgrounded (so long as autoStart is true).

dispatchEvent: Can be called with arguments to call an event and get a response back from an already registered runner config while the app is in the foreground.

registerBackgroundTask: Will set up a passed in runner configuration and configure it to run the next time the app is backgrounded (if a runner for the same label exists, will update the config).

Android

Uses WorkManager for scheduling and running tasks in the background. Runner events that are configured to run once use the OneTimeWorkRequest, while repeatable runner events use the PeriodicWorkRequest.

flowchart TD
    CapacitorPlugin --> onLoad{onLoad}
    CapacitorPlugin --> dispatchEvent
    onLoad --> |Repeats| PeriodicWorkRequest
    onLoad --> |One Time| OneTimeWorkRequest
    PeriodicWorkRequest --> RunnerWorker
    OneTimeWorkRequest --> RunnerWorker
    RunnerWorker --> executeRunner
    dispatchEvent --> executeRunner
   executeRunner --> AndroidEngine

iOS

Uses the BackgroundTasks framework for scheduling and running tasks in the background. One time and repeatable events use BGAppRefreshTaskRequest, in the future if we run into issues with users attempting to execute long running processes, we can create some config options to use BGProcessingTaskRequest.

flowchart TD
    CapacitorPlugin --> onLoad{onLoad}
    CapacitorPlugin --> dispatchEvent
    onLoad --> |Repeats| BGAppRefreshTask
    onLoad --> |One Time| BGAppRefreshTask
    BGAppRefreshTask --> executeRunner
    dispatchEvent --> executeRunner
    executeRunner --> iOSEngine

@theproducer theproducer marked this pull request as ready for review April 26, 2023 15:15
Base automatically changed from ios-engine to main May 16, 2023 16:38
# Conflicts:
#	package.json
#	packages/ios-engine/.gitignore
#	packages/ios-engine/Package.swift
#	packages/ios-engine/Sources/RunnerEngine/Context.swift
#	packages/ios-engine/Sources/RunnerEngine/Errors.swift
#	packages/ios-engine/Sources/RunnerEngine/JSConsole.swift
#	packages/ios-engine/Sources/RunnerEngine/JSCrypto.swift
#	packages/ios-engine/Sources/RunnerEngine/JSTextDecoder.swift
#	packages/ios-engine/Sources/RunnerEngine/JSTextEncoder.swift
#	packages/ios-engine/Sources/RunnerEngine/Runner.swift
#	packages/ios-engine/Tests/RunnerEngineTests/ContextTests.swift
#	packages/ios-engine/Tests/RunnerEngineTests/RunnerTests.swift
#	pnpm-lock.yaml
#	pnpm-workspace.yaml
@theproducer theproducer merged commit ffac505 into main May 16, 2023
@theproducer theproducer deleted the capacitor-plugin branch May 16, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants