Disable context menu in production mode

This commit is contained in:
Lea Anthony 2020-11-21 20:32:55 +11:00
commit 40fdf75042
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
4 changed files with 18 additions and 4 deletions

View file

@ -113,8 +113,6 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string, debug
fullscreen := a.bool2Cint(a.config.Fullscreen)
startHidden := a.bool2Cint(a.config.StartHidden)
logLevel := C.int(a.config.LogLevel)
println("debug = ", debug)
println("devtools = ", a.config.DevTools)
app := C.NewApplication(title, width, height, resizable, devtools, fullscreen, startHidden, logLevel)
// Save app reference

View file

@ -1016,6 +1016,13 @@ void Run(struct Application *app, int argc, char **argv) {
index++;
};
// Disable context menu if not in debug mode
if( debug != 1 ) {
temp = concat(internalCode, "wails._.DisableContextMenu();");
free((void*)internalCode);
internalCode = temp;
}
// class_addMethod(delegateClass, s("applicationWillFinishLaunching:"), (IMP) willFinishLaunching, "@@:@");
// Include callback after evaluation
temp = concat(internalCode, "webkit.messageHandlers.completed.postMessage(true);");
@ -1024,7 +1031,7 @@ void Run(struct Application *app, int argc, char **argv) {
// const char *viewportScriptString = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); meta.setAttribute('initial-scale', '1.0'); meta.setAttribute('maximum-scale', '1.0'); meta.setAttribute('minimum-scale', '1.0'); meta.setAttribute('user-scalable', 'no'); document.getElementsByTagName('head')[0].appendChild(meta);";
// ExecJS(app, viewportScriptString);
// This evaluates the MOAE once the Dom has finished loading
msg(manager,
@ -1035,6 +1042,8 @@ void Run(struct Application *app, int argc, char **argv) {
1,
1));
if( app->webviewIsTranparent == 1 ) {
msg(wkwebview, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("drawsBackground"));
}

View file

@ -14,7 +14,7 @@ import * as Window from './window';
import * as Dialog from './dialog';
import { On, Once, OnMultiple, Emit, Notify } from './events';
import { Callback, SystemCall } from './calls';
import { AddScript, InjectCSS } from './utils';
import { AddScript, InjectCSS, DisableContextMenu } from './utils';
import { AddIPCListener } from 'ipc';
import * as Platform from 'platform';
import * as Store from './store';
@ -41,6 +41,7 @@ export function Init() {
Notify,
AddScript,
InjectCSS,
DisableContextMenu,
// Init,
AddIPCListener,
SystemCall,

View file

@ -36,3 +36,9 @@ export function InjectCSS(css) {
console.log(e);
}
}
export function DisableContextMenu() {
AddScript('function contextMenu(event) { event.preventDefault(); }');
var body = document.getElementsByTagName('body')[0];
body.setAttribute('oncontextmenu', 'contextMenu(event)');
}