From fa720d3b289b85f59b1b55ae7dcd6c42a335675c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 5 Nov 2015 08:42:52 +0000 Subject: [PATCH] Externalised audio playing --- scripts/build-js.sh | 3 ++- src/audio.html | 2 +- src/js/audio-controller.js | 40 ++++++++++++++++++++++++++++ src/js/{audio.js => audio-player.js} | 0 src/main.js | 17 +++--------- 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 src/js/audio-controller.js rename src/js/{audio.js => audio-player.js} (100%) diff --git a/scripts/build-js.sh b/scripts/build-js.sh index fc4458b..859a2b6 100644 --- a/scripts/build-js.sh +++ b/scripts/build-js.sh @@ -14,4 +14,5 @@ echo ">> Building Main JS..." uglifyjs src/main.js --compress --screw-ie8 --define --stats --keep-fnames -o build/main.js echo ">> Building Audio Controller..." -uglifyjs src/js/audio.js --compress --screw-ie8 --define --stats --keep-fnames -o build/js/audio.js +uglifyjs src/js/audio-controller.js --compress --screw-ie8 --define --stats --keep-fnames -o build/js/audio-controller.js +uglifyjs src/js/audio-player.js --compress --screw-ie8 --define --stats --keep-fnames -o build/js/audio-player.js diff --git a/src/audio.html b/src/audio.html index b221ae9..b9a8390 100644 --- a/src/audio.html +++ b/src/audio.html @@ -4,6 +4,6 @@ Audio Controller Window - + diff --git a/src/js/audio-controller.js b/src/js/audio-controller.js new file mode 100644 index 0000000..83e9fe7 --- /dev/null +++ b/src/js/audio-controller.js @@ -0,0 +1,40 @@ +var BrowserWindow = require('browser-window'); +var ipc = require('ipc'); + +var playerWindow; + +function startWindow() { + playerWindow = new BrowserWindow({ + width: 0, + height: 0, + show: false, + frame: false, + transparent: true, + 'skip-taskbar': true + }); + playerWindow.loadUrl('file://' + __dirname + '/audio.html'); + buildEvents(); + return playerWindow; +} + +function buildEvents() { + playerWindow.on('closed', function () { delete playerWindow; }); +} + +function getWindow() { + return playerWindow; +} + +function play() { + console.log("CLICK!"); +} + +ipc.on('play', function () { + play(); +}); + +module.exports = { + getWindow: getWindow, + startWindow: startWindow, + play: play +}; \ No newline at end of file diff --git a/src/js/audio.js b/src/js/audio-player.js similarity index 100% rename from src/js/audio.js rename to src/js/audio-player.js diff --git a/src/main.js b/src/main.js index 512e94e..289d710 100644 --- a/src/main.js +++ b/src/main.js @@ -6,13 +6,14 @@ var fs = require('fs'); var Tray = require('tray'); var ipc = require('ipc'); +var AudioController = require('./js/audio-controller'); + require('crash-reporter').start(); // Start crash reporter // Creating menu var menu = new Menu(); Menu.setApplicationMenu(menu); var mainWindow = null; -var audioController = null; var icon = null; const INDEX_PAGE = 'file://' + __dirname + '/index.html'; @@ -41,20 +42,10 @@ app.on('ready', function () { mainWindow.toggleDevTools(); mainWindow.on('closed', function() { delete mainWindow; - audioController.close(); + AudioController.getWindow().close(); }); - audioController = new BrowserWindow({ - width: 0, - height: 0, - show: false, - frame: false, - transparent: true, - 'skip-taskbar': true, - - }); - audioController.loadUrl('file://' + __dirname + '/audio.html'); - audioController.on('closed', function () { delete audioController; }); + AudioController.startWindow(); }); ipc.on('hide', function () {