Made the context menu en/disable able via the settings and remove the global loader context menu blocker

canary
WolverinDEV 2020-09-17 23:19:30 +02:00
parent 7a3f3761bd
commit 2a25d5ae83
4 changed files with 19 additions and 10 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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<boolean> = {
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();
}

View File

@ -89,9 +89,9 @@ const SettingEditor = () => {
<Translatable>Value</Translatable>
<FlatInputField
className={cssStyle.input}
value={isApplying ? "" : currentValue ? currentValue : " "}
value={isApplying ? "" : typeof currentValue !== "undefined" ? currentValue + "" : ""}
editable={!isApplying}
placeholder={isApplying ? tr("applying...") : tr("setting unset")}
placeholder={isApplying ? tr("applying...") : tr("unset")}
onChange={text => {
setCurrentValue(text);
}}