-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (66 loc) · 2.15 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const { app, BrowserWindow, Tray, Menu } = require('electron');
const path = require('path');
const fs=require('fs/promises');
const {autoUpdater}=require('electron-updater');
let autoLaunch=require('auto-launch')
let tray = null;
let mainWindow=null;
function createWindow() {
mainWindow = new BrowserWindow({
width: 140,
height: 145,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
frame: false,
transparent: true,
autoHideMenuBar: true
});
mainWindow.loadFile('index.html');
mainWindow.setAlwaysOnTop(true, 'floating')
mainWindow.setSkipTaskbar(true)
mainWindow.setResizable(false)
if(process.platform!=="darwin") {
autoUpdater.checkForUpdates();
}
return mainWindow;
}
async function createTray(win) {
const switchMrEgg = (egg) => () => {
win.show();
win.webContents.send('switch-mregg', egg);
}
const iconPath = path.join(__dirname, './imgs/tray.png');
tray = Tray(iconPath);
let trayMenu = [];
const files=await fs.readdir(path.join(__dirname,'./imgs/'))
files.forEach(file => {
if(file !== "tray.png") {
trayMenu.push({label: file.substring(0,file.lastIndexOf('.')), click: switchMrEgg(file.substring(0,file.lastIndexOf('.')))})
}
})
let mreggAutoLaunch=new autoLaunch({name:'mreggthepet'})
trayMenu.push({label:'Auto Launch',type:'checkbox',checked:await mreggAutoLaunch.isEnabled(),click:(menuItem)=>{
if(menuItem.checked){
mreggAutoLaunch.enable()
}
else{
mreggAutoLaunch.disable()
}
}})
trayMenu.push({label: 'Hide', click: () => win.hide()});
trayMenu.push({label: 'Exit', click: () => app.quit()});
const contextMenu = Menu.buildFromTemplate(trayMenu);
tray.setToolTip("MrEggThePet")
tray.setContextMenu(contextMenu);
tray.on('click', () => win.show())
return tray;
}
app.on('ready', () => {
const win = createWindow();
createTray(win);
})
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall();
});
app.on('window-all-closed', () => app.quit())