This repository has been archived by the owner on Mar 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
87 lines (72 loc) · 1.83 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { app, BrowserWindow, globalShortcut, ipcMain, clipboard, Menu, Tray } = require('electron')
const path = require('path')
const AutoLaunch = require('auto-launch');
const isDev = require('electron-is-dev');
var ks = require('node-key-sender')
// Enable reload
require('electron-reload')(__dirname);
// Lets remove application menu
Menu.setApplicationMenu(false);
var iconpath = path.join(__dirname, '/src/assets/icon.ico');
let tray = null;
function createWindow () {
const win = new BrowserWindow({
width: 400,
height: 279,
frame: false,
webPreferences: {
nodeIntegration: true
},
resizable: false,
icon: iconpath
})
if (isDev) {
//win.webContents.openDevTools()
}
win.loadFile('src/app/index.html')
win.hide();
// Add to tray
tray = new Tray(iconpath)
const contextMenu = Menu.buildFromTemplate([
{ label: 'Quit', click: function(){
app.isQuiting = true;
app.quit();
}
}
])
tray.setToolTip('Unipen')
tray.setContextMenu(contextMenu)
// Register short codes
globalShortcut.register ("CommandOrControl+Alt+P", () => { win.show (); })
// Event handler
ipcMain.on('send', (event, arg) => {
const text = arg
clipboard.writeText(text)
ks.sendCombination(['control', 'v'])
win.minimize()
win.hide()
});
ipcMain.on('dismiss', () => {
win.minimize()
win.hide()
});
}
app.whenReady().then(createWindow)
// Auto launch
let autoLaunch = new AutoLaunch({
name: 'Unipen',
path: app.getPath('exe'),
});
autoLaunch.isEnabled().then((isEnabled) => {
if (!isEnabled) autoLaunch.enable();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
//app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})