Skip to content
Advertisement

Electron “ready-to-show” event not working as expected

Here is a block of code from my application Codey.

src/main.py

JavaScript

src/docs/renderer.js

JavaScript

When darkMode = true, toggleDarkMode is never run.

My application has two different windows – an editor and a docs window. For both windows, on the “ready-to-show” event, “dark-mode:toggle” is sent to the renderer process. However, the docs window fails to run the toggleDarkMode function whilst it works for the editor window.

Note: The application must be packaged using “yarn package” as some features do not work in the dev environment.

Any help will be much appreciated.

(Repo: https://github.com/Liamohara/Codey)

Advertisement

Answer

For anyone that’s interested. I found a solution to my issue.

src/main.py

JavaScript

In the docs window, there is more HTML content to be renderered than in the editor window. As a result, the DOM takes longer to load and the “ready-to-show” event is emitted before it has finished. Using the “did-finish-load” event, ensures that the API functions are not called before the DOM has finished loading.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement