-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
125 lines (106 loc) · 3.41 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
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
// const windowStateKeeper = require('electron-window-state');
const Menu = electron.Menu;
const Tray = electron.Tray;
const Docker = require('dockerode');
var socket = '/var/run/docker.sock';
var docker = new Docker({ socketPath: socket });
// browser-window creates a native window
var mainWindow = null;
const process = require('process');
const path = process.argv[2] == 'dev' ? '/src/app' : '';
if(path) {
require('electron-reload')(__dirname, {
electron: require('electron')
});
}
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
const createWindow = function () {
// Initialize the window to our specified dimensions
mainWindow = new BrowserWindow({
// frame: false,
// enableLargerThanScreen: true,
// x: 0,
// y: 0,
title: '',
titleBarStyle: 'hidden',
// icon: __dirname + '/src/assets/camera-icon.png'
icon: __dirname + path + '/dist/assets/docker-sm.png'
});
// Tell Electron where to load the entry point from
mainWindow.loadURL('file://' + __dirname + path + '/index.html');
// console.log('dirname', __dirname);
const screenElectron = electron.screen;
const allScreens = screenElectron.getAllDisplays();
var x = 0;
var y = 0;
var width = 0;
var height = 0;
// Select biggest screen monitor to open app
for (var screen in allScreens) {
if (allScreens[screen].workArea.width > width) {
x = allScreens[screen].bounds.x;
y = allScreens[screen].bounds.y;
width = allScreens[screen].bounds.width;
height = allScreens[screen].bounds.height;
}
}
// Set Screen Position
mainWindow.setPosition(x, y, true);
// Set Screen Size
mainWindow.setSize(width, height, true);
// var mainWindowState = windowStateKeeper({
// defaultWidth: width,
// defaultHeight: height
// });
// App icon tray
appIcon = new Tray(__dirname + path + '/dist/assets/docker-xs.png');
var contextMenu = Menu.buildFromTemplate([
{
label: 'Abrir',
click: mainWindow.show()
},
{
label: 'Fechar',
click: function () {
app._events['will-quit']();
app.quit();
}
}
]);
appIcon.setToolTip('BrScan <NomeDoApp>');
appIcon.setContextMenu(contextMenu);
// App menu
mainWindow.setMenuBarVisibility(false);
// Open the DevTools.
if (path) {
mainWindow.webContents.openDevTools();
}
// mainWindowState.manage(mainWindow);
// Clear out the main window when the app is closed
mainWindow.on('closed', function () {
app._events['will-quit']();
app.quit();
mainWindow = null
});
app.docker = docker;
};
app.on('ready', createWindow);
app.on('show', function (event) {
mainWindow.setHighlightMode('always');
});
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
});