-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
39 lines (36 loc) · 1.32 KB
/
preload.js
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
const {
contextBridge
} = require("electron");
const {
getColorHexRGB,
// for more control and customized checks
DARWIN_IS_PLATFORM_PRE_CATALINA, // darwin only, undefined on other platform
darwinGetColorHexRGB, // darwin only, throw error on other platform
darwinGetScreenPermissionGranted, // darwin only, throw error on other platform
darwinRequestScreenPermissionPopup // darwin only, throw error on other platform
} = require('electron-color-picker');
const saveColorToClipboard = async () => {
if (process.platform === 'darwin' && !DARWIN_IS_PLATFORM_PRE_CATALINA) {
const isGranted = await darwinGetScreenPermissionGranted() // initial check
console.log('darwinGetScreenPermissionGranted:', isGranted)
if (!isGranted) {
await darwinRequestScreenPermissionPopup()
console.warn('no permission granted yet, try again')
return ''
}
const color = await darwinGetColorHexRGB().catch((error) => {
console.warn('[ERROR] getColor', error)
return ''
})
console.log(`getColor: ${color}`)
return color;
} else {
const color = await getColorHexRGB().catch((error) => {
console.warn('[ERROR] getColor', error)
return ''
})
console.log(`getColor: ${color}`)
return color;
}
}
contextBridge.exposeInMainWorld("getColor", saveColorToClipboard);