From 2a25d5ae8371eafa24e90ddbc86d9990a930a782 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Thu, 17 Sep 2020 23:19:30 +0200 Subject: [PATCH] Made the context menu en/disable able via the settings and remove the global loader context menu blocker --- loader/app/targets/shared.ts | 10 +++++++--- shared/js/main.tsx | 7 +++++-- shared/js/settings.ts | 8 +++++--- shared/js/ui/modal/global-settings-editor/Renderer.tsx | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/loader/app/targets/shared.ts b/loader/app/targets/shared.ts index 3ca6cf57..0fe91c55 100644 --- a/loader/app/targets/shared.ts +++ b/loader/app/targets/shared.ts @@ -7,7 +7,8 @@ import { declare global { interface Window { - detectedBrowser: BrowserInfo + detectedBrowser: BrowserInfo, + removeLoaderContextMenuHook: () => void } } @@ -43,6 +44,9 @@ if(__build.target === "web") { } /* directly disable all context menus */ -if(!location.search.match(/(.*[?&]|^)disableGlobalContextMenu=1($|&.*)/)) { - document.addEventListener("contextmenu", event => event.preventDefault()); +if(!location.search.match(/(.*[?&]|^)disableGlobalContextMenu=0($|&.*)/)) { + const callback = event => event.preventDefault(); + + document.addEventListener("contextmenu", callback); + window.removeLoaderContextMenuHook = () => document.removeEventListener("contextmenu", callback); } \ No newline at end of file diff --git a/shared/js/main.tsx b/shared/js/main.tsx index 4575b9fc..f89ae11a 100644 --- a/shared/js/main.tsx +++ b/shared/js/main.tsx @@ -161,8 +161,9 @@ function main() { /* context menu prevent */ $(document).on('contextmenu', (event: ContextMenuEvent) => { - if(event.isDefaultPrevented()) + if(event.isDefaultPrevented()) { return; + } if(event.target instanceof HTMLInputElement) { if((!!event.target.value || __build.target === "client") && !event.target.disabled && !event.target.readOnly && event.target.type !== "number") { @@ -189,9 +190,11 @@ function main() { return; } - if(!settings.static_global(Settings.KEY_DISABLE_GLOBAL_CONTEXT_MENU)) + if(settings.static_global(Settings.KEY_DISABLE_GLOBAL_CONTEXT_MENU)) { event.preventDefault(); + } }); + window.removeLoaderContextMenuHook(); top_menu.initialize(); diff --git a/shared/js/settings.ts b/shared/js/settings.ts index 8734db2f..e5c904cd 100644 --- a/shared/js/settings.ts +++ b/shared/js/settings.ts @@ -1,5 +1,5 @@ import * as log from "./log"; -import {LogCategory} from "./log"; +import {LogCategory, logTrace} from "./log"; import * as loader from "tc-loader"; import {Stage} from "tc-loader"; import {Registry} from "./events"; @@ -196,8 +196,8 @@ export class Settings extends StaticSettings { static readonly KEY_DISABLE_GLOBAL_CONTEXT_MENU: ValuedSettingsKey = { key: 'disableGlobalContextMenu', - description: 'Disable the general context menu prevention', - defaultValue: false, + description: 'Disable the general context menu', + defaultValue: true, valueType: "boolean", }; @@ -672,6 +672,8 @@ export class Settings extends StaticSettings { setting: key.key, newCastedValue: value }); + logTrace(LogCategory.GENERAL, tr("Changing global setting %s to %o"), key.key, value); + if(Settings.UPDATE_DIRECT) this.save(); } diff --git a/shared/js/ui/modal/global-settings-editor/Renderer.tsx b/shared/js/ui/modal/global-settings-editor/Renderer.tsx index 51d85d40..51f6030a 100644 --- a/shared/js/ui/modal/global-settings-editor/Renderer.tsx +++ b/shared/js/ui/modal/global-settings-editor/Renderer.tsx @@ -89,9 +89,9 @@ const SettingEditor = () => { Value { setCurrentValue(text); }}