mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 03:52:41 +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:
parent
ab0b0f8a7f
commit
3f9067c815
@ -17,7 +17,7 @@
|
|||||||
#define WindowStartsMinimised 2
|
#define WindowStartsMinimised 2
|
||||||
#define WindowStartsFullscreen 3
|
#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 Run(void*, const char* url);
|
||||||
|
|
||||||
void SetTitle(void* ctx, const char *title);
|
void SetTitle(void* ctx, const char *title);
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
#import "WailsMenu.h"
|
#import "WailsMenu.h"
|
||||||
#import "WailsMenuItem.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];
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
WailsContext *result = [WailsContext new];
|
WailsContext *result = [WailsContext new];
|
||||||
|
|
||||||
result.devtoolsEnabled = devtoolsEnabled;
|
result.devtoolsEnabled = devtoolsEnabled;
|
||||||
result.defaultContextMenu = defaultContextMenu;
|
result.defaultContextMenuEnabled = defaultContextMenuEnabled;
|
||||||
|
|
||||||
if ( windowStartState == WindowStartsFullscreen ) {
|
if ( windowStartState == WindowStartsFullscreen ) {
|
||||||
fullscreen = 1;
|
fullscreen = 1;
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
@property bool alwaysOnTop;
|
@property bool alwaysOnTop;
|
||||||
|
|
||||||
@property bool devtoolsEnabled;
|
@property bool devtoolsEnabled;
|
||||||
@property bool defaultContextMenu;
|
@property bool defaultContextMenuEnabled;
|
||||||
|
|
||||||
@property (retain) WKUserContentController* userContentController;
|
@property (retain) WKUserContentController* userContentController;
|
||||||
|
|
||||||
|
@ -235,16 +235,18 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
|||||||
[userContentController addScriptMessageHandler:self name:@"external"];
|
[userContentController addScriptMessageHandler:self name:@"external"];
|
||||||
config.userContentController = userContentController;
|
config.userContentController = userContentController;
|
||||||
self.userContentController = userContentController;
|
self.userContentController = userContentController;
|
||||||
|
|
||||||
if (self.devtoolsEnabled) {
|
if (self.devtoolsEnabled) {
|
||||||
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
|
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
|
||||||
} else if (!self.defaultContextMenu) {
|
}
|
||||||
|
|
||||||
|
if (!self.defaultContextMenuEnabled) {
|
||||||
// Disable default context menus
|
// Disable default context menus
|
||||||
WKUserScript *initScript = [WKUserScript new];
|
WKUserScript *initScript = [WKUserScript new];
|
||||||
[initScript initWithSource:@"window.wails.flags.disableDefaultContextMenu = true;"
|
[initScript initWithSource:@"window.wails.flags.disableDefaultContextMenu = true;"
|
||||||
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
|
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
|
||||||
forMainFrameOnly:false];
|
forMainFrameOnly:false];
|
||||||
[userContentController addUserScript:initScript];
|
[userContentController addUserScript:initScript];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.webview = [WKWebView alloc];
|
self.webview = [WKWebView alloc];
|
||||||
|
@ -216,10 +216,10 @@ int main(int argc, const char * argv[]) {
|
|||||||
const char* appearance = "NSAppearanceNameDarkAqua";
|
const char* appearance = "NSAppearanceNameDarkAqua";
|
||||||
int windowIsTranslucent = 1;
|
int windowIsTranslucent = 1;
|
||||||
int devtoolsEnabled = 1;
|
int devtoolsEnabled = 1;
|
||||||
int defaultContextMenu = 1;
|
int defaultContextMenuEnabled = 1;
|
||||||
int windowStartState = 0;
|
int windowStartState = 0;
|
||||||
int startsHidden = 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);
|
startsHidden, 400, 400, 600, 600, false);
|
||||||
SetBackgroundColour(result, 255, 0, 0, 255);
|
SetBackgroundColour(result, 255, 0, 0, 255);
|
||||||
void *m = NewMenu("");
|
void *m = NewMenu("");
|
||||||
|
@ -57,7 +57,7 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
|
|||||||
hideWindowOnClose := bool2Cint(frontendOptions.HideWindowOnClose)
|
hideWindowOnClose := bool2Cint(frontendOptions.HideWindowOnClose)
|
||||||
startsHidden := bool2Cint(frontendOptions.StartHidden)
|
startsHidden := bool2Cint(frontendOptions.StartHidden)
|
||||||
devtoolsEnabled := bool2Cint(devtools)
|
devtoolsEnabled := bool2Cint(devtools)
|
||||||
defaultContextMenu := bool2Cint(frontendOptions.EnableDefaultContextMenu)
|
defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu)
|
||||||
|
|
||||||
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
|
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
|
||||||
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent 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,
|
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
|
||||||
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
|
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)
|
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings, preferences)
|
||||||
|
|
||||||
// Create menu
|
// Create menu
|
||||||
|
@ -474,8 +474,7 @@ void DevtoolsEnabled(void *webview, int enabled, bool showInspector)
|
|||||||
|
|
||||||
if (genabled && showInspector)
|
if (genabled && showInspector)
|
||||||
{
|
{
|
||||||
WebKitWebInspector *inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
|
ShowInspector(webview);
|
||||||
webkit_web_inspector_show(WEBKIT_WEB_INSPECTOR(inspector));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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))
|
C.DevtoolsEnabled(unsafe.Pointer(webview), C.int(1), C.bool(debug && appoptions.Debug.OpenInspectorOnStartup))
|
||||||
// Install Ctrl-Shift-F12 hotkey to call ShowInspector
|
// Install Ctrl-Shift-F12 hotkey to call ShowInspector
|
||||||
C.InstallF12Hotkey(unsafe.Pointer(gtkWindow))
|
C.InstallF12Hotkey(unsafe.Pointer(gtkWindow))
|
||||||
} else if !appoptions.EnableDefaultContextMenu {
|
}
|
||||||
|
|
||||||
|
if !(debug || appoptions.EnableDefaultContextMenu) {
|
||||||
C.DisableContextMenu(unsafe.Pointer(webview))
|
C.DisableContextMenu(unsafe.Pointer(webview))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ func (f *Frontend) setupChromium() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
err = settings.PutAreDefaultContextMenusEnabled(f.devtoolsEnabled || f.frontendOptions.EnableDefaultContextMenu)
|
err = settings.PutAreDefaultContextMenusEnabled(f.debug || f.frontendOptions.EnableDefaultContextMenu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ type App struct {
|
|||||||
CSSDragValue string
|
CSSDragValue string
|
||||||
|
|
||||||
// EnableDefaultContextMenu enables the browser's default context-menu in production
|
// 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
|
EnableDefaultContextMenu bool
|
||||||
|
|
||||||
// EnableFraudulentWebsiteDetection enables scan services for fraudulent content, such as malware or phishing attempts.
|
// EnableFraudulentWebsiteDetection enables scan services for fraudulent content, such as malware or phishing attempts.
|
||||||
|
@ -424,7 +424,7 @@ Type: `string`
|
|||||||
|
|
||||||
EnableDefaultContextMenu enables the browser's default context-menu in production.
|
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 :
|
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 :
|
||||||
|
|
||||||
|
@ -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)
|
- 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
|
## v2.6.0 - 2023-09-06
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user