aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/configUtils.ts
blob: db957caa47b282d83463299a3c3eb892eb9bee0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Config from "../config";
import { Keybind } from "../types";

export function showDonationLink(): boolean {
    return navigator.vendor !== "Apple Computer, Inc." && Config.config.showDonationLink;
}

export function isSafari(): boolean {
    return navigator.vendor === "Apple Computer, Inc.";
}

export function keybindEquals(first: Keybind, second: Keybind): boolean {
    if (first == null || second == null ||
            Boolean(first.alt) != Boolean(second.alt) || Boolean(first.ctrl) != Boolean(second.ctrl) || Boolean(first.shift) != Boolean(second.shift) ||
            first.key == null && first.code == null || second.key == null && second.code == null)
        return false;
    if (first.code != null && second.code != null)
        return first.code === second.code;
    if (first.key != null && second.key != null)
        return first.key.toUpperCase() === second.key.toUpperCase();
    return false;
}

export function formatKey(key: string): string {
    if (key == null)
        return "";
    else if (key == " ")
        return "Space";
    else if (key.length == 1)
        return key.toUpperCase();
    else
        return key;
}

export function keybindToString(keybind: Keybind): string {
    if (keybind == null || keybind.key == null)
        return "";

    let ret = "";
    if (keybind.ctrl)
        ret += "Ctrl+";
    if (keybind.alt)
        ret += "Alt+";
    if (keybind.shift)
        ret += "Shift+";

    return ret += formatKey(keybind.key);
}