question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guide to replace remote module with better writing style

See original GitHub issue

Can there be a guide to teach us how to replace things like remote.getCurrentWindow() to something better?

I can’t find a good article for this, only an article telling remote module should be replaced by something better (https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31) which is somehow useless.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nornagoncommented, Mar 2, 2021

And there seem to be no event.sender in ipc.invoke()

ipcMain.handle() does provide the sender. https://www.electronjs.org/docs/api/structures/ipc-main-invoke-event

e.g.

ipcMain.handle('my-event', (event) => {
  event.sender // this works :)
})
0reactions
linonetwocommented, Mar 24, 2021

Is there a safe package to “Passing callbacks to the main process”?

I think I can iterate through the object, replace each object method with a random uuid, and send this object without a callback to the main thread.

And I register IPCRenderer.on(uuid for each object method, and reconstruct the object with callback on the main process, the callback is just IPCMain.invoke(uuid. Is there any existing package to do so?

I think I will use remote module again, I think it is not harmful if you enable all security settings https://github.com/electron/remote/issues/47


Update: I write my own function as descript above to proxy menu item from renderer to the main. The drawback is the callback can’t get the webContent and ElectronEvent instance on the renderer. But this allows dynamic content to add custom menu items with callback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial - A Guide to Module Federation for Enterprise
A guide for supporting a fully dynamic, multi-environment Module Federation configuration. Tagged with modulefederation, webpack, ...
Read more >
Module Development · bitfocus/companion Wiki - GitHub
Developers Guide. Ish. So, you want to develop a module for Companion? Welcome! This document describes what you need to know and do...
Read more >
Documentation Style Guide - GitLab Docs
Documentation Style Guide. This document defines the standards for GitLab documentation, including grammar, formatting, word use, and more.
Read more >
Replace all instances of a particular string in a file using a ...
This module will replace all instances of a pattern within a file. ... The character encoding for reading and writing the file. Default:...
Read more >
Structuring Your Project - The Hitchhiker's Guide to Python
In this section, we take a closer look at Python's modules and import systems as they are the central elements to enforcing structure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found