forked from CodeForPoznan/alinka-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
92 lines (83 loc) · 2.01 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
88
89
90
91
92
const { app, BrowserWindow, ipcMain, Menu } = require("electron");
const DecisionCreate = require("./doc/decision");
const path = require("path");
// Specifies the enviroment variable
const inDevelopmentMode = process.env.MODE === "dev";
/***************/
/* Main Window */
/***************/
app.on("ready", () => {
// Configure the main window
let mainWindow = new BrowserWindow({
width: 800,
height: 600,
icon: path.join(__dirname, "assets/Alinka-logo.png"),
webPreferences: {
backgroundThrottling: false
}
});
// Load the apropriate file depending on env mode
mainWindow.loadURL(
inDevelopmentMode
? `http://localhost:9000`
: `file://${__dirname}/build/index.html`
);
// Build Menu from template and insert it
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
// Display develooper tools in dev mode
if (inDevelopmentMode) {
mainWindow.webContents.openDevTools();
}
// Quit app when closed
mainWindow.on("closed", () => {
app.quit();
});
});
/********/
/* Menu */
/********/
const mainMenuTemplate = [
{
label: "File",
submenu: [
{
label: "Quit",
accelerator: process.platform == "darwin" ? "Command+Q" : "Ctrl+Q",
click() {
app.quit();
}
}
]
}
];
// If mac add empty object to menu
if (process.platform === "darwin") {
mainMenuTemplate.unshift({});
}
// Add developer tools item in dev mode
if (inDevelopmentMode) {
mainMenuTemplate.push({
label: "Developer Tools",
submenu: [
{
label: "Toggle DevTools",
accelerator: process.platform == "darwin" ? "Command+I" : "Ctrl+I",
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
}
},
{
role: "reload"
}
]
});
}
/*********************/
/* Document Renderer */
/*********************/
ipcMain.on("print:value", (event, value) => {
var doc = new DecisionCreate(value);
doc.create();
doc.save();
});