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

Support Multiple Windows #1480

Closed
leaanthony opened this issue Jun 22, 2022 · 47 comments
Closed

Support Multiple Windows #1480

leaanthony opened this issue Jun 22, 2022 · 47 comments
Labels
Enhancement New feature or request TODO The issue is ready to be developed v3

Comments

@leaanthony
Copy link
Member

leaanthony commented Jun 22, 2022

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)
@leaanthony leaanthony added the Enhancement New feature or request label Jun 22, 2022
@leaanthony leaanthony added this to the v2.2 milestone Jun 22, 2022
@KiddoV
Copy link
Contributor

KiddoV commented Jul 2, 2022

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
Copy link
Member Author

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 👍

@leaanthony leaanthony added the TODO The issue is ready to be developed label Jul 3, 2022
@KiddoV
Copy link
Contributor

KiddoV commented Jul 3, 2022

@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
Copy link
Member Author

Some people wouldn't agree 😄 but having the option is good.

@askie
Copy link

askie commented Jul 3, 2022

+1
one app need Multiple Windows

@aneeskA
Copy link

aneeskA commented Jul 16, 2022

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
Copy link

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

@skypiaoyizhe
Copy link

期待支持多窗口

@santanamic
Copy link

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
Copy link

aneeskA commented Oct 16, 2022

@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
Copy link

aneeskA commented Oct 16, 2022

@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
Copy link

@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
Copy link

@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
Copy link
Member Author

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
Copy link

santanamic commented Oct 17, 2022

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
Copy link

aneeskA commented Oct 17, 2022

@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
Copy link

aneeskA commented Oct 17, 2022

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
Copy link
Contributor

mholt commented Oct 19, 2022

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
Copy link
Contributor

SamHennessy commented Oct 19, 2022

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
Copy link
Member Author

leaanthony commented Oct 19, 2022

@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
Copy link
Member Author

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

@jaunkst
Copy link

jaunkst commented Nov 16, 2022

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..

@leaanthony leaanthony modified the milestones: v2.2, v2.3.0 Nov 25, 2022
@steowens
Copy link

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
Copy link
Member Author

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 👍

@leaanthony leaanthony removed this from the v2.4.0 milestone Dec 29, 2022
@dmwin72015
Copy link

support multiple windows +1

@Korny666
Copy link

Korny666 commented Jan 19, 2023

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
Copy link

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
Copy link

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
Copy link

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
Copy link

sohaha commented Mar 26, 2023

May I ask if there are any new developments?

@crismcn
Copy link

crismcn commented Jun 19, 2023

A year has passed unknowingly.

@leaanthony leaanthony added the v3 label Jun 19, 2023
@leaanthony
Copy link
Member Author

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.

multidevtools720.mov

@Korny666
Copy link

Korny666 commented Jun 19, 2023

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
Copy link
Member Author

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

@Korny666
Copy link

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
Copy link
Member Author

leaanthony commented Jun 19, 2023

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
Copy link

maaft commented Jun 20, 2023

Is there any ETA for v3?

@leaanthony
Copy link
Member Author

leaanthony commented Jun 20, 2023

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

@leaanthony
Copy link
Member Author

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

@gilberto-009199
Copy link

thanks

@xiaobingcaicai
Copy link

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

when will v3 release?

@leaanthony
Copy link
Member Author

When it's ready.

@safareli
Copy link

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

@almas1992
Copy link
Contributor

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
Copy link

c1ngular commented Mar 5, 2024

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

@leaanthony
Copy link
Member Author

Worth asking on the discord channel rather than this closed ticket 👍

@c1ngular
Copy link

c1ngular commented Mar 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request TODO The issue is ready to be developed v3
Projects
None yet
Development

No branches or pull requests