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,105 +1,83 @@
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');
var win = gui.Window.get();
var os = require('os');
var os = os.platform();
var pw = this;
win.title = gui.App.manifest.name;
process.on('uncaughtException', function(err){
pw.changeState('<strong>'+err+'</strong>', '#CD0000');
});
win.title = gui.App.manifest.name;
var bin = gui.App.manifest.phpwebkit.bin;
if(bin === undefined || bin == "") {
if(os == 'win32' || os == 'win64') {
bin = './bin/php/php-cgi.exe';
} else if(os == 'darwin') {
bin = './bin/php/php-cgi';
} else if(os == 'linux') {
bin = './bin/php/php-cgi';
} else {
bin = 'php-cgi';
}
}
this.fileExists(bin, function(result){
if(result === false) {
return 'php-cgi';
}
});
var path = gui.App.manifest.phpwebkit.path;
if(path === undefined || path == "") {
path = './application';
}
var host = gui.App.manifest.phpwebkit.host;
if(host === undefined || host == "") {
host = '127.0.0.1';
}
var port = gui.App.manifest.phpwebkit.port;
if(port === undefined || port == "") {
port = 0;
}
var config = {
"path": path,
"bin": bin,
"host": host,
"port": port,
"arguments": gui.App.argv,
"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;
}
});
var bin = gui.App.manifest.phpwebkit.bin;
if(bin === undefined || bin == "") {
if(os == 'win32' || os == 'win64') {
bin = './bin/php/php-cgi.exe';
} else if(os == 'darwin') {
bin = './bin/php/php-cgi';
} else if(os == 'linux') {
bin = './bin/php/php-cgi';
} else {
bin = 'php-cgi';
}
}
binExists(bin, function(filename){
bin = filename;
});
var path = gui.App.manifest.phpwebkit.path;
if(path === undefined || path == "") {
path = './application';
}
var host = gui.App.manifest.phpwebkit.host;
if(host === undefined || host == "") {
host = '127.0.0.1';
}
var port = gui.App.manifest.phpwebkit.port;
if(port === undefined || port == "") {
port = 0;
}
var phpinfo = {
"path": path,
"bin": bin,
"host": host,
"port": port,
"arguments": gui.App.argv,
"manifest": gui.App.manifest
};
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';
}
});
}