mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[darwin] Add webview preferences
This commit is contained in:
parent
86b6e10620
commit
255690eee0
5 changed files with 74 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ require (
|
|||
github.com/leaanthony/clir v1.6.0
|
||||
github.com/leaanthony/go-ansi-parser v1.6.1
|
||||
github.com/leaanthony/gosod v1.0.3
|
||||
github.com/leaanthony/u v1.1.0
|
||||
github.com/leaanthony/winicon v1.0.0
|
||||
github.com/lmittmann/tint v1.0.0
|
||||
github.com/markbates/goth v1.77.0
|
||||
|
|
|
|||
|
|
@ -235,6 +235,8 @@ github.com/leaanthony/go-ansi-parser v1.6.1/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vL
|
|||
github.com/leaanthony/gosod v1.0.3 h1:Fnt+/B6NjQOVuCWOKYRREZnjGyvg+mEhd1nkkA04aTQ=
|
||||
github.com/leaanthony/gosod v1.0.3/go.mod h1:BJ2J+oHsQIyIQpnLPjnqFGTMnOZXDbvWtRCSG7jGxs4=
|
||||
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
|
||||
github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI=
|
||||
github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
|
||||
github.com/leaanthony/winicon v1.0.0 h1:ZNt5U5dY71oEoKZ97UVwJRT4e+5xo5o/ieKuHuk8NqQ=
|
||||
github.com/leaanthony/winicon v1.0.0/go.mod h1:en5xhijl92aphrJdmRPlh4NI1L6wq3gEm0LpXAPghjU=
|
||||
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package application
|
||||
|
||||
import "github.com/wailsapp/wails/v3/pkg/events"
|
||||
import "github.com/leaanthony/u"
|
||||
|
||||
// MacBackdrop is the backdrop type for macOS
|
||||
type MacBackdrop int
|
||||
|
|
@ -48,6 +49,19 @@ type MacWindow struct {
|
|||
// EnableFraudulentWebsiteWarnings will enable warnings for fraudulent websites.
|
||||
// Default: false
|
||||
EnableFraudulentWebsiteWarnings bool
|
||||
|
||||
// WebviewPreferences contains preferences for the webview
|
||||
WebviewPreferences MacWebviewPreferences
|
||||
}
|
||||
|
||||
// MacWebviewPreferences contains preferences for the Mac webview
|
||||
type MacWebviewPreferences struct {
|
||||
// TabFocusesLinks will enable tabbing to links
|
||||
TabFocusesLinks u.Bool
|
||||
// TextInteractionEnabled will enable text interaction
|
||||
TextInteractionEnabled u.Bool
|
||||
// FullscreenEnabled will enable fullscreen
|
||||
FullscreenEnabled u.Bool
|
||||
}
|
||||
|
||||
// MacTitleBar contains options for the Mac titlebar
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/leaanthony/u"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -12,6 +13,12 @@ import (
|
|||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
)
|
||||
|
||||
// Enabled means the feature should be enabled
|
||||
var Enabled = u.True
|
||||
|
||||
// Disabled means the feature should be disabled
|
||||
var Disabled = u.False
|
||||
|
||||
type (
|
||||
webviewWindowImpl interface {
|
||||
setTitle(title string)
|
||||
|
|
|
|||
|
|
@ -14,11 +14,16 @@ package application
|
|||
#import <AppKit/AppKit.h>
|
||||
#import "webview_window_darwin_drag.h"
|
||||
|
||||
struct WebviewPreferences {
|
||||
bool *TabFocusesLinks;
|
||||
bool *TextInteractionEnabled;
|
||||
bool *FullscreenEnabled;
|
||||
};
|
||||
|
||||
extern void registerListener(unsigned int event);
|
||||
|
||||
// Create a new Window
|
||||
void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWarningEnabled, bool frameless, bool enableDragAndDrop) {
|
||||
void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWarningEnabled, bool frameless, bool enableDragAndDrop, struct WebviewPreferences preferences) {
|
||||
NSWindowStyleMask styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
|
||||
if (frameless) {
|
||||
styleMask = NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable;
|
||||
|
|
@ -52,6 +57,25 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa
|
|||
WKWebViewConfiguration* config = [[WKWebViewConfiguration alloc] init];
|
||||
[config autorelease];
|
||||
|
||||
// Set preferences
|
||||
if (preferences.TabFocusesLinks != NULL) {
|
||||
config.preferences.tabFocusesLinks = *preferences.TabFocusesLinks;
|
||||
}
|
||||
|
||||
if (@available(macOS 11.3, *)) {
|
||||
if (preferences.TextInteractionEnabled != NULL) {
|
||||
config.preferences.textInteractionEnabled = *preferences.TextInteractionEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
if (@available(macOS 12.3, *)) {
|
||||
if (preferences.FullscreenEnabled != NULL) {
|
||||
config.preferences.elementFullscreenEnabled = *preferences.FullscreenEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
config.suppressesIncrementalRendering = true;
|
||||
config.applicationNameForUserAgent = @"wails.io";
|
||||
[config setURLSchemeHandler:delegate forURLScheme:@"wails"];
|
||||
|
|
@ -1023,6 +1047,29 @@ func (w *macosWebviewWindow) height() int {
|
|||
return int(height)
|
||||
}
|
||||
|
||||
func bool2CboolPtr(value bool) *C.bool {
|
||||
v := C.bool(value)
|
||||
return &v
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) getWebviewPreferences() C.struct_WebviewPreferences {
|
||||
wvprefs := w.parent.options.Mac.WebviewPreferences
|
||||
|
||||
var result C.struct_WebviewPreferences
|
||||
|
||||
if wvprefs.TextInteractionEnabled.IsSet() {
|
||||
result.TextInteractionEnabled = bool2CboolPtr(wvprefs.TextInteractionEnabled.Get())
|
||||
}
|
||||
if wvprefs.TabFocusesLinks.IsSet() {
|
||||
result.TabFocusesLinks = bool2CboolPtr(wvprefs.TabFocusesLinks.Get())
|
||||
}
|
||||
if wvprefs.FullscreenEnabled.IsSet() {
|
||||
result.FullscreenEnabled = bool2CboolPtr(wvprefs.FullscreenEnabled.Get())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) run() {
|
||||
for eventId := range w.parent.eventListeners {
|
||||
w.on(eventId)
|
||||
|
|
@ -1030,12 +1077,14 @@ func (w *macosWebviewWindow) run() {
|
|||
globalApplication.dispatchOnMainThread(func() {
|
||||
options := w.parent.options
|
||||
macOptions := options.Mac
|
||||
|
||||
w.nsWindow = C.windowNew(C.uint(w.parent.id),
|
||||
C.int(options.Width),
|
||||
C.int(options.Height),
|
||||
C.bool(macOptions.EnableFraudulentWebsiteWarnings),
|
||||
C.bool(options.Frameless),
|
||||
C.bool(options.EnableDragAndDrop),
|
||||
w.getWebviewPreferences(),
|
||||
)
|
||||
w.setTitle(options.Title)
|
||||
w.setAlwaysOnTop(options.AlwaysOnTop)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue