[WIP] Add Some WindowState
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
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?
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
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 πππ
Not sure why there's an emoji there. π€£:wails:window:eventname π
@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.
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.
I can test on Linux π
I can test on Linux π
Yes, you can try, but i donΒ΄t know if it will work.
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);
}
Tested on Linux. Worked fine apart from when the window is fullscreen,
IsFullscreen()andIsMaximised()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.
Do you want to just double check with those test methods to be sure?
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.
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
Nice. Just let us know when the docs are ready and mark it ready for review π
If @stffabi has no objections with this, I think we can merge in pre v2.
Thanks for all your work on this! πI did a quick update to the docs. Let's merge this and see how we go :-)