Capacitor plugin to enable background mode
This plugin replace to capacitor-plugin-background-mode
npm install @anuradev/capacitor-background-mode
npx cap sync
enable()
disable()
getSettings()
setSettings(...)
checkForegroundPermission()
requestForegroundPermission()
checkNotificationsPermission()
requestNotificationsPermission()
checkBatteryOptimizations()
requestDisableBatteryOptimizations()
enableWebViewOptimizations()
disableWebViewOptimizations()
moveToBackground()
moveToForeground()
isScreenOff()
isEnabled()
isActive()
wakeUp()
unlock()
addListener('appInBackground', ...)
addListener('appInForeground', ...)
removeAllListeners()
- Interfaces
- Type Aliases
enable() => Promise<void>
disable() => Promise<void>
getSettings() => Promise<{ settings: ISettings; }>
Returns: Promise<{ settings: ISettings; }>
setSettings(settings: Partial<ISettings>) => Promise<void>
Param | Type |
---|---|
settings |
Partial<ISettings> |
checkForegroundPermission() => Promise<PermissionStatus>
Returns: Promise<PermissionStatus>
requestForegroundPermission() => Promise<PermissionStatus>
Returns: Promise<PermissionStatus>
checkNotificationsPermission() => Promise<PermissionStatus>
Returns: Promise<PermissionStatus>
requestNotificationsPermission() => Promise<PermissionStatus>
Returns: Promise<PermissionStatus>
checkBatteryOptimizations() => Promise<{ disabled: boolean; }>
Returns: Promise<{ disabled: boolean; }>
requestDisableBatteryOptimizations() => Promise<{ disabled: boolean; }>
Returns: Promise<{ disabled: boolean; }>
enableWebViewOptimizations() => Promise<void>
disableWebViewOptimizations() => Promise<void>
moveToBackground() => Promise<void>
moveToForeground() => Promise<void>
isScreenOff() => Promise<{ isScreenOff: boolean; }>
Returns: Promise<{ isScreenOff: boolean; }>
isEnabled() => Promise<{ enabled: boolean; }>
Returns: Promise<{ enabled: boolean; }>
isActive() => Promise<{ activated: boolean; }>
Returns: Promise<{ activated: boolean; }>
wakeUp() => Promise<void>
unlock() => Promise<void>
addListener(eventName: 'appInBackground', listenerFunc: () => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'appInBackground' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'appInForeground', listenerFunc: () => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'appInForeground' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners() => Promise<void>
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' |
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. |
Prop | Type |
---|---|
"change" |
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 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. |
Method | Signature |
---|---|
handleEvent | (evt: Event) => void |
Prop | Type |
---|---|
once |
boolean |
passive |
boolean |
Prop | Type |
---|---|
capture |
boolean |
Prop | Type |
---|---|
remove |
() => Promise<void> |
Make all properties in T optional
{
[P in keyof T]?: T[P];
}
EventListener | EventListenerObject
"denied" | "granted" | "prompt"