#Multi Window With Svelte – How To?

5 messages · Page 1 of 1 (latest)

jolly flax
#

how would i make a new additional popover dialog which also uses svelte?
the main window would load the default index.html, what would be the best practise to load another svelte app for the second window(settings f.e.)?

my idea would be to keep everything in one svelte project and have two index.html pages which might read a static js value which is different in each index.html file...

is there a better solution?

#
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Tauri + Svelte + TS</title>
  </head>

  <body>
    <div id="app"></div>
    <script>
        window.UI_ELEMENT = "SETTINGS;" // or "MAIN" for example
    </script>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>
golden pier
#

Are you using the sveltekit starter project?

Regardless, in your rust files you will need a command to create a tauri window - see https://tauri.app/v1/guides/features/multiwindow#creating-a-window.

The WindowConfig struct contains a field for URL, with the sveltekit starter project this is the relative path to your window's landing +page.svelte.

Alternatively, you can create the window on startup by adding it to the tauri.conf.json's tauri.windows array; however, with this approach you will need to initialize it as hidden from view (using the WindowConfig.visible) property and toggle its visibility at the appropriate times with the show and hide commands - see https://docs.rs/tauri/latest/tauri/window/struct.Window.html#method.hide and https://docs.rs/tauri/latest/tauri/window/struct.Window.html#method.show.

If you are not using the sveltekit starter app, but rather a svelte vite skeleton project, you can instead use URL params and fetch them on window load at the top level of your svelte project, and switch on those params appropriately.

Manage multiple windows on a single application.

jolly flax
#

i use the default vite svelte template

#

does the tauri::WindowUrl::App("index.html".into()) support url params like ?uielement=settings ?