#Can't close or quit electron app on Mac

44 messages · Page 1 of 1 (latest)

coarse escarp
#

I've created an application using ionic-react and used capacitor to build an electron app. I'm using electron forge to package and distribute my application.

I've configured my app to run in the background and create a window when user needs to see a particular set of data. So I'm invoking a function periodically on the electron code to check the database every 2 hours if this particular set of data is present for the user. When the user puts their system in sleep this function is still running is what I believe. So after 2 days of user putting their laptop on sleep and reopening it, the app window is created and all the functionalities are working fine but the 'Close' function which I had written on the electron code and bridged it to my UI using ipc main and ipc renderrer process doesn't seem to work. I checked the memory consumption of the app on Mac and the virtual memory was 1.4TB but this seems to be normal with electron apps and the other one was shared memory which was usually around 40mb but when the app was not working it was around 150mb. I'm trying to narrow down the issue but I'm not really able to understand what exactly is happening here

#

@tame igloo , so as I was saying I built all my UI components using ionic react

#

I then used capacitor to build an electron app with my ionic code

#

When the laptop is put on sleep for a long time with the app running in the background and woken up the app is still running, I'm able to interact with the UI go through the pages but this is all my react code. When I try to close the app, this triggers an IPC function from my electron which doesn't work.

#

Trying to quit the app doesn't work either

#

I have to force quit in this scenario only that seems to work

tame igloo
#

You have close button in html?

coarse escarp
#

yes

tame igloo
#

And button is clicked?

coarse escarp
#

yes

tame igloo
#

And ipc message is sended?

coarse escarp
#

Was not able to verify that

tame igloo
#

Time to check

#

And check if message is received in main process

coarse escarp
#

Yes sir

coarse escarp
#

This is gonna take some time, I'll post my update once done

coarse escarp
#

Hey @tame igloo, took me sometime to recreate the issue and check but the ipc seems to be working

#

But the app doesn't quit or close nor is throwing any error

runic falcon
#

Can you share your main config as well as this button + ipc config?

coarse escarp
#

Hello @runic falcon, by main config do you mean the code for my main process

runic falcon
coarse escarp
#

ok give me a sec

#

ipcMain.on('close-app', () => {
myCapacitorApp.getMainWindow().close();
if (timer != null) {
clearTimeout(timer);
timer = setTimeout(openWindowOnQuestions, 2 * 60 * 60 * 1000);
}
else {
timer = setTimeout(openWindowOnQuestions, 2 * 60 * 60 * 1000);
}
});

#

This is the ipc I've got running

#

// Handle when all of our windows are close (platforms have their own expectations).
app.on('window-all-closed', function (event: Event) {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
event.preventDefault();
});

#

this.MainWindow.on('closed', () => {
if (this.SplashScreen?.getSplashWindow() && !this.SplashScreen.getSplashWindow().isDestroyed()) {
this.SplashScreen.getSplashWindow().close();
}
});

#

I don't have a particular event .on("close", () => {}), I'm directly using the close() method provided on mainWindow

runic falcon
#

you said it stops working after a while or it never worked at all?

coarse escarp
#

My app keeps running in the background, it is configured wake up once every 2 hours if there is any new data that user needs to see and all functions work fine in normal conditions, but when the laptop is put into sleep mode for long period of time like 2 days on the weekend, on waking up the app has created a new window which I believe is because of the 2 hour timer, but it seems to be frozen

#

The ui code which I have written in ionic react works fine

#

I'm able to navigate between pages

#

The close function on the other hand is on the electron side which didn't work

#

I thought maybe the ipc message was not being sent

#

but that was not the case, I tested using logs and the ipc function was getting invoked

#

right clicking on dock icon and selecting 'Quit' doesn't work either

#

It feels like the App itself went unresponsive

#

Hope my explanation made sense

#

I've reduced this 2 hour timer to every 5 mins and this actually caused the issue a lot faster, so I was thinking maybe this timer was a problem and I started clearing it whenever the app was put into sleep and restarted it when the system wakes up

#

But that didn't work either

#

@runic falcon , were you able to understand my issue?

runic falcon
#

Yeah, but I don't think I can help

coarse escarp
#

Cool, I'll keep working on it and post my updates here. Please let me know if you come across any info. Thank you 😁

coarse escarp
#

Hi @tame igloo and @runic falcon , I seem to have fixed the issue though I'm still testing my app I'm 90% positive that the issue is fixed now, the timers I have used to call a function every two hours was calling the function multiple times as soon as the system woke up from sleep. I thought the timers get paused when the laptop goes into sleep but that was not the case. I'm not sure if this caused the issue but clearing the setTimeout method whenever the system goes into sleep and starting one again as soon as the system wakes up seems to have fixed the issue.