Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement how to serve two windows #33

Open
kuworking opened this issue Feb 18, 2023 · 5 comments
Open

Implement how to serve two windows #33

kuworking opened this issue Feb 18, 2023 · 5 comments

Comments

@kuworking
Copy link

kuworking commented Feb 18, 2023

It is not possible (is it? I've been trying for a while now and have concluded it is not) to serve two different directories when the electron app has two windows.

Something like this

const loadURLOne = serve({ directory: 'one' })
const loadURLTwo = serve({ directory: 'two' })

function createWindow() {
  const oneWindow = new BrowserWindow({
    width: 1800,
    height: 1600,
  })

  const twoWindow = new BrowserWindow({
    width: 1800,
    height: 1600,
  })

  if (isDev) {
    oneWindow.loadURL('http://localhost:3000/one')
    twoWindow.loadURL('http://localhost:3000/two')
  } else {
    loadURLOne(oneWindow)
    loadURLTwo(twoWindow)
  }

This in dev works as expected (the localhost is an astro site)
But in build I can only get two windows opened that point to the same directory (the first one).

So this would be a nice feature to have in mind, if it is feasible.

EDIT: Or a variant would be to point, instead of a directory, to a file

const loadURLOne = serve({ directory: '.', file: 'index.html' })
const loadURLTwo = serve({ directory: '.', file: 'two.html' })
@hadeeb
Copy link
Contributor

hadeeb commented Mar 29, 2023

You can use the scheme option to create 2 different roots.

const loadURLOne = serve({ directory: 'one', scheme: 'app' })
const loadURLTwo = serve({ directory: 'two', scheme: 'foo' })

@kuworking
Copy link
Author

It sort of works, but not being able to point to a file but to a folder, I get all my css lost. I would need to search them at a ../ level, but that is too messy since the folder exists at build level, but not at dev level where the css are imported within a react component. This destroys the dev experience.

So I'll keep it only working at dev level (this is an app for me anyway), but it would be great that the serve would allow to pinpoint to a specific file instead of a folder.

(Thanks!)

@mhkeller
Copy link
Contributor

See if this works for you: https://github.com/mhkeller/electron-serve/tree/custom-route

That's a branch that supports a route option. It defaults to index but you can set it to foo and it will load foo.html.

There's also a branch called query-params which supports passing those in when you call the returned function with a given window.

The main branch of my fork has both changes merged. I can put these in a PR and see if either is of interest.

@mhkeller
Copy link
Contributor

It may be possible to close this now that custom HTML file names are supported via #36

@mhkeller
Copy link
Contributor

mhkeller commented Apr 3, 2024

Since version 1.3.0, this works for me as long as I set a different schema (my files are all in the same directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants