From 24643f086731fc1ca6cf3e464b5d9a01a8cb450a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 11 Feb 2019 18:25:22 +0100 Subject: [PATCH] Updated project structure --- MainWindow.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ TrayMenu.js | 14 ++++++++++++ index.js | 59 +++++++-------------------------------------------- 3 files changed, 80 insertions(+), 51 deletions(-) create mode 100644 MainWindow.js create mode 100644 TrayMenu.js diff --git a/MainWindow.js b/MainWindow.js new file mode 100644 index 0000000..55f9785 --- /dev/null +++ b/MainWindow.js @@ -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; + }); +} \ No newline at end of file diff --git a/TrayMenu.js b/TrayMenu.js new file mode 100644 index 0000000..0004df2 --- /dev/null +++ b/TrayMenu.js @@ -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"); + } +}]); \ No newline at end of file diff --git a/index.js b/index.js index cdeaaf3..acf8698 100644 --- a/index.js +++ b/index.js @@ -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(); });