[help] how to open SPA(ember app) route in electron

Hey @Zorig, one window is probably ideal because with two windows you have two whole separate application instances running with all their own concerns and window behavior and coordinating them is a pain. Our app gives the user the ability to open multiple (theoretically unlimited) windows and it’s kind of a mess. So from what you described I’d recommend the latter scenario where you do a redirect.

Essentially you’ll need to set up an IPC messaging system so you can send messages back and forth from the mainWindow (a BrowserWindow object) to the Ember application. Your ember app will use IPC renderer module and your main thread code will use IPC main module.

First of all if you’re using ember-electron it will do some of the work for you, if not you’ll need to figure out how you want to handle the require collision. Basically I’d recommend using ember-electron for that and other reasons. In your Ember app you’ll need to require the ipcRenderer package from electron (via requireNode, not regular), something like this:

let { ipcRenderer } = requireNode('electron');

In our case we did all the IPC stuff in a service because we use our app both in and out of electron. If your case is simpler, which it sounds like, you may just want to do this in the application route/controller. If you’d like I can share a rough sketch of the service that we use which is mostly courtesy of @bendemboski on slack, but that may be overkill for you. Anyway, next you want to set up a listener to listen for messages on the ipcRenderer module, something like:

ipcRenderer.on("toggle-mini-player", (name, <args>) => {
  // handle the 'toggle-mini-player' event here, with the args you pass from ipcMain, if any
});

Next you’ll write the code to send a message to the ember app. Actually you don’t even need ipc main for this, you just have to say mainWindow.send('toggle-mini-player', <args>) to send a message to that window’s renderer process.

Anyway, sorry if that’s a little convoluted. I found the ipc stuff confusing as first but once you get it set up it’s awesome.