nw.js desktop app

TODO: file saving!
main
Isaiah Odhner 2015-04-05 13:10:02 -04:00
parent b828a6e9bc
commit 5984972bb7
4 changed files with 49 additions and 2 deletions

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
# npm
node_modules/
*.log
# os crap
Thumbs.db
~*

View File

@ -9,8 +9,7 @@
},
"file_handlers": {
"edit": {
"types": ["image/*"],
"title": "Paint"
"types": ["image/*"]
}
},
"permissions": [

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "jspaint",
"version": "0.1.2",
"description": "An MS Paint remake.",
"main": "index.html",
"scripts": {
"start": "nw"
},
"window": {
"icon": "images/icons/48.png",
"toolbar": false
},
"dependencies": {
"nw": "^0.12.0-1",
"wallpaper": "^1.0.0"
},
"repository": {
"type": "git",
"url": "http://github.com/1j01/jspaint.git"
},
"bugs": {
"url": "http://github.com/1j01/jspaint/issues"
}
}

View File

@ -757,6 +757,25 @@ function set_as_wallpaper_centered(c){
layout: 'CENTER_CROPPED',
name: file_name,
}, function(){});
}else if(window.require){
var gui = require("nw.gui");
var fs = require("fs");
var wallpaper = require("wallpaper");
var base64 = c.toDataURL().replace(/^data:image\/png;base64,/, "");
var imgPath = require("path").join(gui.App.dataPath, "bg.png");
fs.writeFile(imgPath, base64, "base64", function(err){
if(err){
alert("Failed to set as desktop background:\nCouldn't write temporary image file");
}else{
wallpaper.set(imgPath, function(err){
if(err){
alert("Failed to set as desktop background!\n" + err);
}
});
}
});
}else{
window.open(c.toDataURL());
}