-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
60 lines (53 loc) · 1.41 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const url = require('url');
const path = require('path');
const robot = require('robotjs');
const {app, BrowserWindow, ipcMain, systemPreferences} = require('electron');
const os = require('os');
async function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
width: 360,
height: 200,
transparent: true,
hasShadow: false,
webPreferences: {
nodeIntegration: true,
},
});
let micAccess = false;
try {
if (os.platform() !== 'darwin') {
micAccess = true;
}
const status = await systemPreferences.getMediaAccessStatus('microphone');
if (status === 'not-determined') {
const success = await systemPreferences.askForMediaAccess('microphone');
micAccess = success.valueOf();
}
micAccess = status === 'granted';
} catch (error) {
console.error('Could not get microphone permission:', error.message);
}
if (micAccess) {
// and load the index.html of the app.
win.setAutoHideMenuBar(true);
win.setAlwaysOnTop(true, 'floating');
win.loadURL(
url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}),
);
}
}
ipcMain.on('clap', () => {
console.log('👏');
if (os.platform() === 'win32') {
robot.typeString(':clap:');
} else {
robot.typeString('👏');
}
robot.keyTap('enter');
});
app.whenReady().then(createWindow);