diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 20f0b30dc..46bab8511 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -767,8 +767,7 @@ func (a *App) runOrDeferToAppRun(r runnable) { } func (a *App) processKeyBinding(acceleratorString string, window *WebviewWindow) bool { - - if a.keyBindings == nil { + if len(a.keyBindings) == 0 { return false } diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index e145d916b..35f3ad5ee 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -1096,20 +1096,17 @@ func (w *WebviewWindow) SetAbsolutePosition(x int, y int) { } func (w *WebviewWindow) processKeyBinding(acceleratorString string) bool { - - if w.keyBindings == nil { - return false - } - // Check key bindings - callback, ok := w.keyBindings[acceleratorString] - if !ok { - return globalApplication.processKeyBinding(acceleratorString, w) - } - // Execute callback - go callback(w) + if w.keyBindings != nil { + if callback := w.keyBindings[acceleratorString]; callback != nil { + // Execute callback + go callback(w) - return true + return true + } + } + + return globalApplication.processKeyBinding(acceleratorString, w) } func (w *WebviewWindow) HandleKeyEvent(acceleratorString string) { diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index bbe99aa12..b53369141 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -1289,14 +1289,9 @@ func (w *windowsWebviewWindow) setupChromium() { globalApplication.capabilities = capabilities.NewCapabilities(webview2version) disableFeatues := []string{} - if !opts.EnableFraudulentWebsiteWarnings { disableFeatues = append(disableFeatues, "msSmartScreenProtection") } - - chromium.DataPath = globalApplication.options.Windows.WebviewUserDataPath - chromium.BrowserPath = globalApplication.options.Windows.WebviewBrowserPath - if opts.WebviewGpuIsDisabled { chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, "--disable-gpu") } @@ -1306,6 +1301,15 @@ func (w *windowsWebviewWindow) setupChromium() { 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 + if opts.Permissions != nil { for permission, state := range opts.Permissions { chromium.SetPermission(edge.CoreWebView2PermissionKind(permission), @@ -1547,9 +1551,6 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool { globalApplication.debug("Processing key binding", "vkey", vkey) - if len(w.parent.keyBindings) == 0 { - return false - } // Get the keyboard state and convert to an accelerator var keyState [256]byte if !w32.GetKeyboardState(keyState[:]) { @@ -1584,9 +1585,20 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool { acc.Key = accKey } - // Process the key binding - return w.parent.processKeyBinding(acc.String()) + accKey := acc.String() + globalApplication.debug("Processing key binding", "vkey", vkey, "acc", accKey) + // Process the key binding + if w.parent.processKeyBinding(accKey) { + return true + } + + if accKey == "alt+f4" { + w32.PostMessage(w.hwnd, w32.WM_CLOSE, 0, 0) + return true + } + + return false } func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(message string, sender *edge.ICoreWebView2, args *edge.ICoreWebView2WebMessageReceivedEventArgs) {