-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
144 lines (125 loc) · 3.75 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const path = require('path');
const {
app,
shell,
BrowserWindow,
ipcMain,
Tray,
Menu,
nativeImage,
} = require('electron');
//test config ----------------------------
const debug = process.argv.includes("debug");
let tray = ""; //musi byc globalne?
const myApp = {
mainWindow: false,
contextMenu: false,
windowOpen: true,
toggleWindow() {
if (this.windowOpen) {
this.mainWindow.minimize();
} else {
this.mainWindow.restore();
}
},
makeCommunicationWithRender() {
ipcMain.handle("saveScreenShot", async (event, args) => {
const img = await this.makeScreenShoot();
return img;
})
},
createWindow() {
this.mainWindow = new BrowserWindow({
width: 1500,
height: 1000,
resizable: true,
icon: path.join(__dirname, 'images/icon.png'),
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false
}
});
this.mainWindow.on("minimize", e => {
this.windowOpen = false;
})
this.mainWindow.on("restore", e => {
this.windowOpen = true;
})
this.mainWindow.loadFile('index.html');
if (!debug) {
Menu.setApplicationMenu(null);
}
// this.mainWindow.show();
},
createContextMenu() {
this.contextMenu = Menu.buildFromTemplate([
{
label: 'Author',
role: 'help',
click: () => {
shell.openExternal('http://domanart.pl/portfolio');
}
},
{
label: 'Help',
role: 'help',
click: () => {
let win = new BrowserWindow({
width: 800,
height: 550,
alwaysOnTop: true,
title: "PresentationDrawer help",
icon: path.join(__dirname, 'images/icon.ico')
});
win.setMenu(null);
win.on('closed', () => {
win = null
});
win.loadFile('help.html');
}
},
{
label: 'Quit program',
role: 'close',
click: () => {
this.mainWindow.close()
}
}
]);
},
createTrayIcon() {
const imgPath = path.join(__dirname, 'images/icon.png');
//const nimage = nativeImage.createFromPath(imgPath);
tray = new Tray(imgPath);
tray.setToolTip('PresentationDrawer');
tray.on('click', () => {
this.windowOpen = !this.windowOpen;
this.toggleWindow(this.windowOpen);
});
tray.setContextMenu(this.contextMenu);
},
init() {
//ubuntu fix
//app.commandLine.appendSwitch('disable-transparent-visuals');
//app.commandLine.appendSwitch('disable-gpu');
//1
//app.disableHardwareAcceleration()
app.on('ready', () => {
//ubuntu fix for black window1
setTimeout(() => {
this.createWindow();
this.makeCommunicationWithRender();
this.createContextMenu();
this.createTrayIcon();
}, 1000);
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) this.createWindow()
});
}
};
myApp.init();