node-webkit app无法在Windows 7 32位上运行

时间:2016-09-25 18:39:27

标签: javascript node.js nwjs

我是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"

}

的index.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>

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

64位NW不适用于32位系统,但32位应适用于所有系统。为了节省很多麻烦,只需编译并坚持使用32位。 64位应用程序总是比较慢,因为内存寻址模式的大小是双倍的,并且每条指令(大或小)都必须清除/设置/读取更宽的寄存器。

此外,每当您的应用程序第一次运行然后不再运行时,通常是因为它仍然在内存中并且没有完全/正确退出。要检查这个,请执行CTRL + ALT + DEL并在仍然存在的情况下终止进程。

最后,您的PACKAGE.JSON似乎有点缺乏,所以请考虑研究并添加更多参数,如...

     "nodejs": true,

“单一实例”:是的, “page-cache”:false

......等等。祝你好运。

相关问题