Skip to content

ramisalminen/capacitor-background-mode

 
 

Repository files navigation

@anuradev/capacitor-background-mode

Capacitor plugin to enable background mode

This plugin replace to capacitor-plugin-background-mode

Install

npm install @anuradev/capacitor-background-mode
npx cap sync

API

enable()

enable() => Promise<void>

disable()

disable() => Promise<void>

getSettings()

getSettings() => Promise<{ settings: ISettings; }>

Returns: Promise<{ settings: ISettings; }>


setSettings(...)

setSettings(settings: Partial<ISettings>) => Promise<void>
Param Type
settings Partial<ISettings>

checkForegroundPermission()

checkForegroundPermission() => Promise<PermissionStatus>

Returns: Promise<PermissionStatus>


requestForegroundPermission()

requestForegroundPermission() => Promise<PermissionStatus>

Returns: Promise<PermissionStatus>


checkNotificationsPermission()

checkNotificationsPermission() => Promise<PermissionStatus>

Returns: Promise<PermissionStatus>


requestNotificationsPermission()

requestNotificationsPermission() => Promise<PermissionStatus>

Returns: Promise<PermissionStatus>


checkBatteryOptimizations()

checkBatteryOptimizations() => Promise<{ disabled: boolean; }>

Returns: Promise<{ disabled: boolean; }>


requestDisableBatteryOptimizations()

requestDisableBatteryOptimizations() => Promise<{ disabled: boolean; }>

Returns: Promise<{ disabled: boolean; }>


enableWebViewOptimizations()

enableWebViewOptimizations() => Promise<void>

disableWebViewOptimizations()

disableWebViewOptimizations() => Promise<void>

moveToBackground()

moveToBackground() => Promise<void>

moveToForeground()

moveToForeground() => Promise<void>

isScreenOff()

isScreenOff() => Promise<{ isScreenOff: boolean; }>

Returns: Promise<{ isScreenOff: boolean; }>


isEnabled()

isEnabled() => Promise<{ enabled: boolean; }>

Returns: Promise<{ enabled: boolean; }>


isActive()

isActive() => Promise<{ activated: boolean; }>

Returns: Promise<{ activated: boolean; }>


wakeUp()

wakeUp() => Promise<void>

unlock()

unlock() => Promise<void>

addListener('appInBackground', ...)

addListener(eventName: 'appInBackground', listenerFunc: () => void) => Promise<PluginListenerHandle>
Param Type
eventName 'appInBackground'
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener('appInForeground', ...)

addListener(eventName: 'appInForeground', listenerFunc: () => void) => Promise<PluginListenerHandle>
Param Type
eventName 'appInForeground'
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

ISettings

Prop Type
title string
text string
subText string
bigText boolean
resume boolean
silent boolean
hidden boolean
color string
icon string
channelName string
channelDescription string
allowClose boolean
closeIcon string
closeTitle string
showWhen boolean
disableWebViewOptimization boolean
visibility 'private' | 'public' | 'secret'

PermissionStatus

Prop Type
onchange ((this: PermissionStatus, ev: Event) => any) | null
state PermissionState
Method Signature Description
addEventListener <K extends "change">(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined) => void Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched. The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture. When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET. When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners. When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed. The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
addEventListener (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined) => void Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched. The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture. When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET. When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners. When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed. The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
removeEventListener <K extends "change">(type: K, listener: (this: PermissionStatus, ev: PermissionStatusEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined) => void Removes the event listener in target's event listener list with the same type, callback, and options.
removeEventListener (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined) => void Removes the event listener in target's event listener list with the same type, callback, and options.

PermissionStatusEventMap

Prop Type
"change" Event

Event

An event which takes place in the DOM.

Prop Type Description
bubbles boolean Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
cancelBubble boolean
cancelable boolean Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.
composed boolean Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
currentTarget EventTarget | null Returns the object whose event listener's callback is currently being invoked.
defaultPrevented boolean Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
eventPhase number Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
isTrusted boolean Returns true if event was dispatched by the user agent, and false otherwise.
returnValue boolean
srcElement EventTarget | null
target EventTarget | null Returns the object to which event is dispatched (its target).
timeStamp number Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
type string Returns the type of event, e.g. "click", "hashchange", or "submit".
AT_TARGET number
BUBBLING_PHASE number
CAPTURING_PHASE number
NONE number
Method Signature Description
composedPath () => EventTarget[] Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget.
initEvent (type: string, bubbles?: boolean | undefined, cancelable?: boolean | undefined) => void
preventDefault () => void If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled.
stopImmediatePropagation () => void Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
stopPropagation () => void When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.

EventTarget

EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

Method Signature Description
addEventListener (type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined) => void Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched. The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture. When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET. When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners. When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed. The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
dispatchEvent (event: Event) => boolean Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
removeEventListener (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => void Removes the event listener in target's event listener list with the same type, callback, and options.

EventListener

EventListenerObject

Method Signature
handleEvent (evt: Event) => void

AddEventListenerOptions

Prop Type
once boolean
passive boolean

EventListenerOptions

Prop Type
capture boolean

PluginListenerHandle

Prop Type
remove () => Promise<void>

Type Aliases

Partial

Make all properties in T optional

{ [P in keyof T]?: T[P]; }

EventListenerOrEventListenerObject

EventListener | EventListenerObject

PermissionState

"denied" | "granted" | "prompt"

About

Fork of capacitor background mode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 82.7%
  • TypeScript 9.9%
  • Swift 3.0%
  • Ruby 2.0%
  • Objective-C 1.4%
  • JavaScript 1.0%