Revert "Restructuring and refactoring"

This reverts commit 766278abf9e1e96cf173a50665e2a7bde7d24460.
This commit is contained in:
Brad Metcalf 2015-04-02 23:55:06 -05:00
commit b49c49acf2

View file

@ -1,21 +1,21 @@
var phpwebkit = { var gui = require('nw.gui');
var win = gui.Window.get();
var http = require('http');
var fs = require('fs');
var php = require('../lib/bridge');
var express = require('express');
var app = express();
var os = require('os');
var os = os.platform();
runApp: function(){ process.on('uncaughtException', function(err){
changeState('<strong>'+err+'</strong>', '#CD0000');
});
var gui = require('nw.gui'); win.title = gui.App.manifest.name;
var win = gui.Window.get();
var os = require('os');
var os = os.platform();
var pw = this;
process.on('uncaughtException', function(err){ var bin = gui.App.manifest.phpwebkit.bin;
pw.changeState('<strong>'+err+'</strong>', '#CD0000'); if(bin === undefined || bin == "") {
});
win.title = gui.App.manifest.name;
var bin = gui.App.manifest.phpwebkit.bin;
if(bin === undefined || bin == "") {
if(os == 'win32' || os == 'win64') { if(os == 'win32' || os == 'win64') {
bin = './bin/php/php-cgi.exe'; bin = './bin/php/php-cgi.exe';
} else if(os == 'darwin') { } else if(os == 'darwin') {
@ -25,81 +25,59 @@ var phpwebkit = {
} else { } else {
bin = 'php-cgi'; bin = 'php-cgi';
} }
} }
this.fileExists(bin, function(result){ binExists(bin, function(filename){
if(result === false) { bin = filename;
return 'php-cgi'; });
}
});
var path = gui.App.manifest.phpwebkit.path; var path = gui.App.manifest.phpwebkit.path;
if(path === undefined || path == "") { if(path === undefined || path == "") {
path = './application'; path = './application';
} }
var host = gui.App.manifest.phpwebkit.host; var host = gui.App.manifest.phpwebkit.host;
if(host === undefined || host == "") { if(host === undefined || host == "") {
host = '127.0.0.1'; host = '127.0.0.1';
} }
var port = gui.App.manifest.phpwebkit.port; var port = gui.App.manifest.phpwebkit.port;
if(port === undefined || port == "") { if(port === undefined || port == "") {
port = 0; port = 0;
} }
var config = { var phpinfo = {
"path": path, "path": path,
"bin": bin, "bin": bin,
"host": host, "host": host,
"port": port, "port": port,
"arguments": gui.App.argv, "arguments": gui.App.argv,
"manifest": gui.App.manifest "manifest": gui.App.manifest
}
this.startServer(config);
},
startServer: function(config, callback){
var http = require('http');
var php = require('../lib/bridge');
var express = require('express');
var app = express();
var host = config.host;
var port = config.port;
var pw = this;
var server = http.createServer(app);
app.use('/', php.cgi(config));
server.listen(port, host, function(){
pw.changeState('Starting application...', '#00CD00');
window.location = 'http://'+host+':'+server.address().port +'/';
}).on('error', function(err) {
pw.changeState('<strong>Error: '+server.err+'</strong>', '#CD0000');
});
},
changeState: function(msg, color){
$('body').css('background-color', color);
$('#loading p').html(msg);
},
fileExists: function(file, callback){
var fs = require('fs');
fs.stat(file, function(err, stats) {
if(!err && stats.isFile()) {
return true;
} else {
return false;
}
});
}
}; };
phpwebkit.runApp(); var server = http.createServer(app);
app.use('/', php.cgi(phpinfo));
server.listen(port, host, function(){
var url = 'http://'+host+':'+server.address().port+'/';
changeState('Starting application...', '#00CD00');
window.location = url;
}).on('error', function(e) {
changeState('<strong>Error: '+e.message+'</strong>', '#CD0000');
});
function changeState(msg, color){
$('body').css('background-color', color);
$('#loading p').html(msg);
}
function binExists(file, callback){
fs.stat(bin, function(err, stats) {
if(!err && stats.isFile()) {
return stats.filename;
} else {
return 'php-cgi';
}
});
}