-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (60 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
/**
* The main Electron process that handles the browser window app.
* @author Justin Hartman <code@justhart.com>
* @copyright Copyright (c) 2023 Justin Hartman. All rights reserved.
* @license MIT
* @link https://justhart.com Justin Hartman
*/
const { app, BrowserWindow } = require('electron');
/**
* Create the main window.
* @returns {Electron.BrowserWindow}
* @constructor
* @see https://www.electronjs.org/docs/latest/api/browser-window
*/
const createWindow = () => {
// Create the browser window.
const win = new BrowserWindow({
width: 1024,
height: 768,
useContentSize: true,
title: 'MacChatGPT',
webPreferences: {
contextIsolation: true,
enablePreferredSizeMode: true,
nodeIntegration: false
}
});
/**
* Load the OpenAI chat page.
* @param {string} url - The URL to load.
* @param {Electron.LoadURLOptions} options - Options for loading the URL.
* @returns {void}
* @see https://www.electronjs.org/docs/latest/api/browser-window#winloadurlurl-options
*/
win.loadURL('https://chat.openai.com/chat');
};
/**
* When Electron has finished initialisation and is ready to create browser windows.
* Some APIs can only be used after this event occurs.
* @returns {Promise<void>}
* @see https://www.electronjs.org/docs/latest/api/app#event-ready
*/
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
/**
* Quit when all windows are closed, except on macOS. There, it's common for applications
* and their menu bar to stay active until the user quits explicitly with `command + Q`.
* @see https://www.electronjs.org/docs/latest/api/app#event-window-all-closed
*/
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});