Electron-builder: Get executable APP name in main.js for portable

Created on 29 Jul 2018  Â·  15Comments  Â·  Source: electron-userland/electron-builder

I see that process.env.PORTABLE_EXECUTABLE_DIR will return executable dir, but how can I get full app name, assume some users would change that app name?

I want to toggle shortcut and startup, which will need dir and app name, C:/Users/${user}/AppData/Local/Temp is not useful since it will change every time.

System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("PORTABLE_EXECUTABLE_DIR", "$EXEDIR").r0'

It only sets PORTABLE_EXECUTABLE_DIR.

feature nsis

Most helpful comment

@Cefold Please try 20.27.1

All 15 comments

Env PORTABLE_EXECUTABLE_APP_FILENAME is added.

Yeach, server side of snap implemented in Go, but why, why client side in Python :(

Yes, that's what I needed, thanks.
I have a rookie question, when can I use the new feature? The newest version v20.26.1 does not have this feature.

By the way, what is the difference from APP_FILENAME and APP_EXECUTABLE_FILENAME?

Release will be today evening CET.

On Sun, Jul 29, 2018, 16:44 Cefold notifications@github.com wrote:

Yes, that's what I needed, thanks.
I have a rookie question, when can I use the new feature? The newest
version v20.26.1 does not have this feature.

By the way, what is the difference from APP_FILENAME and
APP_EXECUTABLE_FILENAME?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/electron-userland/electron-builder/issues/3186#issuecomment-408682499,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVZ3qUv2K70PEozmn-xLB0kbWD5XDCIks5uLcphgaJpZM4VlPDP
.

I tried the new feature, but PORTABLE_EXECUTABLE_APP_FILENAME will return the name in package.json, not the real portable app name.
More importantly, the PORTABLE_EXECUTABLE_APP_FILENAME is fixed.

For example, package.json file has "name": "MyAPP", "productName": "my.app",
I will get a portable app my.app 1.0.0.exe, but PORTABLE_EXECUTABLE_APP_FILENAME will return MyAPP, if I change the APP name, the return value stays the same. What I want is getting my.app 1.0.0, and if I change that file name to anotherAPP.exe, PORTABLE_EXECUTABLE_APP_FILENAME should return anotherAPP.

https://www.electron.build/configuration/nsis/#portable

PORTABLE_EXECUTABLE_ it is a common prefix for all envs that set by portable wrapper.

By the way, what is the difference from APP_FILENAME and APP_EXECUTABLE_FILENAME?

APP_EXECUTABLE_FILENAME is not for users (you are electron-builder user), it is internal developer only name. In the docs PORTABLE_EXECUTABLE_APP_FILENAME described as "sanitized app name to use in file paths."

Now I realised that you want PORTABLE_EXECUTABLE_FILE (full path to portable wrapper).

Yes, I need full path, include portable wrapper, to set shortcut and startup. I know it does not make much sense to give portable app such functions like toggling shortcut and startup, but some users really like to have those functions for portable app.

The hard part is that user might change the portable wrapper name. E.g. if I hardcode the name to my.app 1.0.0.exe, and user change it to something like anotherAPP.exe, the functions used that name will not work.

I guess that name should be passed from nsis to node env, but it seems portable mode does not support Custom NSIS script.

What shortcut do you mean?

Desktop shortcut.

Why do you use portable in this case?

I don't want to use portable, that's users request, some people really hate to install something or unzip something, they just want a single executable, even it will create a tmp folder and unzip everything to that folder every time and slower than normal way.

@Cefold Please try 20.27.1

Great, now PORTABLE_EXECUTABLE_APP_FILENAME will return full path, and path.basename(process.env.PORTABLE_EXECUTABLE_FILE) will return executable name.

Thank you.

For anyone else who finds this- I found that using process.execPath works. I was using an exe built by electron-packager, but not a portable one.

Was this page helpful?
0 / 5 - 0 ratings