forked from ionic-team/capacitor-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.ts
More file actions
47 lines (38 loc) · 1.08 KB
/
web.ts
File metadata and controls
47 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { WebPlugin } from '@capacitor/core';
import type { AppInfo, AppPlugin, AppLaunchUrl, AppState } from './definitions';
export class AppWeb extends WebPlugin implements AppPlugin {
constructor() {
super();
document.addEventListener(
'visibilitychange',
this.handleVisibilityChange,
false,
);
}
exitApp(): Promise<void> {
throw this.unimplemented('Not implemented on web.');
}
async getInfo(): Promise<AppInfo> {
throw this.unimplemented('Not implemented on web.');
}
async getLaunchUrl(): Promise<AppLaunchUrl> {
return { url: '' };
}
async getState(): Promise<AppState> {
return { isActive: document.hidden !== true };
}
async minimizeApp(): Promise<void> {
throw this.unimplemented('Not implemented on web.');
}
private handleVisibilityChange = () => {
const data = {
isActive: document.hidden !== true,
};
this.notifyListeners('appStateChange', data);
if (document.hidden) {
this.notifyListeners('pause', null);
} else {
this.notifyListeners('resume', null);
}
};
}