diff --git a/v2/internal/frontend/desktop/darwin/WailsContext.h b/v2/internal/frontend/desktop/darwin/WailsContext.h index 1a2d53d5dc5..2ab018d16ab 100644 --- a/v2/internal/frontend/desktop/darwin/WailsContext.h +++ b/v2/internal/frontend/desktop/darwin/WailsContext.h @@ -65,6 +65,7 @@ struct Preferences { bool *textInteractionEnabled; bool *fullscreenEnabled; const char *applicationNameForUserAgent; + bool *enableAutoplayWithoutUserAction; }; - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)zoomable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences :(bool)enableDragAndDrop :(bool)disableWebViewDragAndDrop :(bool)disableEscapeExitsFullscreen; diff --git a/v2/internal/frontend/desktop/darwin/WailsContext.m b/v2/internal/frontend/desktop/darwin/WailsContext.m index 642c7313471..55878eab7be 100644 --- a/v2/internal/frontend/desktop/darwin/WailsContext.m +++ b/v2/internal/frontend/desktop/darwin/WailsContext.m @@ -275,6 +275,10 @@ - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable } #endif + if (preferences.enableAutoplayWithoutUserAction != NULL && *preferences.enableAutoplayWithoutUserAction) { + config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; + } + WKUserContentController* userContentController = [WKUserContentController new]; [userContentController addScriptMessageHandler:self name:@"external"]; config.userContentController = userContentController; diff --git a/v2/internal/frontend/desktop/darwin/window.go b/v2/internal/frontend/desktop/darwin/window.go index af1e53e390a..d511ae6b879 100644 --- a/v2/internal/frontend/desktop/darwin/window.go +++ b/v2/internal/frontend/desktop/darwin/window.go @@ -116,6 +116,10 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window if mac.Preferences.ApplicationNameForUserAgent != "" { preferences.applicationNameForUserAgent = c.String(mac.Preferences.ApplicationNameForUserAgent) } + + if mac.Preferences.EnableAutoplayWithoutUserAction.IsSet() { + preferences.enableAutoplayWithoutUserAction = bool2CboolPtr(mac.Preferences.EnableAutoplayWithoutUserAction.Get()) + } } zoomable = bool2Cint(!frontendOptions.Mac.DisableZoom) diff --git a/v2/pkg/options/mac/preferences.go b/v2/pkg/options/mac/preferences.go index 0800124726e..621fb186415 100644 --- a/v2/pkg/options/mac/preferences.go +++ b/v2/pkg/options/mac/preferences.go @@ -24,4 +24,9 @@ type Preferences struct { // (e.g. YouTube embed) reject the default identifier. Leave empty to keep // Wails' default behaviour. ApplicationNameForUserAgent string + // EnableAutoplayWithoutUserAction allows media to start playing automatically + // without requiring a user gesture. When unset or false, WebKit's default + // behaviour is preserved (gesture required). + // Maps to WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback. + EnableAutoplayWithoutUserAction u.Bool }