mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
pretty
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { globalShortcut } from "electron";
|
||||
import { globalShortcut } from 'electron';
|
||||
|
||||
export function isGlobalShortcutRegisteredSafe(accelerator: string): boolean {
|
||||
try {
|
||||
@@ -13,58 +13,50 @@ export function shortcutMatchesInputForLocalFallback(
|
||||
accelerator: string,
|
||||
allowWhenRegistered = false,
|
||||
): boolean {
|
||||
if (input.type !== "keyDown" || input.isAutoRepeat) return false;
|
||||
if (input.type !== 'keyDown' || input.isAutoRepeat) return false;
|
||||
if (!accelerator) return false;
|
||||
if (!allowWhenRegistered && isGlobalShortcutRegisteredSafe(accelerator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const normalized = accelerator
|
||||
.replace(/\s+/g, "")
|
||||
.replace(/cmdorctrl/gi, "CommandOrControl")
|
||||
.replace(/\s+/g, '')
|
||||
.replace(/cmdorctrl/gi, 'CommandOrControl')
|
||||
.toLowerCase();
|
||||
const parts = normalized.split("+").filter(Boolean);
|
||||
const parts = normalized.split('+').filter(Boolean);
|
||||
if (parts.length === 0) return false;
|
||||
|
||||
const keyToken = parts[parts.length - 1];
|
||||
const modifierTokens = new Set(parts.slice(0, -1));
|
||||
const allowedModifiers = new Set([
|
||||
"shift",
|
||||
"alt",
|
||||
"meta",
|
||||
"control",
|
||||
"commandorcontrol",
|
||||
]);
|
||||
const allowedModifiers = new Set(['shift', 'alt', 'meta', 'control', 'commandorcontrol']);
|
||||
for (const token of modifierTokens) {
|
||||
if (!allowedModifiers.has(token)) return false;
|
||||
}
|
||||
|
||||
const inputKey = (input.key || "").toLowerCase();
|
||||
const inputKey = (input.key || '').toLowerCase();
|
||||
if (keyToken.length === 1) {
|
||||
if (inputKey !== keyToken) return false;
|
||||
} else if (keyToken.startsWith("key") && keyToken.length === 4) {
|
||||
} else if (keyToken.startsWith('key') && keyToken.length === 4) {
|
||||
if (inputKey !== keyToken.slice(3)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
const expectedShift = modifierTokens.has("shift");
|
||||
const expectedAlt = modifierTokens.has("alt");
|
||||
const expectedMeta = modifierTokens.has("meta");
|
||||
const expectedControl = modifierTokens.has("control");
|
||||
const expectedCommandOrControl = modifierTokens.has("commandorcontrol");
|
||||
const expectedShift = modifierTokens.has('shift');
|
||||
const expectedAlt = modifierTokens.has('alt');
|
||||
const expectedMeta = modifierTokens.has('meta');
|
||||
const expectedControl = modifierTokens.has('control');
|
||||
const expectedCommandOrControl = modifierTokens.has('commandorcontrol');
|
||||
|
||||
if (Boolean(input.shift) !== expectedShift) return false;
|
||||
if (Boolean(input.alt) !== expectedAlt) return false;
|
||||
|
||||
if (expectedCommandOrControl) {
|
||||
const hasCmdOrCtrl =
|
||||
process.platform === "darwin"
|
||||
? Boolean(input.meta || input.control)
|
||||
: Boolean(input.control);
|
||||
process.platform === 'darwin' ? Boolean(input.meta || input.control) : Boolean(input.control);
|
||||
if (!hasCmdOrCtrl) return false;
|
||||
} else {
|
||||
if (process.platform === "darwin") {
|
||||
if (process.platform === 'darwin') {
|
||||
if (input.meta || input.control) return false;
|
||||
} else if (!expectedControl && input.control) {
|
||||
return false;
|
||||
@@ -72,16 +64,12 @@ export function shortcutMatchesInputForLocalFallback(
|
||||
}
|
||||
|
||||
if (expectedMeta && !input.meta) return false;
|
||||
if (!expectedMeta && modifierTokens.has("meta") === false && input.meta) {
|
||||
if (!expectedMeta && modifierTokens.has('meta') === false && input.meta) {
|
||||
if (!expectedCommandOrControl) return false;
|
||||
}
|
||||
|
||||
if (expectedControl && !input.control) return false;
|
||||
if (
|
||||
!expectedControl &&
|
||||
modifierTokens.has("control") === false &&
|
||||
input.control
|
||||
) {
|
||||
if (!expectedControl && modifierTokens.has('control') === false && input.control) {
|
||||
if (!expectedCommandOrControl) return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user