mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Add Center
Add more events
This commit is contained in:
parent
d5e21d5003
commit
a134bfac42
7 changed files with 98 additions and 5 deletions
|
|
@ -71,6 +71,7 @@ func main() {
|
|||
myWindow2.NavigateToURL("https://wails.io")
|
||||
myWindow.SetMinSize(600, 600)
|
||||
myWindow.SetMaxSize(650, 650)
|
||||
myWindow.Center()
|
||||
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,34 @@
|
|||
systemEventHandler(EventApplicationWillTerminate);
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
|
||||
{
|
||||
systemEventHandler(EventApplicationDidBecomeActive);
|
||||
}
|
||||
|
||||
- (void)applicationWillHide:(NSNotification *)aNotification
|
||||
{
|
||||
systemEventHandler(EventApplicationWillHide);
|
||||
}
|
||||
|
||||
- (void)applicationDidHide:(NSNotification *)aNotification
|
||||
{
|
||||
systemEventHandler(EventApplicationDidHide);
|
||||
}
|
||||
|
||||
- (void)applicationWillUnhide:(NSNotification *)aNotification
|
||||
{
|
||||
systemEventHandler(EventApplicationWillUnhide);
|
||||
}
|
||||
|
||||
- (void)applicationDidUnhide:(NSNotification *)aNotification
|
||||
{
|
||||
systemEventHandler(EventApplicationDidUnhide);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -26,6 +26,7 @@ type windowImpl interface {
|
|||
restore()
|
||||
setBackgroundColor(color *options.RGBA)
|
||||
run()
|
||||
center()
|
||||
}
|
||||
|
||||
type Window struct {
|
||||
|
|
@ -209,3 +210,10 @@ func (w *Window) handleMessage(message string) {
|
|||
w.SetTitle("Hello World")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) Center() {
|
||||
if w.impl == nil {
|
||||
return
|
||||
}
|
||||
w.impl.center()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -399,6 +399,20 @@ void windowSetAppearanceTypeByName(void* nsWindow, const char *appearanceName) {
|
|||
});
|
||||
}
|
||||
|
||||
// Center window on current monitor
|
||||
void windowCenter(void* nsWindow) {
|
||||
// Center window on main thread
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// get main window
|
||||
NSWindow* window = (NSWindow*)nsWindow;
|
||||
[window center];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
|
|
@ -413,6 +427,10 @@ type macosWindow struct {
|
|||
options *options.Window
|
||||
}
|
||||
|
||||
func (w *macosWindow) center() {
|
||||
C.windowCenter(w.nsWindow)
|
||||
}
|
||||
|
||||
func (w *macosWindow) isMinimised() bool {
|
||||
return C.windowIsMinimised(w.nsWindow) == C.bool(true)
|
||||
}
|
||||
|
|
@ -537,6 +555,8 @@ func (w *macosWindow) run() {
|
|||
}
|
||||
|
||||
}
|
||||
C.windowCenter(w.nsWindow)
|
||||
|
||||
if w.options.URL != "" {
|
||||
w.navigateToURL(w.options.URL)
|
||||
}
|
||||
|
|
@ -550,3 +570,7 @@ func (w *macosWindow) setBackgroundColor(colour *options.RGBA) {
|
|||
}
|
||||
C.webviewSetBackgroundColor(w.nsWindow, C.int(colour.Red), C.int(colour.Green), C.int(colour.Blue), C.int(colour.Alpha))
|
||||
}
|
||||
|
||||
func (w *macosWindow) Center() {
|
||||
C.windowCenter(w.nsWindow)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,29 @@ package events
|
|||
var Mac = newMacEvents()
|
||||
|
||||
type macEvents struct {
|
||||
ApplicationDidFinishLaunching string
|
||||
ApplicationWillTerminate string
|
||||
ApplicationDidFinishLaunching string
|
||||
ApplicationWillTerminate string
|
||||
ApplicationDidBecomeActive string
|
||||
ApplicationWillUpdate string
|
||||
ApplicationDidUpdate string
|
||||
ApplicationWillFinishLaunching string
|
||||
ApplicationWillHide string
|
||||
ApplicationWillUnhide string
|
||||
ApplicationDidHide string
|
||||
ApplicationDidUnhide string
|
||||
}
|
||||
|
||||
func newMacEvents() macEvents {
|
||||
return macEvents{
|
||||
ApplicationDidFinishLaunching: "mac:ApplicationDidFinishLaunching",
|
||||
ApplicationWillTerminate: "mac:ApplicationWillTerminate",
|
||||
ApplicationDidFinishLaunching: "mac:ApplicationDidFinishLaunching",
|
||||
ApplicationWillTerminate: "mac:ApplicationWillTerminate",
|
||||
ApplicationDidBecomeActive: "mac:ApplicationDidBecomeActive",
|
||||
ApplicationWillUpdate: "mac:ApplicationWillUpdate",
|
||||
ApplicationDidUpdate: "mac:ApplicationDidUpdate",
|
||||
ApplicationWillFinishLaunching: "mac:ApplicationWillFinishLaunching",
|
||||
ApplicationWillHide: "mac:ApplicationWillHide",
|
||||
ApplicationWillUnhide: "mac:ApplicationWillUnhide",
|
||||
ApplicationDidHide: "mac:ApplicationDidHide",
|
||||
ApplicationDidUnhide: "mac:ApplicationDidUnhide",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@ extern void systemEventHandler(char*);
|
|||
|
||||
#define EventApplicationDidFinishLaunching "mac:ApplicationDidFinishLaunching"
|
||||
#define EventApplicationWillTerminate "mac:ApplicationWillTerminate"
|
||||
#define EventApplicationDidBecomeActive "mac:ApplicationDidBecomeActive"
|
||||
#define EventApplicationWillUpdate "mac:ApplicationWillUpdate"
|
||||
#define EventApplicationDidUpdate "mac:ApplicationDidUpdate"
|
||||
#define EventApplicationWillFinishLaunching "mac:ApplicationWillFinishLaunching"
|
||||
#define EventApplicationWillHide "mac:ApplicationWillHide"
|
||||
#define EventApplicationWillUnhide "mac:ApplicationWillUnhide"
|
||||
#define EventApplicationDidHide "mac:ApplicationDidHide"
|
||||
#define EventApplicationDidUnhide "mac:ApplicationDidUnhide"
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,2 +1,10 @@
|
|||
mac:ApplicationDidFinishLaunching
|
||||
mac:ApplicationWillTerminate
|
||||
mac:ApplicationWillTerminate
|
||||
mac:ApplicationDidBecomeActive
|
||||
mac:ApplicationWillUpdate
|
||||
mac:ApplicationDidUpdate
|
||||
mac:ApplicationWillFinishLaunching
|
||||
mac:ApplicationWillHide
|
||||
mac:ApplicationWillUnhide
|
||||
mac:ApplicationDidHide
|
||||
mac:ApplicationDidUnhide
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue