nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

Select Folder dialog crashes the app

Open avchugaev opened this issue 10 years ago • 7 comments

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.

avchugaev avatar Jan 24 '16 09:01 avchugaev

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 input node).
  • NW provides the path member of file input controls, you probably want to use that instead of value, 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.

offshore avatar Jan 25 '16 08:01 offshore

thank you :) I will try your recommendations today and write the feedback.

avchugaev avatar Jan 25 '16 09:01 avchugaev

Yes, using chrome fileSystem module solved the problem, but it is strange, that app crashes with the code which worked perfectly in 0.12

avchugaev avatar Jan 29 '16 09:01 avchugaev

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.

offshore avatar Jan 29 '16 14:01 offshore

Ok. thank you @offshore. Only one more question: should I close this issue?

avchugaev avatar Jan 29 '16 14:01 avchugaev

You decide, I bet nothing prevents you :)

offshore avatar Jan 29 '16 17:01 offshore

@achugaev93 , seem this issue doesn't exist, so could we close this issue now?

Christywl avatar May 03 '17 08:05 Christywl