-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathcapacitor.mjs
46 lines (43 loc) · 1.16 KB
/
capacitor.mjs
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
import { NodeJS } from 'capacitor-nodejs'
import { KeepAwake } from '@capacitor-community/keep-awake';
import { App } from '@capacitor/app';
import { NativeFileDownloader } from '@eoscz/capacitor-plugin-native-file-downloader'
import { Keyboard } from '@capacitor/keyboard';
import { Share } from '@capacitor/share';
import { Clipboard } from '@capacitor/clipboard';
const requestPermission = async perm => {
const permissions = cordova.plugins.permissions
const has = await new Promise((resolve => {
permissions.hasPermission(permissions[perm], status => {
resolve(!!status.hasPermission)
}, () => {
resolve(false)
})
}))
if(!has) {
const got = await new Promise((resolve => {
permissions.requestPermission(permissions[perm], status => {
resolve(!!status.hasPermission)
}, () => {
resolve(false)
})
}))
return got
}
return has
}
const clipboard = async text => {
if(typeof text === 'string') {
await Clipboard.write({string: text})
} else {
const { type, value } = await Clipboard.read()
return {type, value}
}
}
window.capacitor = {
NodeJS, App, Share,
KeepAwake, Keyboard,
NativeFileDownloader,
requestPermission,
clipboard
}