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

app. Ispackaged is also false after it is packaged by electronic builder #35153

Closed
3 tasks done
message163 opened this issue Aug 1, 2022 · 8 comments
Closed
3 tasks done
Labels
blocked/need-repro Needs a test case to reproduce the bug bug 🪲

Comments

@message163
Copy link

message163 commented Aug 1, 2022

Preflight Checklist

Electron Version

16

What operating system are you using?

Windows

Operating System Version

window 11

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

import { app, BrowserWindow } from 'electron'

import path from 'path'
let win: BrowserWindow | null;

const createWindow = () => {

win = new BrowserWindow({
    webPreferences: {
        devTools:true,
        contextIsolation: false,
        nodeIntegration: true
    }
})

//  app.isPackaged  returns  false
if (app.isPackaged) {
    win.loadFile(path.join(__dirname, '../index.html'))
} else {
    win.loadURL(`http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}`)
}
}

app.whenReady().then(createWindow)

Actual Behavior

// app.isPackaged returns true

Testcase Gist URL

No response

Additional Information

No response

@message163 message163 changed the title [Bug]: app. Ispackaged is also false after it is packaged by electronic builder Aug 1, 2022
@RaisinTen
Copy link
Contributor

what do you get when you print app.getPath('exe')?

@message163
Copy link
Author

C:\Users\TR\Desktop\electron\electron.exe

@message163
Copy link
Author

image

@RaisinTen
Copy link
Contributor

RaisinTen commented Aug 2, 2022

I didn't get a chance to try to package an electron app using electron-builder yet but the reason why this happens is clear -

bool App::IsPackaged() {
auto env = base::Environment::Create();
if (env->HasVar("ELECTRON_FORCE_IS_PACKAGED"))
return true;
base::FilePath exe_path;
base::PathService::Get(base::FILE_EXE, &exe_path);
base::FilePath::StringType base_name =
base::ToLowerASCII(exe_path.BaseName().value());
#if BUILDFLAG(IS_WIN)
return base_name != FILE_PATH_LITERAL("electron.exe");
#else
return base_name != FILE_PATH_LITERAL("electron");
#endif
}
.
app.isPackaged works by checking if the name of the executable is electron. If it is so (which is true in your case), it assumes that it is not packaged, otherwise it thinks that it's packaged. If this is blocking your progress, you could try to set the environment variable, ELECTRON_FORCE_IS_PACKAGED, with any value you want and that would make electron think that it's always a packaged app.

I'd also like to know what version of electron or electron-builder where this problem was introduced in. That info would be very helpful (might help us understand if opening this issue in the electron-builder repo makes more sense, which you have already done in electron-userland/electron-builder#7034)!

@message163
Copy link
Author

set ELECTRON_FORCE_IS_PACKAGED Or false

@RaisinTen
Copy link
Contributor

RaisinTen commented Aug 5, 2022

@message163 I tried to package a dummy app using electron-builder v23.3.3 on Windows and I wasn't able to repro this locally because the name of the executable is the same as the name of the packaged app (which is not electron btw). I'm adding blocked/need-info ❌, so that you can share the steps for reproducing this. It would be really awesome if you're able to share a GitHub gist / repo that has the repro code!

@RaisinTen RaisinTen added the blocked/need-repro Needs a test case to reproduce the bug label Aug 5, 2022
@RaisinTen
Copy link
Contributor

No follow-up for more than a month, closing.

@RaisinTen RaisinTen closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2022
@Yorenzz
Copy link

Yorenzz commented Mar 24, 2023

No follow-up for more than a month, closing.

I didn't get a chance to try to package an electron app using electron-builder yet but the reason why this happens is clear -

bool App::IsPackaged() {
auto env = base::Environment::Create();
if (env->HasVar("ELECTRON_FORCE_IS_PACKAGED"))
return true;
base::FilePath exe_path;
base::PathService::Get(base::FILE_EXE, &exe_path);
base::FilePath::StringType base_name =
base::ToLowerASCII(exe_path.BaseName().value());
#if BUILDFLAG(IS_WIN)
return base_name != FILE_PATH_LITERAL("electron.exe");
#else
return base_name != FILE_PATH_LITERAL("electron");
#endif
}

.
app.isPackaged works by checking if the name of the executable is electron. If it is so (which is true in your case), it assumes that it is not packaged, otherwise it thinks that it's packaged. If this is blocking your progress, you could try to set the environment variable, ELECTRON_FORCE_IS_PACKAGED, with any value you want and that would make electron think that it's always a packaged app.
I'd also like to know what version of electron or electron-builder where this problem was introduced in. That info would be very helpful (might help us understand if opening this issue in the electron-builder repo makes more sense, which you have already done in electron-userland/electron-builder#7034)!

when i change the productName of build parameter to the name except electron, app.isPackaged seems true after building

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/need-repro Needs a test case to reproduce the bug bug 🪲
Projects
None yet
Development

No branches or pull requests

3 participants