From a9205daf7efae4160b9f9a887f7e69ca53d84d55 Mon Sep 17 00:00:00 2001 From: WEBER Antoine Date: Sun, 11 Oct 2015 22:13:49 +0200 Subject: [PATCH] =?UTF-8?q?mode=20application=20clusteris=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/custom-tray-menu.js | 10 ++--- js/startup.js | 73 ++++++++++++++----------------------- views/custom-tray-menu.html | 8 +++- 3 files changed, 39 insertions(+), 52 deletions(-) diff --git a/js/custom-tray-menu.js b/js/custom-tray-menu.js index a19a910..13e096c 100644 --- a/js/custom-tray-menu.js +++ b/js/custom-tray-menu.js @@ -26,7 +26,6 @@ class CustomTrayMenu { this.tray.remove(); this.tray = null; this.trayMenu.close(); - process.emit('log', 'Remove tray icon'); } _initTray() { @@ -37,7 +36,6 @@ class CustomTrayMenu { tooltip: window.document.title, iconsAreTemplates: false }); - process.emit('log', 'Add tray icon'); } _initMenuWindow() { @@ -57,13 +55,13 @@ class CustomTrayMenu { // add class to new window's body to apply platform specific css this.trayMenu.on('document-end', function() { this.trayMenu.window.document.body.className += ' ' + process.platform; - process.emit('log', "Adding class " + process.platform); + //console.log("Adding class " + process.platform); }.bind(this)); this.trayMenu.on('blur', function () { this.trayMenu.hide(); this.shown = false; - process.emit('log', 'Hide custom menu'); + //console.log('Hide custom menu'); }.bind(this)); } @@ -81,13 +79,13 @@ class CustomTrayMenu { this.trayMenu.show(); //this.trayMenu.focus(); this.shown = true; - process.emit('log', 'Show custom menu'); + //console.log('Show custom menu'); //} } // calculdate position for window to appear translate(pos) { - process.emit('log', "Click position: " + util.inspect(pos)); + //console.log("Click position: " + util.inspect(pos)); if (process.platform == 'darwin') { pos.x -= Math.floor(this.trayMenu.width / 2 - this.iconWidth); } else { diff --git a/js/startup.js b/js/startup.js index 0919ca6..d1dd525 100644 --- a/js/startup.js +++ b/js/startup.js @@ -1,53 +1,36 @@ -"use strict"; -var gui = require('nw.gui'); -var CustomTrayMenu = require('./js/custom-tray-menu'); -var win = gui.Window.get(); -global.main_win = win; -// Extend application menu for Mac OS -if (process.platform == "darwin") { - var menu = new gui.Menu({type: "menubar"}); - menu.createMacBuiltin && menu.createMacBuiltin(window.document.title); - win.menu = menu; -} + //sur le master on cree l'interface + "use strict"; + var gui = require('nw.gui'); + var CustomTrayMenu = require('./js/custom-tray-menu'); + var win = gui.Window.get(); + global.main_win = win; -var $ = function (selector) { - return document.querySelector(selector); -} + // Extend application menu for Mac OS + if (process.platform == "darwin") { + var menu = new gui.Menu({type: "menubar"}); + menu.createMacBuiltin && menu.createMacBuiltin(window.document.title); + win.menu = menu; + } -var customTray; + var $ = function (selector) { + return document.querySelector(selector); + } -customTray = new CustomTrayMenu('./views/custom-tray-menu.html', 'public/icon.png', { - width: 200, - height: 150 -}); + var customTray; -// for nw-notify frameless windows -win.on('close', function() { - gui.App.quit(); -}); + customTray = new CustomTrayMenu('views/custom-tray-menu.html', 'public/icon.png', { + width: 200, + height: 180 + }); -win.on('click',function(t){ - console.log(t); -}); + win.hide(); -// bring window to front when open via terminal -//win.focus(); -win.hide(); + //lancement du serveur + var child_process = require('child_process'); + global.main_server = child_process.fork('./js/clustering.js'); -var writeLog = function (msg, type) { - console.log(msg); -}; - -process.on('log', function (message) { - writeLog(message); -}); - -//on lance l'application en commencant par la creation des cluster -//require('./clustering'); -var child_process = require('child_process'); - -// exec: spawns a shell. -child_process.exec('node js/clustering.js', function(error, stdout, stderr){ - console.log(stdout); -}); + //on tue le serveur quand on quite l'interface + process.on('exit', function (exitCode) { + child_process.kill(); + }); diff --git a/views/custom-tray-menu.html b/views/custom-tray-menu.html index 8dfe426..044fed2 100644 --- a/views/custom-tray-menu.html +++ b/views/custom-tray-menu.html @@ -11,6 +11,12 @@ console.log(stdout); }); } + + function proper_quit(){ + gui.App.closeAllWindows(); + global.main_server.kill(); + gui.App.quit(); + }