wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
24.6k stars 1.18k forks source link

Support Multiple Windows #1480

Closed leaanthony closed 1 year ago

leaanthony commented 2 years ago

Is your feature request related to a problem? Please describe.

We'd like to support multiple windows and improve the current window APIs to support it.

Describe the solution you'd like

A window-centric API eg:

  app := wails.CreateApp(appOptions)
  mainWindow := app.CreateWindow(windowOptions)
  childWindow := mainWindow.CreateWindow(windowOptions)
KiddoV commented 2 years ago

Can you also support custom dialog windows as an HTML? So that the dialog windows will all match with the application window theme which is already styled in HTML and CSS?

leaanthony commented 2 years ago

Hey @KiddoV - what's driving this requirement? Is it Webview2 showing light dialogs in dark mode? That's a known bug on their end. If not, please open another ticket so we don't mix up the conversation πŸ‘

KiddoV commented 2 years ago

@leaanthony no, I was just wondering if we can have a way to customize the dialog boxes like a message box using CSS and HTML. With the help of Wails, we build the app main window with full of HTML and CSS, so , calling a dialog box with the default OS theme seem a bit ...odd.

So, instead of: basic-window This looks better, don't you think? styled-window

I know, I know... that I can make a modal within the webview window and call it done, but having a separate dialog window would be awesome.

leaanthony commented 2 years ago

Some people wouldn't agree πŸ˜„ but having the option is good.

askie commented 2 years ago

+1 one app need Multiple Windows

aneeskA commented 2 years ago

Yes, this would unlock the true potential of wails. πŸ’ͺ I discovered wails today and super pumped to learn and create. Thanks for this excellent effort.

Deepfried-Chips commented 2 years ago

genuinely looking forward to this, something like this would be a lifesaver especially for a screenshotting tool

skypiaoyizhe commented 2 years ago

ζœŸεΎ…ζ”―ζŒε€šηͺ—口

santanamic commented 2 years ago

To support multiple windows, I'm treating each window as a different executable.

My project structure looks like this

--MyApp
--splash.exe //Splash screen. After 5 seconds this screen is automatically closed and the projects screen is opened
--projects.exe //Screen to list saved projects. When a project is selected, the project editing screen opens
--editor.exe //Playground to edit a project

1 - The screens are opened via cmd inside the executables. 2 - With the flag library it is possible to pass custom parameters before execution.

path, _ := os.Getwd()
cmd := exec.Command(path+"\\editor.exe", "-project=xxxx")
...

This is a simple and limited solution, but it suits my use case.

aneeskA commented 1 year ago

@santanamic Why didn't I think of this! :)

I tried this just now in my Mac and realised that this created two apps in the taskbar. For example:

image

Do you have a way to make it not do this?

aneeskA commented 1 year ago

@santanamic To give context, this is what I did to the template app. Please ignore the messy code; it is written to confirm my understanding.

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
    dir, err := os.Getwd()
    if err != nil {
        fmt.Println(err.Error())
    }
    fmt.Println("directory=", dir)
    err = exec.Command(dir + "/kuit").Run()
    if err != nil {
        fmt.Println(err.Error())
    }
    return fmt.Sprintf("Hello %s, It's show time!", name)
}
santanamic commented 1 year ago

@aneeskA You can open a native webview window.

<a href="#" id="open-popup">open popup</a>

(() => { let id = document.getElementById("open-popup"); id.addEventListener("click", function(event){ let popupWindow = window.open("", 'myWindow', "width=800,height=500,left=283,top=134,location=no,menubar=no,scrollbars=no,resizable=no,status=no,titlebar=no,toolbar=no"); popupWindow.document.write("<html><body>123...</body></html>"); }); })();

The problem is the fixed URL bar

image

window.open accepts some parameters. Most unfortunately don't work.

santanamic commented 1 year ago

@santanamic Why didn't I think of this! :)

I tried this just now in my Mac and realised that this created two apps in the taskbar. For example:

image

Do you have a way to make it not do this?

You can also reopen the current window. πŸ˜…

cmd := exec.Command(path+"\self.exe", "-screen=editor")

The screen argument must receive the name of the view and do the proper logic for execution.

This way it is possible to work with only 1 executable.

I hadn't noticed this simplicity. I believe Multiple Windows support can be based on this? @leaanthony

@aneeskA Please if this runs successfully on the mec let me know.

leaanthony commented 1 year ago

Great workaround πŸ‘ Multiple window support will allow more than 1 window to be displayed at once. Is there any reason you prefer to relaunch the app instead of just swapping out the view?

santanamic commented 1 year ago

Great workaround πŸ‘ Multiple window support will allow more than 1 window to be displayed at once. Is there any reason you prefer to relaunch the app instead of just swapping out the view?

I need for the following components

1 - Home screen/Splash screen

2 - Custom Dialogs, Configuration Forms and a Log Console

3 - Open a custom HTML outside the main editor

aneeskA commented 1 year ago

@aneeskA Please if this runs successfully on the mec let me know.

I just now tried it and it is not working as we expected in my Mac.

aneeskA commented 1 year ago

Great workaround πŸ‘ Multiple window support will allow more than 1 window to be displayed at once. Is there any reason you prefer to relaunch the app instead of just swapping out the view?

I am not sure if I understood "swapping out the view", but for me I need multiple windows to be able to do separate but related things in different windows something like a browser allows me to do. Put different but related stuff side by side to analyse data.

image
mholt commented 1 year ago

This would be great. I think all I really need is a way to open a window with window options that opens to a particular HTML file. A way to control the window would be good too (close it, move it, hide it, etc).

I'd mainly be using these for displaying logs alongside the main application, giving the user a way to provide more information (like a form), and customize the main app (like an options pane).

