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

Exception from outdated electron-config module on newer version of Electron #86

Open
RandomEngy opened this issue Dec 15, 2021 · 5 comments

Comments

@RandomEngy
Copy link

I'm using Electron 16.0.4 and am initializing the electron-push-receiver from the isolated context preload script in the renderer process. I'm getting this error on importing the module:

TypeError: Cannot read properties of undefined (reading 'app')
    at new ElectronConfig (webpack-internal:///../node_modules/electron-config/index.js:8:47)
    at eval (webpack-internal:///../node_modules/electron-push-receiver/src/index.js:12:16)

It appears that v1.0 of electron-config is making a check: electron.app || electron.remote.app. This throws since both are null in newer versions of Electron. It appears the new package for storing data is electron-store. I think it might be fixed just by updating to use that instead.

I was able to work around this by using the literal strings when listening for the push events rather than trying to import the values in the preload script.

"PUSH_RECEIVER:::START_NOTIFICATION_SERVICE"
"PUSH_RECEIVER:::NOTIFICATION_SERVICE_ERROR"
"PUSH_RECEIVER:::NOTIFICATION_SERVICE_STARTED"
"PUSH_RECEIVER:::NOTIFICATION_SERVICE_ERROR"
"PUSH_RECEIVER:::NOTIFICATION_RECEIVED"
"PUSH_RECEIVER:::TOKEN_UPDATED"
@davej
Copy link

davej commented Jan 1, 2022

Can confirm. I noticed the same issue.

@vialoh
Copy link

vialoh commented Mar 25, 2022

@RandomEngy I just want to say... Thank you for sharing your workaround. You probably saved me hours/days of going in circles trying to find a solution. It would have taken me entirely too long to determine that importing the constants from electron-push-receiver was the reason for my preload script failing to load, based on the console's error messages. Seriously, thank you.

@weeks6
Copy link

weeks6 commented Mar 25, 2022

@vialoh Hi, can you please share your snippet of how you initialize the reciever? I tried using strings instead of imported event names but I still get the same error

@vialoh
Copy link

vialoh commented Mar 25, 2022

@weeks6 Sure! I'm using @capacitor-community/electron, and you can see how I've integrated electron-push-receiver here in this commit: molecule-dev/molecule@7621889

And if you're curious as to how it's integrated into a React app: molecule-dev/molecule@b4b94cd

Plus some instructions for configuring the GOOGLE_CLOUD_MESSAGING_SENDER_ID: molecule-dev/molecule@dd767c8

The molecule-dev/molecule-app is a work in progress which often has its git history overwritten (for good reason if you take a look at what it's for), so if these links to the commits above ever break, ping me here and I'll update this comment.

@weeks6
Copy link

weeks6 commented Mar 25, 2022

@vialoh Thanks! That helped me a great deal!

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

No branches or pull requests

4 participants