1 | import type { PluginRegistry } from './legacy/legacy-definitions';
|
2 | import type { CapacitorException } from './util';
|
3 | export interface CapacitorGlobal {
|
4 | /**
|
5 | * The Exception class used when generating plugin Exceptions
|
6 | * from bridge calls.
|
7 | */
|
8 | Exception: typeof CapacitorException;
|
9 | /**
|
10 | * Utility function to convert a file path into a usable src depending
|
11 | * on the native WebView implementation value and environment.
|
12 | */
|
13 | convertFileSrc: (filePath: string) => string;
|
14 | /**
|
15 | * Gets the name of the platform, such as `android`, `ios`, or `web`.
|
16 | */
|
17 | getPlatform: () => string;
|
18 | /**
|
19 | * Boolean if the platform is native or not. `android` and `ios`
|
20 | * would return `true`, otherwise `false`.
|
21 | */
|
22 | isNativePlatform: () => boolean;
|
23 | /**
|
24 | * Used to check if a platform is registered and available.
|
25 | */
|
26 | isPluginAvailable: (name: string) => boolean;
|
27 | registerPlugin: RegisterPlugin;
|
28 | /**
|
29 | * Add a listener for a plugin event.
|
30 | */
|
31 | addListener?: (pluginName: string, eventName: string, callback: PluginCallback) => PluginListenerHandle;
|
32 | /**
|
33 | * Remove a listener to a plugin event.
|
34 | */
|
35 | removeListener?: (pluginName: string, callbackId: string, eventName: string, callback: PluginCallback) => void;
|
36 | DEBUG?: boolean;
|
37 | isLoggingEnabled?: boolean;
|
38 | /**
|
39 | * @deprecated Plugins should be imported instead. Deprecated in
|
40 | * v3 and Capacitor.Plugins property definition will not be exported in v4.
|
41 | */
|
42 | Plugins: PluginRegistry;
|
43 | /**
|
44 | * Called when a plugin method is not available. Defaults to console
|
45 | * logging a warning. Provided for backwards compatibility.
|
46 | * @deprecated Deprecated in v3, will be removed from v4
|
47 | */
|
48 | pluginMethodNoop: (target: any, key: PropertyKey, pluginName: string) => Promise<never>;
|
49 | /**
|
50 | * @deprecated Use `isNativePlatform()` instead
|
51 | */
|
52 | isNative?: boolean;
|
53 | /**
|
54 | * @deprecated Use `getPlatform()` instead
|
55 | */
|
56 | platform?: string;
|
57 | }
|
58 | /**
|
59 | * Register plugin implementations with Capacitor.
|
60 | *
|
61 | * This function will create and register an instance that contains the
|
62 | * implementations of the plugin.
|
63 | *
|
64 | * Each plugin has multiple implementations, one per platform. Each
|
65 | * implementation must adhere to a common interface to ensure client code
|
66 | * behaves consistently across each platform.
|
67 | *
|
68 | * @param pluginName The unique CamelCase name of this plugin.
|
69 | * @param implementations The map of plugin implementations.
|
70 | */
|
71 | export type RegisterPlugin = <T>(pluginName: string, implementations?: Readonly<PluginImplementations>) => T;
|
72 | /**
|
73 | * A map of plugin implementations.
|
74 | *
|
75 | * Each key should be the lowercased platform name as recognized by Capacitor,
|
76 | * e.g. 'android', 'ios', and 'web'. Each value must be an instance of a plugin
|
77 | * implementation for the respective platform.
|
78 | */
|
79 | export type PluginImplementations = {
|
80 | [platform: string]: (() => Promise<any>) | any;
|
81 | };
|
82 | export interface Plugin {
|
83 | addListener(eventName: string, listenerFunc: (...args: any[]) => any): Promise<PluginListenerHandle>;
|
84 | removeAllListeners(): Promise<void>;
|
85 | }
|
86 | export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';
|
87 | export interface PluginListenerHandle {
|
88 | remove: () => Promise<void>;
|
89 | }
|
90 | export interface PluginResultData {
|
91 | [key: string]: any;
|
92 | }
|
93 | export interface PluginResultError {
|
94 | message: string;
|
95 | }
|
96 | export type PluginCallback = (data: PluginResultData, error?: PluginResultError) => void;
|