Updated project structure

This commit is contained in:
Pierre HUBERT 2019-02-11 18:25:22 +01:00
parent 484813ff4d
commit 24643f0867
3 changed files with 80 additions and 51 deletions

58
MainWindow.js Normal file
View File

@ -0,0 +1,58 @@
/**
* Main Window script
*
* @author The Comunic authors
*/
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const {Tray} = require('electron');
const Config = require("./Config");
const TrayMenu = require("./TrayMenu");
let mainWindow;
let tray = null;
let page_finished_loading = false;
/**
* Show main window
*/
exports.show = function(){
//Create and show main window
mainWindow = new BrowserWindow({
icon:'icon.png',
webPreferences: {
nodeIntegration: false
},
//show: false
});
//mainWindow.maximize();
//set the url which must be open
mainWindow.loadURL(Config.access_url);
mainWindow.on('closed', () =>{
//To close the window
mainWindow = null;
});
//Create tray
tray = new Tray('./icon.png');
tray.setToolTip('Comunic');
tray.setContextMenu(TrayMenu);
console.log("Started successfully");
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.webContents.on('did-finish-load', function() {
page_finished_loading = true;
});
}

14
TrayMenu.js Normal file
View File

@ -0,0 +1,14 @@
/**
* Tray menu
*
* @author Comunic Authors
*/
const {app, Menu} = require('electron');
module.exports = Menu.buildFromTemplate([{
label : 'Close',
click: () => {
app.quit();
console.log("Closed");
}
}]);

View File

@ -1,57 +1,14 @@
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const {app, Menu, Tray} = require('electron');
/**
* Application main script
*
* @author The Comunic Authors
*/
const Config = require("./Config");
let mainWindow;
let tray = null;
let page_finished_loading = false;
const menu = Menu.buildFromTemplate([{
label : 'Close',
click: () => {
app.quit();
console.log("Closed");
}
}]);
const {app} = require('electron');
const MainWindow = require("./MainWindow");
console.log("Starting...");
app.on('ready', () => {
//Create and show main window
mainWindow = new BrowserWindow({
icon:'icon.png',
webPreferences: {
nodeIntegration: false
},
//show: false
});
//mainWindow.maximize();
//set the url which must be open
mainWindow.loadURL(Config.access_url);
mainWindow.on('closed', () =>{
//To close the window
mainWindow = null;
});
//Create tray
tray = new Tray('./icon.png');
tray.setToolTip('Comunic');
tray.setContextMenu(menu);
console.log("Started successfully");
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.webContents.on('did-finish-load', function() {
page_finished_loading = true;
});
MainWindow.show();
});