5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 06:50:22 +08:00

[v2] Devtools tag doesn't enable default context-menu (#2923)

* Devtools tag doesn't enable default context-menu

* Update changelog
This commit is contained in:
Mohamed Gharib 2023-09-26 00:43:18 +03:00 committed by GitHub
parent ab0b0f8a7f
commit 3f9067c815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 23 additions and 16 deletions

View File

@ -17,7 +17,7 @@
#define WindowStartsMinimised 2
#define WindowStartsFullscreen 3
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenu, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences);
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences);
void Run(void*, const char* url);
void SetTitle(void* ctx, const char *title);

View File

@ -14,14 +14,14 @@
#import "WailsMenu.h"
#import "WailsMenuItem.h"
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenu, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences) {
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences) {
[NSApplication sharedApplication];
WailsContext *result = [WailsContext new];
result.devtoolsEnabled = devtoolsEnabled;
result.defaultContextMenu = defaultContextMenu;
result.defaultContextMenuEnabled = defaultContextMenuEnabled;
if ( windowStartState == WindowStartsFullscreen ) {
fullscreen = 1;

View File

@ -45,7 +45,7 @@
@property bool alwaysOnTop;
@property bool devtoolsEnabled;
@property bool defaultContextMenu;
@property bool defaultContextMenuEnabled;
@property (retain) WKUserContentController* userContentController;

View File

@ -235,16 +235,18 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
[userContentController addScriptMessageHandler:self name:@"external"];
config.userContentController = userContentController;
self.userContentController = userContentController;
if (self.devtoolsEnabled) {
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
} else if (!self.defaultContextMenu) {
}
if (!self.defaultContextMenuEnabled) {
// Disable default context menus
WKUserScript *initScript = [WKUserScript new];
[initScript initWithSource:@"window.wails.flags.disableDefaultContextMenu = true;"
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
forMainFrameOnly:false];
[userContentController addUserScript:initScript];
}
self.webview = [WKWebView alloc];

View File

@ -216,10 +216,10 @@ int main(int argc, const char * argv[]) {
const char* appearance = "NSAppearanceNameDarkAqua";
int windowIsTranslucent = 1;
int devtoolsEnabled = 1;
int defaultContextMenu = 1;
int defaultContextMenuEnabled = 1;
int windowStartState = 0;
int startsHidden = 0;
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenu, windowStartState,
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled, windowStartState,
startsHidden, 400, 400, 600, 600, false);
SetBackgroundColour(result, 255, 0, 0, 255);
void *m = NewMenu("");

View File

@ -57,7 +57,7 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
hideWindowOnClose := bool2Cint(frontendOptions.HideWindowOnClose)
startsHidden := bool2Cint(frontendOptions.StartHidden)
devtoolsEnabled := bool2Cint(devtools)
defaultContextMenu := bool2Cint(frontendOptions.EnableDefaultContextMenu)
defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu)
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int
@ -104,7 +104,7 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
}
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenu,
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled,
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings, preferences)
// Create menu

View File

@ -474,8 +474,7 @@ void DevtoolsEnabled(void *webview, int enabled, bool showInspector)
if (genabled && showInspector)
{
WebKitWebInspector *inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
webkit_web_inspector_show(WEBKIT_WEB_INSPECTOR(inspector));
ShowInspector(webview);
}
}

View File

@ -107,7 +107,9 @@ func NewWindow(appoptions *options.App, debug bool, devtoolsEnabled bool) *Windo
C.DevtoolsEnabled(unsafe.Pointer(webview), C.int(1), C.bool(debug && appoptions.Debug.OpenInspectorOnStartup))
// Install Ctrl-Shift-F12 hotkey to call ShowInspector
C.InstallF12Hotkey(unsafe.Pointer(gtkWindow))
} else if !appoptions.EnableDefaultContextMenu {
}
if !(debug || appoptions.EnableDefaultContextMenu) {
C.DisableContextMenu(unsafe.Pointer(webview))
}

View File

@ -517,7 +517,7 @@ func (f *Frontend) setupChromium() {
if err != nil {
log.Fatal(err)
}
err = settings.PutAreDefaultContextMenusEnabled(f.devtoolsEnabled || f.frontendOptions.EnableDefaultContextMenu)
err = settings.PutAreDefaultContextMenusEnabled(f.debug || f.frontendOptions.EnableDefaultContextMenu)
if err != nil {
log.Fatal(err)
}

View File

@ -74,7 +74,7 @@ type App struct {
CSSDragValue string
// EnableDefaultContextMenu enables the browser's default context-menu in production
// This menu is already enabled in development, as well as in debug builds and production builds with the `-devtools` flag
// This menu is already enabled in development and debug builds
EnableDefaultContextMenu bool
// EnableFraudulentWebsiteDetection enables scan services for fraudulent content, such as malware or phishing attempts.

View File

@ -424,7 +424,7 @@ Type: `string`
EnableDefaultContextMenu enables the browser's default context-menu in production.
By default, the browser's default context-menu is only available in development and in a `-debug` or `-devtools` [build](../reference/cli.mdx#build) along with the devtools inspector, Using this option you can enable the default context-menu in `production` while the devtools inspector won't be available unless the `-devtools` build flag is used.
By default, the browser's default context-menu is only available in development and in a `-debug` [build](../reference/cli.mdx#build) along with the devtools inspector, Using this option you can enable the default context-menu in `production` while the devtools inspector won't be available unless the `-devtools` build flag is used.
When this option is enabled, by default the context-menu will only be shown for text contexts (where Cut/Copy/Paste is needed), to override this behavior, you can use the CSS property `--default-contextmenu` on any HTML element (including the `body`) with the following values :

View File

@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed typo on docs/reference/options page. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/2887)
### Changed
- Now building with `-devtools` flag doesn't enable the default context-menu. Changed by @mmghv in [PR](https://github.com/wailsapp/wails/pull/2923)
## v2.6.0 - 2023-09-06