-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmobileInit.ts
36 lines (30 loc) · 1.06 KB
/
mobileInit.ts
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
import { App } from '@capacitor/app';
import { StatusBar, Style } from '@capacitor/status-bar';
import { Keyboard } from '@capacitor/keyboard';
import { Preferences } from '@capacitor/preferences';
export const initializeMobileApp = async () => {
try {
await StatusBar.setStyle({ style: Style.Dark });
const viewport = document.querySelector('meta[name=viewport]');
if (viewport) {
viewport.setAttribute('content',
'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no');
}
Keyboard.addListener('keyboardWillShow', () => {
document.body.classList.add('keyboard-visible');
});
Keyboard.addListener('keyboardWillHide', () => {
document.body.classList.remove('keyboard-visible');
});
App.addListener('appStateChange', async ({ isActive }) => {
if (!isActive) {
await Preferences.set({
key: 'lastActiveTime',
value: new Date().toISOString()
});
}
});
} catch (error) {
console.error('Error initializing mobile app:', error);
}
};