mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:44:21 +02:00
Merge pull request #54 from huffman/console
Add support for starting/stopping interface
This commit is contained in:
commit
1ac40e4e89
6 changed files with 208 additions and 9 deletions
|
@ -1,12 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello World!</title>
|
||||
<title>Console</title>
|
||||
<script src="index.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World!</h1>
|
||||
We are using node <script>document.write(process.versions.node)</script>,
|
||||
Chrome <script>document.write(process.versions.chrome)</script>,
|
||||
and Electron <script>document.write(process.versions.electron)</script>.
|
||||
<body onload="ready()">
|
||||
|
||||
<h1>Console</h1>
|
||||
|
||||
<h2>Interface</h2>
|
||||
<div id="process-status">
|
||||
<div id="process-interface">
|
||||
<span class="name">Interface</span>
|
||||
<span class="status">unknown</span>
|
||||
<button class="power-on">Turn On</button>
|
||||
<button class="power-off">Turn Off</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Home</h2>
|
||||
<div id="server">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Node Version: <script>document.write(process.versions.node)</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
31
console/index.js
Executable file
31
console/index.js
Executable file
|
@ -0,0 +1,31 @@
|
|||
ready = function() {
|
||||
window.$ = require('./jquery');
|
||||
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
|
||||
function onProcessUpdate(event, arg) {
|
||||
// Update interface
|
||||
console.log("update", event, arg);
|
||||
var state = arg.interface.state;
|
||||
$('#process-interface .status').text(state);
|
||||
var on = state != 'stopped';
|
||||
if (on) {
|
||||
$('#process-interface .power-on').hide();
|
||||
$('#process-interface .power-off').show();
|
||||
} else {
|
||||
$('#process-interface .power-on').show();
|
||||
$('#process-interface .power-off').hide();
|
||||
}
|
||||
}
|
||||
|
||||
$('#process-interface .power-on').click(function() {
|
||||
ipcRenderer.send('start-process', { name: 'interface' });
|
||||
});
|
||||
$('#process-interface .power-off').click(function() {
|
||||
ipcRenderer.send('stop-process', { name: 'interface' });
|
||||
});
|
||||
|
||||
ipcRenderer.on('process-update', onProcessUpdate);
|
||||
|
||||
ipcRenderer.send('update');
|
||||
};
|
5
console/jquery.js
vendored
Executable file
5
console/jquery.js
vendored
Executable file
File diff suppressed because one or more lines are too long
|
@ -1,13 +1,22 @@
|
|||
var app = require('app'); // Module to control application life.
|
||||
'use strict'
|
||||
|
||||
var electron = require('electron');
|
||||
var app = electron.app; // Module to control application life.
|
||||
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
||||
var Menu = require('menu');
|
||||
var Tray = require('tray');
|
||||
|
||||
var hfprocess = require('./modules/hf-process.js');
|
||||
var Process = hfprocess.Process;
|
||||
var ProcessGroup = hfprocess.ProcessGroup;
|
||||
|
||||
const ipcMain = electron.ipcMain;
|
||||
|
||||
// Report crashes to our server.
|
||||
require('crash-reporter').start();
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
// be closed automatically when the JavaScript object is garggbage collected.
|
||||
var mainWindow = null;
|
||||
var appIcon = null;
|
||||
var TRAY_ICON = 'resources/tray-icon.png';
|
||||
|
@ -51,4 +60,45 @@ app.on('ready', function() {
|
|||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
var pInterface = new Process('interface', 'C:\\Interface\\interface.exe');
|
||||
|
||||
var domainServerPath = 'C:\\Users\\Ryan\\AppData\\Local\\High Fidelity\\Stack Manager\\domain-server.exe';
|
||||
var acPath = 'C:\\Users\\Ryan\\AppData\\Local\\High Fidelity\\Stack Manager\\assignment-client.exe';
|
||||
|
||||
var homeServer = new ProcessGroup('home', [
|
||||
new Process('Domain Server', domainServerPath),
|
||||
new Process('AC - Audio', acPath, ['-t0']),
|
||||
new Process('AC - Avatar', acPath, ['-t1']),
|
||||
new Process('AC - Asset', acPath, ['-t3']),
|
||||
new Process('AC - Messages', acPath, ['-t4']),
|
||||
new Process('AC - Entity', acPath, ['-t6'])
|
||||
]);
|
||||
homeServer.start();
|
||||
|
||||
var processes = {
|
||||
interface: pInterface,
|
||||
home: homeServer
|
||||
};
|
||||
|
||||
function sendProcessUpdate() {
|
||||
console.log("Sending process update to web view");
|
||||
mainWindow.webContents.send('process-update', processes);
|
||||
};
|
||||
|
||||
pInterface.on('state-update', sendProcessUpdate);
|
||||
|
||||
ipcMain.on('start-process', function(event, arg) {
|
||||
pInterface.start();
|
||||
sendProcessUpdate();
|
||||
});
|
||||
ipcMain.on('stop-process', function(event, arg) {
|
||||
pInterface.stop();
|
||||
sendProcessUpdate();
|
||||
});
|
||||
ipcMain.on('update', function(event, arg) {
|
||||
sendProcessUpdate();
|
||||
});
|
||||
|
||||
sendProcessUpdate();
|
||||
});
|
||||
|
|
96
console/modules/hf-process.js
Executable file
96
console/modules/hf-process.js
Executable file
|
@ -0,0 +1,96 @@
|
|||
'use strict'
|
||||
|
||||
var extend = require('extend');
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var childProcess = require('child_process');
|
||||
|
||||
const ProcessStates = {
|
||||
STOPPED: 'stopped',
|
||||
STARTED: 'started',
|
||||
STOPPING: 'stopping'
|
||||
};
|
||||
|
||||
function ProcessGroup(name, processes) {
|
||||
this.name = name;
|
||||
this.processes = processes;
|
||||
};
|
||||
util.inherits(ProcessGroup, events.EventEmitter);
|
||||
ProcessGroup.prototype = extend(ProcessGroup.prototype, {
|
||||
addProcess: function(process) {
|
||||
this.processes.push(process);
|
||||
},
|
||||
start: function() {
|
||||
for (let process of this.processes) {
|
||||
process.start();
|
||||
}
|
||||
},
|
||||
stop: function() {
|
||||
for (let process of this.processes) {
|
||||
process.stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var ID = 0;
|
||||
function Process(name, command, commandArgs) {
|
||||
events.EventEmitter.call(this);
|
||||
|
||||
this.id = ++ID;
|
||||
this.name = name;
|
||||
this.command = command;
|
||||
this.commandArgs = commandArgs ? commandArgs : [];
|
||||
this.child = null;
|
||||
|
||||
this.state = ProcessStates.STOPPED;
|
||||
};
|
||||
util.inherits(Process, events.EventEmitter);
|
||||
Process.prototype = extend(Process.prototype, {
|
||||
start: function() {
|
||||
if (this.state != ProcessStates.STOPPED) {
|
||||
console.warn("Can't start process that is not stopped.");
|
||||
return;
|
||||
}
|
||||
console.log("Starting " + this.command);
|
||||
try {
|
||||
this.child = childProcess.spawn(this.command, this.commandArgs, {
|
||||
detached: false
|
||||
});
|
||||
//console.log("started ", this.child);
|
||||
this.child.on('error', this.onChildStartError.bind(this));
|
||||
this.child.on('close', this.onChildClose.bind(this));
|
||||
this.state = ProcessStates.STARTED;
|
||||
console.log("Child process started");
|
||||
} catch (e) {
|
||||
console.log("Got error starting child process for " + this.name, e);
|
||||
this.child = null;
|
||||
this.state = ProcessStates.STOPPED;
|
||||
}
|
||||
|
||||
this.emit('state-update');
|
||||
},
|
||||
stop: function() {
|
||||
if (this.state != ProcessStates.STARTED) {
|
||||
console.warn("Can't stop process that is not started.");
|
||||
return;
|
||||
}
|
||||
this.child.kill();
|
||||
this.state = ProcessStates.STOPPING;
|
||||
},
|
||||
|
||||
// Events
|
||||
onChildStartError: function(error) {
|
||||
console.log("Child process error ", error);
|
||||
this.state = ProcessStates.STOPPED;
|
||||
this.emit('state-update');
|
||||
},
|
||||
onChildClose: function(code) {
|
||||
console.log("Child process closed with code ", code);
|
||||
this.state = ProcessStates.STOPPED;
|
||||
this.emit('state-update');
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.Process = Process;
|
||||
module.exports.ProcessGroup = ProcessGroup;
|
||||
module.exports.ProcessStates = ProcessStates;
|
0
console/package.json
Normal file → Executable file
0
console/package.json
Normal file → Executable file
Loading…
Reference in a new issue