Select Folder dialog crashes the app
Ubuntu 14.04 x64 NW 0.13.0-beta4 x64
When I invoke the select folder dialog, app crashes. The code I use to open folder select dialog is below:
openFolderDialog: function (options) {
options = options || {};
var $input = $('<input type="file" class="hidden" nwdirectory>');
if (options.multiple) {
$input.attr('multiple', 'multiple');
}
if (options.cwd) {
$input.attr('nwworkingdir', options.cwd);
}
return $.Deferred(function (promise) {
var chosenPath = null;
$input[0].files.append(new File("", ""));
$input.on('change', function () {
chosenPath = $input.val();
$input.remove();
if (chosenPath) {
promise.resolve(chosenPath);
} else {
promise.reject();
}
});
$input.appendTo($('body'));
$input.click();
});
}
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Your code seems legit, the only thing to suspect for me is:
$input[0].files.append(new File("", ""));
There are some other things to mention:
- the promise would never be rejected -- its unable to detect the "Cancel" action in file/folder selection dialogs.
- the previous means that older cancelled dialogs never clean up their environment (Deferred object and
inputnode). - NW provides the
pathmember of file input controls, you probably want to use that instead ofvalue, see this - in 0.13 branch you can use https://developer.chrome.com/apps/fileSystem (but there are some drawbacks).
So, it does not look like NW problem; please try rewriting your code using notes above and feel free to ask for more help if needed.
thank you :) I will try your recommendations today and write the feedback.
Yes, using chrome fileSystem module solved the problem, but it is strange, that app crashes with the code which worked perfectly in 0.12
Thats because shims used to emulate "application" behavior had been delegated to Chromium core, so some backward compatibility (especially non-documented) became broken. However, code you provided above is not totally correct, so facing problems after API changes should not be a surprise.
Ok. thank you @offshore. Only one more question: should I close this issue?
You decide, I bet nothing prevents you :)
@achugaev93 , seem this issue doesn't exist, so could we close this issue now?