wexond / browser-base

Modern and feature-rich web browser base based on Electron
https://wexond.net
2.68k stars 406 forks source link

Changing the Browser Chrome based on Events emitted in the Website #599

Closed davkle closed 3 years ago

davkle commented 3 years ago

Hey,

I have a general question (potentially fitting label would be documentation I suppose):

I want to change indicators (e.g., the layout (i.e., the color) of the address bar) based on events occurring on the website. Emitting events from the website and receiving it via ipcMain (in app.ts in src/main/windows) works so far. What I didn't figure out is how to for example notify the address bar based on the received events in app.ts to e.g., change the background color.

ipcMain.on('ev-blur', (e,a) => {
      console.log("Received ev-blur", a);
      // ... do something here that e.g. modifies the address bar background
});

Everything I tried sends the response back to the renderer which emitted the event, which does not really help me.

Can you give me a hint on how to achieve this?

Cheers

sentialx commented 3 years ago

Hi, now we don't use ipcMain or ipcRenderer, but a wrapper around these two @wexond/rpc-electron. You can read the docs here: https://github.com/wexond/browser-base/blob/master/docs/development.md#ipc

If you want to notify a renderer that a blur or focus event occurred, I would create a listener to BrowserWindow blur event and then use windowRendererChannel.getInvoker(browserWindow.webContents).onBlur() and handle that IPC message in the renderer process.