Electron-Builder Linux updates - APPIMAGE env is not defined - electron

I am on an Electron + Create React App stack.
I am using Electron Updater (https://github.com/develar/electron-updater) for auto updates.
Platform: Linux, Format: AppImage.
When my app checks for updates, I get the following error:
APPIMAGE env is not defined.
Has someone experienced the same issue? Suggestions required.

Please don't use electron-updater anymore, since it is no longer supported according to its GitHub page.

Most often, this occurs when you are trying to use the auto updater in development mode (or non-packaged AppImage mode). It only works in a packed production build.
For me however, this also occurred in a packed AppImage, and turned out to be caused by using the webpack DefinePlugin, like this:
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
},
...
Removing the process.env definition allowed APPIMAGE to be defined once again in the distributed package. It seems the rest of the definitions can be left in place safely without breaking the auto-updater.
If removing this definition is not possible for your use-case, according to some users it's possible to simply override it at the beginning of your main thread (not renderer thread) file like this:
process.env.APPIMAGE = path.join(__dirname, 'dist', `MyApp-${app.getVersion()}.AppImage`)
... obviously with the correct file name in the 3rd argument of Path.join.
This override approach didn't seem to do anything for me though, so I myself went with simply removing process.env from the DefinePlugin definitions, but it may help in other cases.

try to use electron-builder for building your app cause this module is is in maintainance only mode.
the autoUpdate for linux is not possible, you can do that only for mac and windows try to read this documentation.

Related

Codesigning electron app for windows (on windows)

As it says in the title, this is what im trying to do: using windows 10, codesign my electron app using the certificate purchased from a third party vendor (which is in p12 format).
I've read the docs here: https://www.electron.build/configuration/win and here: https://www.electron.build/code-signing
And realise that I need to provide a path to the certificate file and password (if one is set) using the appropriate keys (certificateFile and certificatePassword).
I've also seen these answers:
How to sign in windows installer using electron builder
(There's also loads of questions and answers referring to people building for windows on mac, but that's not what im doing here)
But this doesnt seem to address the question.
These are how the lines in my package.json are set referring to the relevant path/password:
"certificateFile ": "./certificate_file.p12",
"certificatePassword ": "password"
I realise that it is better to have these set in a .env file and read them from there, which I intend to do later. But as I understand it, this should suffice shouldnt it?
My build command is:
"build": "electron-builder build"
And this produces the following:
But there is no mention of signing taking place at all. If Im being royally stupid, please feel free to point out where ^_^ many thanks in advance!
Updates
Queried with project maintainers on github, code signing is supposed to take place automatically provided the variables are set correctly, see convo here: https://github.com/electron-userland/electron-builder/issues/6895)
It may be significantly simpler to sign your exe OUTSIDE of electron builder. In which case, the approach I took was to use SSL.com's SSL manager GUI.
You can read about it toward the bottom of this page and see their documentation of the tool here.
About a week looking into codesigning with electron builder, still not entirely sure how to do it.
About 5 mins using this tool. Done.
I don't remember the whole process but I had to fumble around for a few days to get it working.
In my package.json file I have a build object like this:
"build":
...
"win": {
"certificateFile": "private/mycertificate.pfx",
"verifyUpdateCodeSignature": true,
"publisherName": [
"My Company Name"
]
},
Then before publishing I run this in windows powershell to set the env variable:
setx CSC_KEY_PASSWORD my-certifcate-password-here
Then finally:
electron-builder -w

Remix.run deployment on Vercel: process not defined error

I have deployed a remix application on Vercel. Further, I have defined some environment variables in Vercel and want to perform some checks and use env variables in my app:
if (process.env.NODE_ENV === 'production') {
setPaths({
path: process.env.prod_path,
})
}
It gives me error, process is not defined. I even tried adding process && in the if statement, it did not help.
Second, I am unable to even set the env variables locally. I followed remix docs but it gives me undefined every time when I console.log as mentioned in the docs.
Any guide/pointer towards using environmental variables in remix would be really helpful.
I was able to solve this problem. I was using loader/useLoaderData to access server side environment variables. The problem was that I was trying to call these at component level. Apparently, we can only call them at the route level.
I'm not sure, but the name of the function (setXXX makes me think this is the setter of a hook), makes me think you are trying to use process.env in the browser, but process.env is only available in server-side code, if you want to use env variables in your react app you can use this guide to send the variables from the server side to you react app. If this code is server side code, maybe it's worth making a reproduction in stackblitz so we can have a better look at it.

Using Environment Variables for Per Environment Configuration in iOS

