node-webkit invoke download action doesn't work

Discussion and feedback on Construct 2

Post » Wed Mar 19, 2014 9:52 am

Hi,

I am trying to download a screenshot of the canvas. On the preview it works well, but when exported to nodekit I have problems.

If i minify, instead of a download popup, I get a new "modal" window opened with the contents i want to download. The pop-up window doens't allow doing anything like ctrl-s for save or right mouse click for save as.

If i don't minify, i get a pop-up window for a split of a second, that then disappears, removing the "goto" shows the captured image in the window "ontop" of the original window (i can see buttons the original window includes).

all in all, its weird behavior,

any suggestions would be much appreciated,

Dan
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Mar 19, 2014 12:51 pm

I wouldn't expect it to work: the normal download UI and right-click menus are all part of the browser UI. Node-webkit is not quite a real browser, just a browser engine with the UI missing so it looks like a native app.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Wed Mar 19, 2014 12:53 pm

I see. Thanks.

I noticed that nodekit supports file save. Can it save CanvasSnapshot (non text files)?
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Mar 19, 2014 1:09 pm

I noticed that node-webkit save, saves a base64 string -- so I guess I would need to translate this back into a jpg image, somehow, from the outside.
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Mar 19, 2014 1:27 pm

@Ashley, any chance that node-webkit could support saving a canvas snapshot as an jpg or png -- or is this a limitation imposed by node-webkit itself.
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Mar 19, 2014 1:42 pm

This is not supported right now, currently node-webkit can only save text files.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Wed Mar 19, 2014 3:08 pm

Hi @Ashley,

OK, so I solved it with some Javascript injected with the browser, and a tailored javascript call as follows:
(Its pretty basic. It's too bad that its not supported "natively" in C2 in the node-webkit plugin, but since I am new to javascript, it took me a bit to stich together, and I feel my solution is rather brittle).

In C2:

set varCanvas = right(CanvasSnapshot,len(CanvasSnapshot)-23)
Execute JavaScript varScript & "; me( 'c:\\results\\file99.jpg', '" & varCanvas & "');"

and javascript I've loaded in the varScript variable:

function me(name, canvas) {
var fs = require('fs');
var img = new Buffer(canvas, encoding='base64');

fs.writeFile(name, img, function(err) {
// if(err) {
// document.write("<p>");
// document.write(err);
// document.write("</p>");
// } else {
// document.write("<p> The file was saved!</p>");
// }
//
}
);
};
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Fri Mar 21, 2014 5:39 am

Can you post a CAPX of this please ?
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699


Return to Construct 2 General

Who is online

Users browsing this forum: AthleticDesign and 5 guests