#Create Window and Send Message to it

1 messages · Page 1 of 1 (latest)

edgy flicker
#

My app is using electron v. 27.3.11. I would like to up-version it to a more recent electron version.

My problem is that ipcRenderer.sendTo is deprecated in 27.3.11, but absent in more recent versions.

What is the mechanism that I can use when the app creates a new Window in a renderer process, and needs to send that Window a message after it's created?

const addToPlaylistButton = document.querySelector('#add-to-playlist');

addToPlaylistButton.addEventListener(StringLiterals.CLICK, async () => {
    const selectedTracks = tracksTable.searchData('selected', '=', true);

    // create the new window (via new remote.BrowserWindow...)
    const playlistWindow = WindowUtils.createWindow('playlist', true);
    remote.require("@electron/remote/main").enable(playlistWindow.webContents);

    playlistWindow.webContents.once(StringLiterals.DID_FINISH_LOAD, () => {
        ipcRenderer.sendTo(playlistWindow.id, StringLiterals.CHILD_WINDOW_CHANNEL, {
            'playlists': Object.keys(metadata.playlists),
            'tracks': selectedTracks,
            'defaultPlaylistName': getSelectedHierarchyRowData() !== undefined ?
                getSelectedHierarchyRowData().displayName : StringLiterals.EMPTY_STRING,
            metadata
        });
    });
});

Thanks in advance!

edgy flicker
#

Thanks @ivory finch.

I was able to update the IPC for the latest version of Electron. It's unfortunate that there isn't a great way to do IPC directly from one renderer process to another renderer process, without having to have the main process orchestrate the IPC.

https://github.com/EricTerrell/ebt-music-manager/compare/efccbc8..2c8a724

GitHub

EBT Music Manager allows you to edit playlists and audio file metadata. EBT Music Manager can play your playlists, albums, and tracks. EBT Music Manager allows you to sync your music to a folder, w...

tranquil dust
#

sounds like a BroadcastChannel (https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel) for message exchange across windows would work for you

MDN Web Docs

The BroadcastChannel interface represents a named channel that any browsing context of a given origin can subscribe to. It allows communication between different documents (in different windows, tabs, frames or iframes) of the same origin. Messages are broadcasted via a message event fired at all BroadcastChannel objects listening to the channel...