[Linux] Wrong Path with NWjs.AppFolder

Bugs will be moved here once resolved.

Post » Tue Aug 30, 2016 12:51 pm

Problem Description
If NWjs.AppFolder is called in a NWjs-App in Linux it gives the wrong path. It puts chrome-extension:// with an ChromeApp-Id in front of the path. It works fine with Windows.

Attach a Capx
Capx with two externels files:
https://drive.google.com/file/d/0B5FlDY ... sp=sharing

NWjs-win32:
https://drive.google.com/file/d/0B5FlDY ... sp=sharing

NWjs-linux64:
https://drive.google.com/file/d/0B5FlDY ... sp=sharing


Description of Capx
The Capx displays the NWjs.AppFolder path in a Textbox. Where the path will be shown correct on all Systems. Then it tries to load a picture in a sprite from an external file and a text-file with the ajax-plugin.
If ajax loaded successful it will write an O.K, otherwise Error

Steps to Reproduce Bug
  • Make a Linux64 NWjs-App from the Capx.
  • Copy the to files: pic2.jpg and test.txt in the linux64 folder
  • Make nw executable an start it.
  • Press F12 to open the Debug-Window, click on the console Tab to see the wrong path.

Observed Result
The Textbox displays the correct path, but no image is loaded and ajax reported an error.

Expected Result
Correct path.

Affected System/b]
  • Windows 7: (NO)
  • Linux Mint 64 Bit: (YES)

[b]Operating System and Service Pack

Windows 7 SP 1
Linux Mint 64 Bit

Construct 2 Version ID
r233 and nwjs 0.16
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Wed Mar 08, 2017 11:44 pm

Anyone know if this is something one could possibly get around? I'm planning on to porting to mac/Linux and it's impossible to load external files because of this. :[
B
6
S
1
Posts: 8
Reputation: 416

Post » Tue Apr 18, 2017 12:37 pm

The expression returns the correct path - e.g. "/home/username/Desktop/". This is a valid path for the file system. The problem is if you make a request to this treating it as a URL - such as you do to issue an AJAX request and load an image - then it's routed through the browser URL resolution. This is not the same as a file path. It expects URLs of the form "https://www.scirra.com", but you pass it something like "/home/username/Desktop/test.txt". This looks like a relative URL (e.g. fetching "/folder/file.txt") so the request happens to be made relative to the current URL, which happens to be something based on chrome-extension:// for NW.js apps. The problem probably only does not happen on Windows because the different file path style with a drive letter unambiguously identifies a local path. You can force it to treat a path as a local URL by prefixing "file://". So your example actually starts working if you add "file://" before the request URLs. That's a nice easy workaround for the time being!

So far everything is actually working correctly. The real problem is confusion between file paths and URLs. We can't change AppFolder because adding "file://" is incorrect for actions that directly manipulate local files. But then you can't directly use AppFolder in a URL expression without prefixing "file://".

So I think the best solution is a new expression AppFolderURL, which has the "file://" part automatically included. Then you can use AppFolder for local file stuff, and AppFolderURL for anything treated as a URL. This will be added in the next build, but you don't need to wait, just add "file://" for now and it works.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Sun Apr 23, 2017 10:03 pm

Thanks Ashley, I did some tests in Ubuntu today and it looks like loading a text file via NWjs.ReadFile works fine without the "file:" prefix, but loading images into a Sprite via Load image from... requires prefix "file:/" (with just the single forward-slash). Will the next build make this consistent between the two objects, so I can just make a single "AppPath" text variable to use for all file loading?
B
12
S
1
Posts: 8
Reputation: 473

Post » Mon Apr 24, 2017 10:32 am

@BipolarMike - no, because URLs and file paths are different things. The issue here is people confusing the two.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Mon Apr 24, 2017 1:12 pm

Right, and both of what I mentioned above were file paths. One loaded a text file saved locally into a text object, the other loaded an image saved locally into a sprite. The former did not need the file:/ prefix, the latter did need it.

I suppose there might be a better way to load in a local text file than using NWjs.ReadFile that I am not aware of?
B
12
S
1
Posts: 8
Reputation: 473


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 4 guests