Capacitor plugin to allow background execution of JavaScript
npm install @atroo/background-runner-ng
npx cap sync
Each time you re-install capacitor-sqlite plugin (including the first install), run the following
npm run sqlite-transpile
Each time you change the background.ts file, run:
npm run background-transpile
Modify capacitor.config.ts
...
plugins: {
BackgroundRunner: {
label: "com.example.background.task",
src: "background.ts", //ts file only. The folder is fixed. Check the location below
event: "updateData", //The event corresponds to the script's addEventListener
repeat: true, //Repeating event
interval: 15, //Interval of repetition. It should be more than 10. The exact timing is not guaranteed.
autoStart: true
},
},
...
The src file above should be placed here:
<<project root>>/src/assets/<<script name>>
The necessary .ts files is transcribed with the above package.json scripts from the capacitor-sqlite plugin.
checkPermissions() => Promise<PermissionStatus>
Check permissions for the various Capacitor device APIs.
Returns: Promise<PermissionStatus>
Since: 1.0.0
requestPermissions(options: RequestPermissionOptions) => Promise<PermissionStatus>
Request permission to display local notifications.
Param | Type |
---|---|
options |
RequestPermissionOptions |
Returns: Promise<PermissionStatus>
Since: 1.0.0
dispatchEvent(options: DispatchEventOptions) => Promise<void>
Dispatches an event to the configured runner.
Param | Type |
---|---|
options |
DispatchEventOptions |
Since: 1.0.0
Prop | Type |
---|---|
geolocation |
PermissionState |
notifications |
PermissionState |
Prop | Type |
---|---|
apis |
API[] |
Prop | Type | Description | Since |
---|---|---|---|
label |
string |
The runner label to dispatch the event to | 1.0.0 |
event |
string |
The name of the registered event listener. | 1.0.0 |
details |
{ [key: string]: any; } |
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
'geolocation' | 'notifications'