我是 node webkit 的新手,用 html 开发桌面应用程序。我创建了一个小项目并使用 nw.exe 运行,它在 windows 8.1 64 位中运行良好,但在 windows 7 中无法运行。
意味着如果我单击多次然后突然启动并关闭一次后它就无法再次运行。
我的package.json
{
"window": {
"icon": "app.png",
"toolbar": true,
"show": false,
"toolbar": false,
"frame": true,
"position": "center",
"width": 1360,
"height": 720
},
"apache_port": 81,
"mysql_port": 3308,
"name": "My App",
"version": "1.0.0",
"author": "Author",
"email": "test@yahoo.com",
"phone": "+91-9999999999",
"url": "http://example.com",
"main": "index.html"
}
索引.html
<script>
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
var gui = require("nw.gui");
var fs = require('fs');
if(process.env.PWD) {
process.chdir(process.env.PWD);
}
/**
* Base dirpath
*/
var base_path=process.cwd();
var i=0;
while(i!=-1) {
base_path=base_path.replace("\\","/");
i=base_path.indexOf('\\');
}
/**
* Package.JSON Details
*/
var package;
//read config file
fs.readFile('./package.json', 'utf-8', function (error, contents) {
package = JSON.parse(contents);
});
function log(str) {
//document.getElementById('text').value+= (str+"\n");
}
function proc_config(file,path) {
fs.readFile(base_path+'/config/'+file, 'utf-8', function (error, contents) {
var substr="%phpbrowserbox%";
var replc=base_path;
contents = contents.replaceAll(substr, replc);
contents = contents.replaceAll('%mysql_port%', package.mysql_port);
contents = contents.replaceAll('%apache_port%', package.apache_port);
fs.writeFile(base_path+"/"+path+"/"+file, contents, function(err) {
if(err) {
return log("error:"+err);
}
log(file+" was saved to "+base_path+"/"+path+"/"+file);
});
});
}
</script>
<!DOCTYPE html>
<html>
<head>
<title>Please wait...</title>
<style>
html,body {height:100%;}
</style>
</head>
<body style="margin:0;padding:0;overflow:hidden;">
<img src="splash.jpg" style="width:100%;height:100%;">
<script>
window.onload=function() {
document.title=package.name;
proc_config('php.ini','bin/php');
proc_config('php.ini','bin/apache/bin');
proc_config('my.ini','bin/mysql');
proc_config('httpd.conf','bin/apache/conf');
var mysqld=base_path+"/bin/mysql/bin/mysqld.exe"
var httpd=base_path+"/bin/apache/bin/httpd.exe"
var proc = require('child_process');
//start apache server
proc.spawn(httpd);
//start mysql server
proc.spawn(mysqld);
location.href="http://localhost:"+package.apache_port+"?apache_port="+package.apache_port+"&mysql_port="+package.mysql_port+"&cache="+Math.random()+"&base_path="+base_path;
gui.Window.get().show();
}
</script>
</body>
</html>
有人可以帮忙吗?