-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
87 lines (75 loc) · 1.74 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
77
78
79
80
81
82
83
84
85
86
87
const {app, BrowserWindow, Tray, Menu, shell} = require('electron');
const path = require('path');
const process = require('process');
const positioner = require('electron-traywindow-positioner');
let window = null;
let tray = null;
const showWindow = () => {
positioner.position(window, tray.getBounds());
window.show();
};
const toggleWindow = () => {
if (window.isVisible()) {
return window.hide();
}
return showWindow();
};
const createTray = () => {
tray = new Tray(path.join(__dirname, 'static', 'Icon.png'));
tray.on('click', () => {
toggleWindow();
});
tray.on('right-click', () => {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Github',
type: 'normal',
click() {
shell.openExternal(
'https://github.com/florindumitru/chatgpt-desktop-tray',
);
},
},
{type: 'separator'},
{label: 'Quit', type: 'normal', role: 'quit'},
]);
tray.popUpContextMenu(contextMenu);
});
};
const createWindow = () => {
// Create the browser window.
window = new BrowserWindow({
width: 400,
height: 600,
show: false,
frame: false,
icon: path.join(__dirname, 'static', 'iconp.png'),
webPreferences: {
nodeIntegration: true,
},
});
window.menuBarVisible = false;
window.loadURL('https://chat.openai.com/chat');
window.setSkipTaskbar(true);
if (process.platform === 'darwin') {
app.dock.hide();
app.dock.setIcon(path.join(__dirname, 'static', 'iconp.png'));
}
};
app.on('ready', () => {
createWindow();
createTray();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('will-quit', () => {
// GlobalShortcut.unregisterAll();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});