Skip to content

atroo/capacitor-background-runner-ng

Repository files navigation

@atroo/background-runner-ng

Capacitor plugin to allow background execution of JavaScript

Install/Usage

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

Config

Plugin config

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>>

About SQLite API

The necessary .ts files is transcribed with the above package.json scripts from the capacitor-sqlite plugin.

API

checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check permissions for the various Capacitor device APIs.

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions(...)

requestPermissions(options: RequestPermissionOptions) => Promise<PermissionStatus>

Request permission to display local notifications.

Param Type
options RequestPermissionOptions

Returns: Promise<PermissionStatus>

Since: 1.0.0


dispatchEvent(...)

dispatchEvent(options: DispatchEventOptions) => Promise<void>

Dispatches an event to the configured runner.

Param Type
options DispatchEventOptions

Since: 1.0.0


Interfaces

PermissionStatus

Prop Type
geolocation PermissionState
notifications PermissionState

RequestPermissionOptions

Prop Type
apis API[]

DispatchEventOptions

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; }

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

API

'geolocation' | 'notifications'

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •