wails icon indicating copy to clipboard operation
wails copied to clipboard

[WIP] Add Some WindowState

Open zandercodes opened this issue 3 years ago β€’ 6 comments

Add Some WindowStates, States not tested.

Issue: #1348

  • [x] Implement window state as a native event
  • [x] Testing on Windows
  • [x] Testing on macOS
  • [ ] Fixing Merge conflicts
  • [ ] Testing on Linux
  • [ ] Documetation

zandercodes avatar Apr 24 '22 13:04 zandercodes

Great stuff! Thanks for all this hard work. I'm wondering if, at the API level, we should have WindowGetState() that returns a WindowState type (int). It would cut the number of functions needed down quite significantly. We could use the IsWindow* methods behind the scenes to determine this. Thoughts?

leaanthony avatar Apr 27 '22 20:04 leaanthony

That would be optimal for Windows. But I don't know how it is on macOS or Linux. I think it might be a possibility to offer this as a separate event as a callback when the state of the window changes.
I'll see what I can do :D

zandercodes avatar Apr 28 '22 06:04 zandercodes

I think it should work on all platforms. Great idea on the events, just use the standard EventEmit call with "wails:window:maximised" etc. That's the convention πŸ‘πŸ‘πŸ‘

leaanthony avatar Apr 28 '22 08:04 leaanthony

Not sure why there's an emoji there. 🀣:wails:window:eventname πŸ˜‚

leaanthony avatar Apr 28 '22 09:04 leaanthony

@leaanthony I thought again and looked at Electron to understand how they map this case. Electron itself also uses the native window state functions. In the javascript, the resize event is accessed and the state is retrieved from the native functions. So, the way I have this built in, I have done everything right and could be released that way. The only thing left to do, test it on macOS and Linux. Windows worked in my testing.

zandercodes avatar May 02 '22 08:05 zandercodes

Small status update. Merge conflicts are complicated to resolve.
I will delete a the merge commits and edit my last commit so that the conflicts can be fixed.
Sorry, since I'm doing this free, I can't always take care of it.

zandercodes avatar Jul 28 '22 21:07 zandercodes

I can test on Linux πŸ‘

leaanthony avatar Aug 02 '22 08:08 leaanthony

I can test on Linux πŸ‘

Yes, you can try, but i donΒ΄t know if it will work.

zandercodes avatar Aug 02 '22 09:08 zandercodes

Tested on Linux. Worked fine apart from when the window is fullscreen, IsFullscreen() and IsMaximised() are true. Pushed a quick fix for that.

I used this for testing - thought it might be useful:

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
	println("WindowIsFullscreen:", runtime.WindowIsFullscreen(a.ctx))
	println("WindowIsMaximised:", runtime.WindowIsMaximised(a.ctx))
	println("WindowIsMinimised:", runtime.WindowIsMinimised(a.ctx))
	println("WindowIsNormal:", runtime.WindowIsNormal(a.ctx))
	println("\n\n")
	return fmt.Sprintf("Hello %s, It's show time!", name)
}

and

window.WindowState = function() {
    WindowIsNormal().then((result) => {console.log("IsNormal: " + result);});
    WindowIsMinimised().then((result) => {console.log("IsMinimised: " + result);});
    WindowIsMaximised().then((result) => {console.log("IsMaximised: " + result);});
    WindowIsFullscreen().then((result) => {console.log("IsFullscreen: " + result);});
}

window.testGo = function() {
    WindowMinimise();
    setTimeout(() => {
        document.getElementsByTagName("button")[0].click();
        WindowUnminimise();
    }, 3000);
}

window.testJS = function() {
    WindowMinimise();
    setTimeout(() => {
        WindowState();
        WindowUnminimise();
    }, 3000);
}

leaanthony avatar Aug 02 '22 20:08 leaanthony

Tested on Linux. Worked fine apart from when the window is fullscreen, IsFullscreen() and IsMaximised() are true. Pushed a quick fix for that.

I used this for testing - thought it might be useful:

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
	println("WindowIsFullscreen:", runtime.WindowIsFullscreen(a.ctx))
	println("WindowIsMaximised:", runtime.WindowIsMaximised(a.ctx))
	println("WindowIsMinimised:", runtime.WindowIsMinimised(a.ctx))
	println("WindowIsNormal:", runtime.WindowIsNormal(a.ctx))
	println("\n\n")
	return fmt.Sprintf("Hello %s, It's show time!", name)
}

and

window.WindowState = function() {
    WindowIsNormal().then((result) => {console.log("IsNormal: " + result);});
    WindowIsMinimised().then((result) => {console.log("IsMinimised: " + result);});
    WindowIsMaximised().then((result) => {console.log("IsMaximised: " + result);});
    WindowIsFullscreen().then((result) => {console.log("IsFullscreen: " + result);});
}

window.testGo = function() {
    WindowMinimise();
    setTimeout(() => {
        document.getElementsByTagName("button")[0].click();
        WindowUnminimise();
    }, 3000);
}

window.testJS = function() {
    WindowMinimise();
    setTimeout(() => {
        WindowState();
        WindowUnminimise();
    }, 3000);
}

Thanks for testing and fixing :D

I'll finish the documentation for the website and then we can merge it.

zandercodes avatar Aug 03 '22 07:08 zandercodes

Do you want to just double check with those test methods to be sure?

leaanthony avatar Aug 03 '22 08:08 leaanthony

Do you want to just double check with those test methods to be sure?

Good idea. I will test it again on windows and macos. So that we are sure that they really work.

zandercodes avatar Aug 03 '22 08:08 zandercodes

Do you want to just double check with those test methods to be sure?

Good idea. I will test it again on windows and macos. So that we are sure that they really work.

@leaanthony Works well on Windows and Mac

zandercodes avatar Aug 08 '22 06:08 zandercodes

Nice. Just let us know when the docs are ready and mark it ready for review πŸ‘

leaanthony avatar Aug 08 '22 07:08 leaanthony

If @stffabi has no objections with this, I think we can merge in pre v2.

leaanthony avatar Aug 23 '22 10:08 leaanthony

Thanks for all your work on this! πŸ™I did a quick update to the docs. Let's merge this and see how we go :-)

leaanthony avatar Aug 29 '22 20:08 leaanthony