Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nwworkingdir is not working on Windows #3372

Closed
ognb opened this issue Apr 14, 2015 · 15 comments
Closed

nwworkingdir is not working on Windows #3372

ognb opened this issue Apr 14, 2015 · 15 comments
Labels

Comments

@ognb
Copy link

ognb commented Apr 14, 2015

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@knockshore
Copy link

Can you post the results from devtools:

process.versions
process.arch
process.platform

@ognb
Copy link
Author

ognb commented Apr 16, 2015

untitled

@knockshore
Copy link

I've tried the below element and the value is set as "C:\Windows" thru the javascript.

<input name='file' type="file"/>
inputEl.nwworkingdir = 'C:\\Windows';

It would be helpful if you could tell how you're using the nwworkingdir property.
Is it intermittent? Because, it didn't work one time out of several tries.

Yeah, I stripped the code from the tests.

@bobatsar
Copy link

bobatsar commented Sep 9, 2015

Seem #2948 seems the same problem. I am also still waiting for a bugfix.

@matthew-dean
Copy link

Hey, all! After a LOT of trial and error, I stumbled across a scenario for me that works. It seems, on Windows, setting other attributes essentially causes nwworkingdir to fail, or setting it as an attribute later causes it to fail (or something weird along those lines). I could get it to work in the developer tools console with just nwworkingdir, but then if I added other attributes, it would fail.

In other words, this worked:
$('<input type="file" nwworkingdir="C:\\Users\Matthew\\" />').click()

But this didn't:
$('<input type="file" nwworkingdir="C:\\Users\Matthew\\" nwsaveas="untitled" />').click()

Buuuuut... I realized that a "saveas" path doesn't have to be relative, therefore I tried:
$('<input type="file" nwworkingdir="C:\\Users\Matthew\\" nwsaveas="C:\\Users\Matthew\\untitled" />').click()

This worked!

I used jQuery to build it, so it's not the same as these examples, but this is my final working code on Windows:

var input = '<input type="file" ';

            var fullPath = F.fullPath(options.path);

            if(options.type) {
                if(options.type === 'saveas') {
                    input+='nwsaveas="' + fullPath + Path.sep + options.name + '" ';
                }
                else if(options.type === 'openDirectory') {
                    input+='nwdirectory ';
                }   
            }
            input+='nwworkingdir="' + fullPath + '" />';

            var $dialog = $(input);

            $dialog.on('change', function() {
                callback.call(this);
                $dialog = null;

            });
            $dialog.click();

Hope that helps.

(End note: it would be nice to finally have a real File API for this, instead of this insanity. I'm not sure on what planet this is supposed to be friendly to developers.)

@fritx
Copy link

fritx commented May 6, 2016

@matthew-dean how could you find that. You made my day!

@matthew-dean
Copy link

matthew-dean commented May 6, 2016

@fritx In web developer years, I'm about 1,000 years old, lol. So it's just lots of experience problem-solving. And: no problem! Hope it helped you.

@fritx
Copy link

fritx commented Nov 26, 2016

input.setAttribute('nwworkingdir', 'C:\Windows') // wont work
input.setAttribute('nwsaveas', 'filename')
const fullPath = join(dir, filename)
const input = document.createElement('input')
input.setAttribute('type', 'file')
input.setAttribute('nwsaveas', fullPath) // absolute path works
input.addEventListener('change', ({ target }) => {
  // target.files[0].path
  saveTo(target.value)
})
input.click()

The above solution worked fine in nw 0.12.3, however, it seems to remember last chosen savepath everytime ignoring nwsaveas after upgraded to nw18.

In nw18, the a filename (not fullPath) should be provided to nwsaveas.

@matthew-dean
Copy link

@fritx Are you saying that setting the full path to nwsaveas breaks in nw18? If so, it should be filed to a new bug.

@fritx
Copy link

fritx commented Nov 29, 2016

Yes, last time I've tried it both in Mac 10.11 and Windows 7.
It seems like what I said.

@Christywl
Copy link
Contributor

nwworkingdir works fine for me on Windows with nwjs-sdk-v0.23.5.
<input type="file" nwworkingdir="/home/path/">

@Christywl
Copy link
Contributor

close until there is more information.

@f3l1x
Copy link

f3l1x commented Mar 12, 2018

Just for your info. We're running nwjs-sdk-v0.29.0 on Windows 10 and it's working.

@VoidVolker
Copy link

Similar issue: nwsaveas and nwworkingdir not working. Windows 7, 10, nwjs 0.37.3 normal and SDK versions.

@ffanny
Copy link
Member

ffanny commented Apr 9, 2019

nwworkingdir works well with nwjs-sdk-win-v0.37.3, and nwsaveas with file name doesn't work, but it works well with v0.36.5.

<input type="file" nwsaveas="setuperr.log" nwworkingdir="C:\Windows\debug" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants