Updated project

This commit is contained in:
Pierre HUBERT 2019-02-11 18:13:40 +01:00
parent ee02924124
commit 484813ff4d
2 changed files with 59 additions and 57 deletions

14
Config.js Normal file
View File

@ -0,0 +1,14 @@
/**
* Project configuration
*/
const Config = {
/**
* URL to access to Comunic
*/
access_url: 'https://comunic.io'
}
module.exports = Config;

View File

@ -1,69 +1,57 @@
const electron = require('electron'); const electron = require('electron');
const BrowserWindow = electron.BrowserWindow; const BrowserWindow = electron.BrowserWindow;
const {app, Menu, Tray} = require('electron') const {app, Menu, Tray} = require('electron');
let mainWindow const Config = require("./Config");
let tray = null
function main(){ let mainWindow;
let tray = null;
let page_finished_loading = false;
const menu = Menu.buildFromTemplate([{
label : 'Close',
click: () => {
app.quit();
console.log("Closed");
}
}]);
console.log("Starting...");
app.on('ready', () => {
//Create and show main window
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
icon:'icon.png', icon:'icon.png',
webPreferences: { webPreferences: {
nodeIntegration: false nodeIntegration: false
}, },
show: false //show: false
}); });
mainWindow.maximize(); //mainWindow.maximize();
//createWindow --> create the window
mainWindow.loadURL('https://comunic.io'); //set the url which must be open
//set the url who must be open mainWindow.loadURL(Config.access_url);
mainWindow.on('closed', () =>{ mainWindow.on('closed', () =>{
//To close the window
mainWindow = null; mainWindow = null;
}); });
//To close the window
//Create tray
tray = new Tray('./icon.png'); tray = new Tray('./icon.png');
tray.setToolTip('Comunic'); tray.setToolTip('Comunic');
tray.setContextMenu(menu);
console.log("Started successfully");
tray.setContextMenu(menu_1);
console.log("Started succesfully");
mainWindow.once('ready-to-show', () => { mainWindow.once('ready-to-show', () => {
mainWindow.show() mainWindow.show();
}) });
};
const menu_1 = Menu.buildFromTemplate([{
label: "Ouvrir la version stable",
click: () => {
mainWindow.loadURL('https://communiquons.org');
tray.setContextMenu(menu_2)
}
},
{
label : 'Quit',
click: () => {
app.quit();
console.log("Closed");
}
}]);
const menu_2 = Menu.buildFromTemplate([{
label: "Ouvrir la nouvelle version",
click: () =>{
mainWindow.loadURL('https://comunic.io');
tray.setContextMenu(menu_1)
}
},
{
label:'Quit',
click: () => {
app.quit();
console.log("Closed");
}
}]);
console.log("Starting..."); mainWindow.webContents.on('did-finish-load', function() {
app.on('ready', main); page_finished_loading = true;
});
});