Skip to content

Commit

Permalink
[darwin] Support Ignore mouse events
Browse files Browse the repository at this point in the history
[darwin] Support applicationSupportsSecureRestorableState
Update video example
  • Loading branch information
leaanthony committed Oct 29, 2023
1 parent daec8a9 commit 985c5bf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
8 changes: 2 additions & 6 deletions v3/examples/video/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ go 1.21

toolchain go1.21.0

require (
github.com/wailsapp/go-webview2 v1.0.9
github.com/wailsapp/wails/v3 v3.0.0-alpha.0
)
require github.com/wailsapp/wails/v3 v3.0.0-alpha.0

require (
github.com/Microsoft/go-winio v0.4.16 // indirect
Expand Down Expand Up @@ -37,6 +34,7 @@ require (
github.com/rivo/uniseg v0.4.4 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/wailsapp/go-webview2 v1.0.9 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
Expand All @@ -47,5 +45,3 @@ require (
)

replace github.com/wailsapp/wails/v3 => ../..

replace github.com/wailsapp/go-webview2 => D:\GolandProjects\go-webview2
2 changes: 2 additions & 0 deletions v3/examples/video/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/wailsapp/go-webview2 v1.0.9 h1:lrU+q0cf1wgLdR69rN+ZnRtMJNaJRrcQ4ELxoO7/xjs=
github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
Expand Down
3 changes: 3 additions & 0 deletions v3/examples/video/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func main() {
BackgroundColour: application.NewRGB(33, 37, 41),
Mac: application.MacWindow{
DisableShadow: true,
WebviewPreferences: application.MacWebviewPreferences{
FullscreenEnabled: application.Enabled,
},
},
HTML: "<video controls width=\"500\" >\n <source\n src=\"https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm\"\n type=\"video/webm\"\n />\n <source\n src=\"https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4\"\n type=\"video/mp4\"\n />\n </video>",
})
Expand Down
11 changes: 0 additions & 11 deletions v3/examples/window/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"math/rand"
"os"
"runtime"
"strconv"
"time"
Expand Down Expand Up @@ -400,16 +399,6 @@ func main() {
_ = w.Print()
})
})
printMenu.Add("Capture PNG").OnClick(func(ctx *application.Context) {
currentWindow(func(w *application.WebviewWindow) {
img, err := w.CapturePNG()
if err != nil {
application.ErrorDialog().SetTitle("Error").SetMessage(err.Error()).Show()
return
}
os.WriteFile("capture.png", img, 0644)
})
})

app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
BackgroundColour: application.NewRGB(33, 37, 41),
Expand Down
1 change: 1 addition & 0 deletions v3/pkg/application/application_darwin_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@interface AppDelegate : NSObject <NSApplicationDelegate>
@property bool shouldTerminateWhenLastWindowClosed;
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app;
@end

#endif
8 changes: 7 additions & 1 deletion v3/pkg/application/application_darwin_delegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ - (void)themeChanged:(NSNotification *)notification {
processApplicationEvent(EventApplicationDidChangeTheme, NULL);
}
}
- (BOOL)applicationShouldHandleReopen:(NSNotification *)notification

- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
{
return YES;
}

- (BOOL)applicationShouldHandleReopen:(NSNotification *)notification
hasVisibleWindows:(BOOL)flag {
if( hasListeners(EventApplicationShouldHandleReopen) ) {
processApplicationEvent(EventApplicationShouldHandleReopen, @{@"hasVisibleWindows": @(flag)});
Expand Down
10 changes: 9 additions & 1 deletion v3/pkg/application/webview_window_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,11 @@ static void windowShowMenu(void *window, void *menu, int x, int y) {
[nsMenu popUpMenuPositioningItem:nil atLocation:point inView:webView];
}
// windowIgnoreMouseEvents makes the window ignore mouse events
static void windowIgnoreMouseEvents(void *window, bool ignore) {
WebviewWindow* nsWindow = (WebviewWindow*)window;
[nsWindow setIgnoresMouseEvents:ignore];
}
// Make the given window frameless
static void windowSetFrameless(void *window, bool frameless) {
Expand Down Expand Up @@ -1112,6 +1116,10 @@ func (w *macosWebviewWindow) run() {
C.webviewSetTransparent(w.nsWindow)
}

if options.IgnoreMouseEvents {
C.windowIgnoreMouseEvents(w.nsWindow, C.bool(true))
}

titleBarOptions := macOptions.TitleBar
if !w.parent.options.Frameless {
C.windowSetTitleBarAppearsTransparent(w.nsWindow, C.bool(titleBarOptions.AppearsTransparent))
Expand Down

0 comments on commit 985c5bf

Please sign in to comment.