I think it'll be useful if windows have access to other windows, so for example the new window could change what the main window is doing.

SamHennessy commented 1 year ago

I want to have two web views in one window, allowing me to show an external website. Many sites block iframe usage, and I assume that's true with something like Wails.

I have two use cases. One use case is a live-reload app that will run a Go web app and rebuild, then reload it when something changes. This is possible with an iframe but doesn't allow me to read things like the page title or to use JavaScript to reload the page. The workaround is to use a reverse proxy. The other is a hacker news client, where I'd like to show the comments with the linked external website.

I can move this comment elsewhere if this is out of scope for Multi-Windows.

leaanthony commented 1 year ago

@mholt - I think this will be fairly trivial once we refactor out the current window code and make it more programmatic, as per the system tray API. I imagine this being something like:

logWindow := application.NewWindow(...)

// Store wherever you want

logWindow.Resize() // etc
leaanthony commented 1 year ago

@SamHennessy I'd make that a different request. I think you're wanting more flexibility around containers within the same window?

jaunkst commented 1 year ago

I have another use case. I am pushing windows to another embedded wayland compositor and I would like to share state between them in goland. Multiple windows could allow me to manage everything from a single runtime.

I could use a single view but I will need to manage window properties and focus as there are other wayland surfaces that are rendering other applications..

steowens commented 1 year ago

So I want to port a web app I was working on to Wails. One of my use cases is the ability to enter markdown in text areas. But I also provide the ability to edit the markdown in a full blown editor window that launches as a separate named tab and writes the result to local storage and sends a closed event to the launching tab when done. Then the launching tab fetches the modified markdown and replaces the text area with the new markdown. Being able to launch a separate editor window that allows communication between the two windows would be fantastic.

leaanthony commented 1 year ago

Hey @steowens - this is absolutely happening but be aware that the current API is really geared around 1 window, and that affects everything. For multiple windows, there will unavoidably be an API change but that's a good thing! I have some exciting things to announce soon so stick around πŸ‘

dmwin72015 commented 1 year ago

support multiple windows +1

Korny666 commented 1 year ago

Please Support multiple Windows:

import useChildWindow from "../wailsjs/go/main/App.js";

// the window uses a piniaStore for data exchange
let details = useChildWindow('details.vue', windowOptions);

function onShowDetails() {
  details.show();
} 
megozhang commented 1 year ago

PLZ Support multiple Windows:

import useChildWindow from "../wailsjs/go/main/App.js";

// the window uses a piniaStore for data exchange
let details = useChildWindow('details.vue', windowOptions);

function onShowDetails() {
  details.show();
} 

What's PLT?

Korny666 commented 1 year ago

PLZ Support multiple Windows:

import useChildWindow from "../wailsjs/go/main/App.js";

// the window uses a piniaStore for data exchange
let details = useChildWindow('details.vue', windowOptions);

function onShowDetails() {
  details.show();
} 

What's PLT?

I think you mean PLZ? PLZ is please in internet slang

megozhang commented 1 year ago

PLZ Support multiple Windows:

import useChildWindow from "../wailsjs/go/main/App.js";

// the window uses a piniaStore for data exchange
let details = useChildWindow('details.vue', windowOptions);

function onShowDetails() {
  details.show();
} 

What's PLT?

I think you mean PLZ? PLZ is please in internet slang

haha~,Thank you!

sohaha commented 1 year ago

May I ask if there are any new developments?

crismcn commented 1 year ago

A year has passed unknowingly.

leaanthony commented 1 year ago

Multiple windows is in v3. If anyone is interested in any updates on this then please feel free to join the discord server. This was a video made 6 months ago as a little demo. If you want to see the source code, just press pause and rewind to the start.

https://github.com/wailsapp/wails/assets/1943904/a9f92cbe-af23-4034-aa75-20c913b7f2e4

Korny666 commented 1 year ago

Is there a popout into second window feature planned? e.g. a (tab-content-)component and data (context/vars/pinia-store)? and window icon and window title and so on :)

leaanthony commented 1 year ago

Sorry, I'm not sure I understand what you mean.

Korny666 commented 1 year ago

Sorry, I'm not sure I understand what you mean.

In your example it seems that you can spawn only a clone of the root window. Not a certain subcomponent. Like a Gallery as a new window or complex toolbars as a new window would be beneficial. And then this new windows should communicate with the other data from the main window somehow. And it should be possible to give the new windows another name and icon to distinguish them. (As mentioned before)

leaanthony commented 1 year ago

Those 2 windows are entirely independent and you can have what you like in them. This was just defaulting to an external URL for demo purposes. A lot has happened in 6 months πŸš€For more discussion on this, please join the Discord server πŸ‘

maaft commented 1 year ago

Is there any ETA for v3?

leaanthony commented 1 year ago

No. I imagine Mac/Windows alpha might be out soon...

leaanthony commented 1 year ago

Multi window support has been completed for v3. Closing this.

gilberto-009199 commented 1 year ago

thanks

xiaobingcaicai commented 9 months ago

Multi window support has been completed for v3. Closing this.

when will v3 release?

leaanthony commented 9 months ago

When it's ready.

safareli commented 8 months ago

Where is it documented? checked next version of docs but can't find new api https://wails.io/docs/next/reference/runtime/window

almas1992 commented 8 months ago

Where is it documented? checked next version of docs but can't find new api https://wails.io/docs/next/reference/runtime/window

https://v3alpha.wails.io/whats-new/#multiple-windows

c1ngular commented 6 months ago

@leaanthony how would multiple windows communicate with each other , through BroadcastChannel ? window.postMessage ?

leaanthony commented 6 months ago

Worth asking on the discord channel rather than this closed ticket πŸ‘

c1ngular commented 6 months ago

@leaanthony sorry ,google search lead me here , did not realize this was closed .