This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
108 lines (98 loc) · 2.82 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// This file does not need to be diagnosed. As this is the only file that runs on the Main Process
const {
app,
ipcMain,
BrowserWindow,
shell,
dialog,
Menu,
} = require('electron');
const path = require('path');
const { createMenu } = require('./index.config');
const createWindow = () => {
let mainWindow = new BrowserWindow({
title: 'SnailyCAD Manager',
height: 600,
minHeight: 600,
width: 700,
minWidth: 700,
transparent: false,
alwaysOnTop: true, // To prevent focus-loss on startup.
maximizable: true,
titleBarStyle: 'default',
icon: __dirname + '/public/icon-white-bg.png',
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
const renderer = mainWindow.webContents;
mainWindow.loadFile('./index.html');
mainWindow.on('ready-to-show', () => {
mainWindow.show();
});
// IPC Functions
ipcMain.on('focus', () => {
mainWindow.setAlwaysOnTop(false);
mainWindow.focus();
}); // Focus App on Startup (Must be called in renderer)
ipcMain.on('close', () => {
mainWindow.close();
});
ipcMain.on('minimize', () => {
mainWindow.minimize();
});
ipcMain.on('maximize', () => {
if (mainWindow.isFullScreen()) {
mainWindow.setFullScreen(true);
return;
}
mainWindow.setFullScreen(false);
mainWindow.restore();
});
ipcMain.on('url', (e, arg) => {
shell.openExternal(arg);
});
ipcMain.on('directory', (e, title) => {
dialog
.showOpenDialog(mainWindow, {
title: title,
properties: ['openDirectory'],
defaultPath: '',
})
.then((result) => {
renderer.send('dir-cb', `${result.filePaths}`);
})
.catch((err) => alert(err));
});
ipcMain.on('hard-restart', () => {
app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) });
app.exit(0);
});
ipcMain.on('devTools', () => {
mainWindow.webContents.openDevTools();
});
ipcMain.on('online', () => {
mainWindow.setOverlayIcon(
path.join(__dirname, '/public/overlay/online.png'),
'Online'
);
});
ipcMain.on('offline', () => {
mainWindow.setOverlayIcon(
path.join(__dirname, '/public/overlay/offline.png'),
'Offline'
);
});
ipcMain.on('popup', (e, args) => {
dialog.showMessageBox(mainWindow, {
type: 'warning',
buttons: ['OK'],
title: args.title,
message: args.message,
});
});
createMenu(mainWindow);
};
app.on('ready', createWindow);