Added EnabledFeatures and DisabledFeatures options

This commit is contained in:
Lea Anthony 2024-12-06 17:17:22 +11:00
commit 459b5e1036
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
3 changed files with 25 additions and 21 deletions

View file

@ -31,7 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `GeneralAutofillEnabled` and `PasswordAutosaveEnabled` Windows options by [leaanthony](https://github.com/leaanthony) in [#3766](https://github.com/wailsapp/wails/pull/3766)
- Added the ability to retrieve the window calling a service method by [leaanthony](https://github.com/leaanthony)
in [#3888](https://github.com/wailsapp/wails/pull/3888)
- Added `EnabledFeatures` and `DisabledFeatures` options for Webview2 by [leaanthony](https://github.com/leaanthony).
-
### Changed
- `service.OnStartup` now shutdowns the application on error and runs `service.OnShutdown`for any prior services that started by @atterpac in [#3920](https://github.com/wailsapp/wails/pull/3920)
- Refactored systray click messaging to better align with user interactions by @atterpac in [#3907](https://github.com/wailsapp/wails/pull/3907)
@ -45,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Consolidated dev config into `config.yml` by [leaanthony](https://github.com/leaanthony)
- Systray dialog now defaults to the application icon if available (Windows) by [@leaanthony](https://github.com/leaanthony)
- Better reporting of GPU + Memory for macOS by [@leaanthony](https://github.com/leaanthony)
- Removed `WebviewGpuIsDisabled` and `EnableFraudulentWebsiteWarnings` (superseded by `EnabledFeatures` and `DisabledFeatures` options) by [leaanthony](https://github.com/leaanthony)
### Fixed
- Fixed deadlock in Linux dialog for multiple selections caused by unclosed channel variable by @michael-freling in [#3925](https://github.com/wailsapp/wails/pull/3925)

View file

@ -252,10 +252,6 @@ type WindowsWindow struct {
// Default: false
WindowMaskDraggable bool
// WebviewGpuIsDisabled is used to enable / disable GPU acceleration for the webview
// Default: false
WebviewGpuIsDisabled bool
// Disable the menu bar for this window
// Default: false
DisableMenu bool
@ -272,10 +268,6 @@ type WindowsWindow struct {
// Default: false
EnableSwipeGestures bool
// EnableFraudulentWebsiteWarnings will enable warnings for fraudulent websites.
// Default: false
EnableFraudulentWebsiteWarnings bool
// Menu is the menu to use for the window.
Menu *Menu
@ -294,6 +286,14 @@ type WindowsWindow struct {
// PasswordAutosaveEnabled enables autosaving passwords
PasswordAutosaveEnabled bool
// EnabledFeatures and DisabledFeatures are used to enable or disable specific features in the WebView2 browser.
// Available flags: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/webview-features-flags?tabs=dotnetcsharp#available-webview2-browser-flags
// WARNING: Apps in production shouldn't use WebView2 browser flags,
// because these flags might be removed or altered at any time,
// and aren't necessarily supported long-term.
EnabledFeatures []string
DisabledFeatures []string
}
type Theme int

View file

@ -1410,25 +1410,27 @@ func (w *windowsWebviewWindow) setupChromium() {
}
globalApplication.capabilities = capabilities.NewCapabilities(webview2version)
disableFeatues := []string{}
if !opts.EnableFraudulentWebsiteWarnings {
disableFeatues = append(disableFeatues, "msSmartScreenProtection")
}
if opts.WebviewGpuIsDisabled {
chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, "--disable-gpu")
}
// We disable this by default. Can be overridden with the `EnableFraudulentWebsiteWarnings` option
opts.DisabledFeatures = append(opts.DisabledFeatures, "msSmartScreenProtection")
if len(disableFeatues) > 0 {
arg := fmt.Sprintf("--disable-features=%s", strings.Join(disableFeatues, ","))
if len(opts.DisabledFeatures) > 0 {
opts.DisabledFeatures = lo.Uniq(opts.DisabledFeatures)
arg := fmt.Sprintf("--disable-features=%s", strings.Join(opts.DisabledFeatures, ","))
chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg)
}
enableFeatures := []string{"msWebView2BrowserHitTransparent"}
if len(enableFeatures) > 0 {
arg := fmt.Sprintf("--enable-features=%s", strings.Join(enableFeatures, ","))
if len(opts.EnabledFeatures) > 0 {
opts.EnabledFeatures = lo.Uniq(opts.EnabledFeatures)
arg := fmt.Sprintf("--enable-features=%s", strings.Join(opts.EnabledFeatures, ","))
chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg)
}
////enableFeatures := []string{"msWebView2BrowserHitTransparent"}
//if len(enableFeatures) > 0 {
// arg := fmt.Sprintf("--enable-features=%s", strings.Join(enableFeatures, ","))
// chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg)
//}
chromium.DataPath = globalApplication.options.Windows.WebviewUserDataPath
chromium.BrowserPath = globalApplication.options.Windows.WebviewBrowserPath