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

Why does Fyne close application if no Windows are shown? #1080

Closed
ababo opened this issue Jun 5, 2020 · 12 comments
Closed

Why does Fyne close application if no Windows are shown? #1080

ababo opened this issue Jun 5, 2020 · 12 comments

Comments

@ababo
Copy link

ababo commented Jun 5, 2020

I would like to have an app event loop running while I open and close windows without exiting with a last window? What's behind this design decision and how can I overpass this behaviour? Thanks in advance.

@andydotxyz
Copy link
Member

In most desktop operating systems closing the last window closes the app.
Can I assume you are a macOS user? That is the only one that I know has some apps stay open after last window closes.
More information about your platform would help us to consider this issue.
However I think that we will always have to compromise between cross platform consistency and matching OS expectations. on Mobile apps we don't quit when the window hides, so this is certainly a place we can explore more.

@ababo
Copy link
Author

ababo commented Jun 5, 2020

Can I hide the main window instead of closing it?

@andydotxyz
Copy link
Member

There is an ongoing discussion in this area - but unless the user can tell the difference I’m not sure that it seems like a good idea. What is the difference between closed and hidden for a user, how can they bring them back?

As I said before the more we can know about your platform and why this is important the more it can inform the discussion.

@andydotxyz
Copy link
Member

I am going to close this as a duplicate of #467 - if you intercept the close and call Hide() instead the behaviour you desire will be possible.
How the window becomes un-hidden is of course another question, but I suspect you have designed the workflow already.

@guillermo
Copy link

guillermo commented Aug 10, 2020

I leave this to document a use case:

TLDR: My app show/hide flow is through a trayicon.

Use case:

The app manages a dev environment where:

  • A API server is started and can be started stoped in different modes through the fyne window
  • A web server is started and can be started, stoped in different modes through the fyne window.
  • Several clients are started. Also started and stoped through the fyne window.

Once launched the application, the app shows a try icon. On press of the tray icon, it shows the fyne window. Upon close, the trayicon is show again.

The app flows as this:

  1. AppManager init. (where all the servers are started).
  2. fyne is setup and called with Run().
  3. Trayicon is called and the go program waits until closed.
  4. Call to win.Show().

Then the app exists... and don't know how to restart the UI within the same process.

@andydotxyz
Copy link
Member

the call to App.Run() will return when all windows are closed.
Either:

*) Use Window.Hide() (and with #467 you could do the same wind user closes the window)
*) Use Window.ShowAndRun() and put it in a loop until you truly want to quit.

@zsr228
Copy link

zsr228 commented Jun 8, 2021

@andydotxyz I have the same query as @ababo
An app.Run() with two windows, one is Window.Hide(), the other is Window.Show(), when I close the showed window, the app is quit. I don't know whether it's expected.

var appTest fyne.App

func gen(isHide bool) {
	w := appTest.NewWindow("Hello")

	if isHide {
		w.SetContent(widget.NewLabel("Hello Hide Fyne!"))
		w.SetMaster()
		w.Hide()
	} else {
		w.SetContent(widget.NewLabel("Hello Show Fyne!"))
		w.Show()
	}
}


func main() {
	appTest = app.New()
	gen(true)
	gen(false) // close this window app will quit

	appTest.Run()
}

Sorry,I use App.Run() and Window.Run(), when I use App.Run() and Window.ShowAndRun() it works.

@andydotxyz
Copy link
Member

That is expected. As listed above you can use Window.Hide() instead of Window.Close() to keep the app alive.
If you want to deal with user closing the window and still staying open then Window.SetCloseIntercept() will allow you to intercept and call Hide in place of Close in the callback.

@zsr228
Copy link

zsr228 commented Jun 9, 2021

That is expected. As listed above you can use Window.Hide() instead of Window.Close() to keep the app alive.
If you want to deal with user closing the window and still staying open then Window.SetCloseIntercept() will allow you to intercept and call Hide in place of Close in the callback.

Okay, It means fyne doesn't support new a window in hidden status,but can be hidden by the user's click. Thanks a lot.

@andydotxyz
Copy link
Member

I don’t understand why you think this means a window can’t be created hidden? This is absolutely possible - just don’t call Show when you create the window.

@zsr228
Copy link

zsr228 commented Jun 9, 2021

I'm not express clear, I want a master window created in hidden default, other windows can be closed.
The following code, If close all showed window app is quit, where the hidden window is?

var appTest fyne.App

func gen(isHide bool) {
	w := appTest.NewWindow("Hello")

	if isHide {
		w.SetContent(widget.NewLabel("Hello Hide Fyne!"))
		w.SetMaster()
		//w.Show()
	} else {
		w.SetContent(widget.NewLabel("Hello Show Fyne!"))
		w.Show()
	}
}

func main() {
	appTest = app.New()
	gen(true)
	go func() {
		for {
			time.Sleep(10 * time.Second)
			gen(false) 
		}
	}()
        appTest.Run()
}

@andydotxyz
Copy link
Member

That code has forgotten to call Run, which you need to do at the end of your main.

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

4 participants