I am working on an iOS application that uses a pretty normal multi-environment deployment model. We have a QA, Prod, and "Dev" version of the app that all talk to their own corresponding backends. I am new to iOS development but am familiar with Node, Java, and a few other development environments.
The first thing I reached to for this problem was Environment Variables. I saw that XCode had a way to set environment variables in a Scheme and they could be read pretty easily. So I used 4 environment variables per environment to configure a few needed backend hosts. Everything seemed to be going fine until I realized that those environment variables seem to ONLY be available when running the app through XCode. Is that correct? Is there no way to configure environment variables that "bundle up" with an app? If so, the ability to configure environment variables at all seems like a footgun.
What I mean is, In a NodeJS or Java app, I can set a number of useful "necessary" configs like a backend hosts and use some approach to provide those values when running the app for real. It seems like in iOS / Swift, environment variables are only useful for development-time debugging settings? The asymmetry between what's available in XCode vs a "real" shipped app seems odd.
Is there a similar standard way that I can configure my app for multiple different environments that works on shipped applications and ideally just involves reading some value at runtime rather than using conditionals and/or using compiler flags or something?
You are correct. The Environment Variables are only meaningful when executing the Scheme in Xcode. Their primary use in that context is to activate debugging features that are not on all the time. For example, if you try to create a bitmap Core Graphics context (CGContext) with an invalid set of parameters, the debugger may tell you to set an environment variable to see additional debugging output from Core Graphics. Or you can set environment variables to turn on memory management debugging features.
When you are running an application on a server, the Unix framework in which the application is running is part of the "user experience". In that context it makes sense for the application to use things like environment variables.
As developers we understand that a mobile app is running inside a unix process, but that unix environment is mostly unavailable to us. A similar feature that is common to Unix apps is command line arguments. An iOS application on startup receives command line arguments (argc and argv) but there is no way specify those when the app is launched either.
There are a number of places you could include configuration information like that which you describe in your application. The most common that I can think of is to include the setting in the applications Info.plist. At runtime you could access the contents of the property list by fetching the main bundle and asking for it's infoDictionary:
let infoBundle = Bundle.main.infoDictionary
let mySetting = infoBundle["SomeSetting"]
When the application's info.plist is created, it DOES have access to the environment variables declared in the Scheme so you could put the environment variables in the scheme, reference them in the Info.plist, and retrieve them at runtime from the main bundle.
try Using FeatureFlags, maybe will help you, check this
https://medium.com/#rwbutler/feature-flags-a-b-testing-mvt-on-ios-718339ac7aa1

Using foreverjs in electron causes electron app duplicates in dock

I am using foreverjs within my electron app main like so:
const forever = require("forever-monitor");
let child = forever.start(scriptPath, {fork: true});
I am doing this intentionally over using child_process.fork because I want foreverjs to monitor the forks and restart them when needed.
Well - the above works, but looking at my dock on mac osx, I see that the electron app is duplicated for each fork. In production it is the same -- the app icon get's duplicated N times in the Dock for each process.
Investigating further I found the cause but not the solution. The cause is that when you fork a process normally using child_process from within electron, it launches it using the Electron Helper app.
However when you fork a process using forever.js it uses the Electron app itself, thus explaining the duplicates.
How do I force forever to use the Electron Helper app when forking and not the Electron app itself?
OK, so I figured it out. Quite simply you need to pass one environment variable to foreverjs like so:
const forever = require("forever-monitor");
let child = forever.start(scriptPath, {fork: true, env: {ELECTRON_RUN_AS_NODE: 1}});
Doing this and the fork will correctly use its prepackaged version of node instead of launching another copy of electron "main".

How to pass an argument to electron when using electron-builder?

I'm building an application with Electron and packaging with Electron Builder. When running electron, I want to pass this command line argument: --enable-mixed-sandbox.
Is it possible? How?
This:
app.commandLine.appendSwitch('enable-mixed-sandbox')
wouldn't work due to:
Note that it is not enough to call
app.commandLine.appendSwitch('--enable-sandbox'), as electron/node
startup code runs after it is possible to make changes to chromium
sandbox settings. The switch must be passed to electron on the
command-line:
electron --enable-sandbox app.js
It is not possible to have the OS sandbox active only for some renderers, if --enable-sandbox is enabled, normal electron windows
cannot be created.
You can use app.commandLine.appendSwitch in your applications main script (the one that opens the Electron window)
Example for your switch would be
app.commandLine.appendSwitch('enable-mixed-sandbox')
another way of doing it, you can use spectron to start the app in debug mode. which allows you to pass any arguments you want.
const Application = require('spectron').Application
// Returns a promise that resolves to a Spectron Application once the app has loaded.
// Takes a Ava test. Makes some basic assertions to verify that the app loaded correctly.
function createApp (t) {
return new Application({
path: 'path/to/app',
args: ['-r', '--enable-mixed-sandbox'],
env: {NODE_ENV: 'test'},
waitTimeout: 10e3
})
}
https://github.com/electron/spectron#new-applicationoptions
I got a response on that issue I raised and linked to in the comments:
app.enableMixedSandbox() // Experimental macOS Windows
See here for documentation.

Resources