angeloraso / capacitor-background-mode

15 stars 9 forks source link

@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) * [`disable()`](#disable) * [`getSettings()`](#getsettings) * [`setSettings(...)`](#setsettings) * [`checkForegroundPermission()`](#checkforegroundpermission) * [`requestForegroundPermission()`](#requestforegroundpermission) * [`checkNotificationsPermission()`](#checknotificationspermission) * [`requestNotificationsPermission()`](#requestnotificationspermission) * [`checkBatteryOptimizations()`](#checkbatteryoptimizations) * [`requestDisableBatteryOptimizations()`](#requestdisablebatteryoptimizations) * [`enableWebViewOptimizations()`](#enablewebviewoptimizations) * [`disableWebViewOptimizations()`](#disablewebviewoptimizations) * [`moveToBackground()`](#movetobackground) * [`moveToForeground()`](#movetoforeground) * [`isScreenOff()`](#isscreenoff) * [`isEnabled()`](#isenabled) * [`isActive()`](#isactive) * [`wakeUp()`](#wakeup) * [`unlock()`](#unlock) * [`addListener('appInBackground', ...)`](#addlistenerappinbackground) * [`addListener('appInForeground', ...)`](#addlistenerappinforeground) * [`removeAllListeners()`](#removealllisteners) * [Interfaces](#interfaces) * [Type Aliases](#type-aliases) ### enable() ```typescript enable() => Promise ``` -------------------- ### disable() ```typescript disable() => Promise ``` -------------------- ### getSettings() ```typescript getSettings() => Promise<{ settings: ISettings; }> ``` **Returns:** Promise<{ settings: ISettings; }> -------------------- ### setSettings(...) ```typescript setSettings(settings: Partial) => Promise ``` | Param | Type | | -------------- | ------------------------------------------------------------------------------------- | | **`settings`** | Partial<ISettings> | -------------------- ### checkForegroundPermission() ```typescript checkForegroundPermission() => Promise ``` **Returns:** Promise<PermissionStatus> -------------------- ### requestForegroundPermission() ```typescript requestForegroundPermission() => Promise ``` **Returns:** Promise<PermissionStatus> -------------------- ### checkNotificationsPermission() ```typescript checkNotificationsPermission() => Promise ``` **Returns:** Promise<PermissionStatus> -------------------- ### requestNotificationsPermission() ```typescript requestNotificationsPermission() => Promise ``` **Returns:** Promise<PermissionStatus> -------------------- ### checkBatteryOptimizations() ```typescript checkBatteryOptimizations() => Promise<{ disabled: boolean; }> ``` **Returns:** Promise<{ disabled: boolean; }> -------------------- ### requestDisableBatteryOptimizations() ```typescript requestDisableBatteryOptimizations() => Promise<{ disabled: boolean; }> ``` **Returns:** Promise<{ disabled: boolean; }> -------------------- ### enableWebViewOptimizations() ```typescript enableWebViewOptimizations() => Promise ``` -------------------- ### disableWebViewOptimizations() ```typescript disableWebViewOptimizations() => Promise ``` -------------------- ### moveToBackground() ```typescript moveToBackground() => Promise ``` -------------------- ### moveToForeground() ```typescript moveToForeground() => Promise ``` -------------------- ### isScreenOff() ```typescript isScreenOff() => Promise<{ isScreenOff: boolean; }> ``` **Returns:** Promise<{ isScreenOff: boolean; }> -------------------- ### isEnabled() ```typescript isEnabled() => Promise<{ enabled: boolean; }> ``` **Returns:** Promise<{ enabled: boolean; }> -------------------- ### isActive() ```typescript isActive() => Promise<{ activated: boolean; }> ``` **Returns:** Promise<{ activated: boolean; }> -------------------- ### wakeUp() ```typescript wakeUp() => Promise ``` -------------------- ### unlock() ```typescript unlock() => Promise ``` -------------------- ### addListener('appInBackground', ...) ```typescript addListener(eventName: 'appInBackground', listenerFunc: () => void) => Promise & PluginListenerHandle ``` | Param | Type | | ------------------ | ------------------------------ | | **`eventName`** | 'appInBackground' | | **`listenerFunc`** | () => void | **Returns:** Promise<PluginListenerHandle> & PluginListenerHandle -------------------- ### addListener('appInForeground', ...) ```typescript addListener(eventName: 'appInForeground', listenerFunc: () => void) => Promise & PluginListenerHandle ``` | Param | Type | | ------------------ | ------------------------------ | | **`eventName`** | 'appInForeground' | | **`listenerFunc`** | () => void | **Returns:** Promise<PluginListenerHandle> & PluginListenerHandle -------------------- ### removeAllListeners() ```typescript removeAllListeners() => Promise ``` -------------------- ### 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`** | 'public' \| 'private' \| 'secret' | #### PermissionStatus | Prop | Type | | ------------- | ----------------------------------------------------------- | | **`display`** | PermissionState | #### PluginListenerHandle | Prop | Type | | ------------ | ----------------------------------------- | | **`remove`** | () => Promise<void> | ### Type Aliases #### Partial Make all properties in T optional { [P in keyof T]?: T[P]; } #### PermissionState 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'