Skip to content

Commit d897d43

Browse files
committed
fix(command-line): hide Firefox private-window shortcut hint (@d1rshan)
1 parent ed774cf commit d897d43

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

frontend/src/ts/components/layout/footer/Keytips.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import { JSXElement, Show } from "solid-js";
22

33
import { getConfig } from "../../../config/store";
44
import { getFocus } from "../../../states/core";
5+
import {
6+
getCommandLineKeyLabel,
7+
getModifierKeyLabel,
8+
isFirefoxBrowser,
9+
} from "../../../utils/shortcuts";
510
import { Conditional } from "../../common/Conditional";
611

712
export function Keytips(): JSXElement {
8-
const userAgent = window.navigator.userAgent.toLowerCase();
9-
const modifierKey =
10-
userAgent.includes("mac") && !userAgent.includes("firefox")
11-
? "cmd"
12-
: "ctrl";
13-
13+
const isFirefox = isFirefoxBrowser();
14+
const modifierKey = getModifierKeyLabel();
1415
const commandKey = (): string =>
15-
getConfig.quickRestart === "esc" ? "tab" : "esc";
16+
getCommandLineKeyLabel(getConfig.quickRestart);
1617

1718
return (
1819
<Show when={getConfig.showKeyTips}>
@@ -36,8 +37,20 @@ export function Keytips(): JSXElement {
3637
}
3738
/>
3839
<br />
39-
<kbd>{commandKey()}</kbd> or <kbd>{modifierKey}</kbd> + <kbd>shift</kbd>{" "}
40-
+ <kbd>p</kbd> - command line
40+
<Conditional
41+
if={isFirefox}
42+
then={
43+
<>
44+
<kbd>{commandKey()}</kbd> - command line
45+
</>
46+
}
47+
else={
48+
<>
49+
<kbd>{commandKey()}</kbd> or <kbd>{modifierKey}</kbd> +{" "}
50+
<kbd>shift</kbd> + <kbd>p</kbd> - command line
51+
</>
52+
}
53+
/>
4154
</div>
4255
</Show>
4356
);

frontend/src/ts/components/pages/AboutPage.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ import { getActivePage } from "../../states/core";
1212
import { showModal } from "../../states/modals";
1313
import { getTheme } from "../../states/theme";
1414
import { getNumberWithMagnitude } from "../../utils/numbers";
15+
import {
16+
getCommandLineKeyLabel,
17+
isFirefoxBrowser,
18+
} from "../../utils/shortcuts";
1519
import AsyncContent from "../common/AsyncContent";
1620
import { Button } from "../common/Button";
1721
import { ChartJs } from "../common/ChartJs";
22+
import { Conditional } from "../common/Conditional";
1823
import { Fa } from "../common/Fa";
1924
import { H2, H3 } from "../common/Headers";
2025

2126
export function AboutPage(): JSXElement {
2227
const isOpen = () => getActivePage() === "about";
28+
const isFirefox = isFirefoxBrowser();
29+
const commandKey = (): string =>
30+
getCommandLineKeyLabel(getConfig.quickRestart);
2331

2432
const contributors = useQuery(() => ({
2533
...getContributorsQueryOptions(),
@@ -203,9 +211,19 @@ export function AboutPage(): JSXElement {
203211
<p>
204212
You can use <kbd>tab</kbd> and <kbd>enter</kbd> (or just{" "}
205213
<kbd>tab</kbd> if you have quick tab mode enabled) to restart the
206-
typing test. Open the command line by pressing <kbd>ctrl/cmd</kbd> +{" "}
207-
<kbd>shift</kbd> + <kbd>p</kbd> or <kbd>esc</kbd> - there you can
208-
access all the functionality you need without touching your mouse.
214+
typing test. Open the command line by pressing{" "}
215+
<Conditional
216+
if={isFirefox}
217+
then={<kbd>{commandKey()}</kbd>}
218+
else={
219+
<>
220+
<kbd>ctrl/cmd</kbd> + <kbd>shift</kbd> + <kbd>p</kbd> or{" "}
221+
<kbd>{commandKey()}</kbd>
222+
</>
223+
}
224+
/>{" "}
225+
- there you can access all the functionality you need without touching
226+
your mouse.
209227
</p>
210228
</section>
211229
<section>

frontend/src/ts/pages/settings.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { authEvent } from "../events/auth";
5252
import * as FpsLimitSection from "../elements/settings/fps-limit-section";
5353
import { qs, qsa, qsr, onDOMReady } from "../utils/dom";
5454
import { showPopup } from "../modals/simple-modals-base";
55+
import { getCommandLineKeybindHtml } from "../utils/shortcuts";
5556

5657
let settingsInitialized = false;
5758

@@ -723,16 +724,10 @@ export async function update(
723724

724725
CustomBackgroundFilter.updateUI();
725726

726-
const userAgent = window.navigator.userAgent.toLowerCase();
727-
const modifierKey =
728-
userAgent.includes("mac") && !userAgent.includes("firefox")
729-
? "cmd"
730-
: "ctrl";
731-
732-
const commandKey = Config.quickRestart === "esc" ? "tab" : "esc";
727+
const commandLineKeybind = getCommandLineKeybindHtml(Config.quickRestart);
733728
qs(".pageSettings .tip")?.setHtml(`
734729
tip: You can also change all these settings quickly using the
735-
command line (<kbd>${commandKey}</kbd> or <kbd>${modifierKey}</kbd> + <kbd>shift</kbd> + <kbd>p</kbd>)`);
730+
command line (${commandLineKeybind})`);
736731

737732
if (
738733
customLayoutFluidSelect !== undefined &&

frontend/src/ts/utils/shortcuts.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export function isFirefoxBrowser(): boolean {
2+
if (typeof window === "undefined") return false;
3+
4+
return window.navigator.userAgent.toLowerCase().includes("firefox");
5+
}
6+
7+
export function getModifierKeyLabel(): string {
8+
if (typeof window === "undefined") return "ctrl";
9+
10+
const userAgent = window.navigator.userAgent.toLowerCase();
11+
12+
return userAgent.includes("mac") && !isFirefoxBrowser() ? "cmd" : "ctrl";
13+
}
14+
15+
export function getCommandLineKeyLabel(quickRestart: string): string {
16+
return quickRestart === "esc" ? "tab" : "esc";
17+
}
18+
19+
export function getCommandLineKeybindHtml(quickRestart: string): string {
20+
const commandKey = getCommandLineKeyLabel(quickRestart);
21+
22+
if (isFirefoxBrowser()) {
23+
return `<kbd>${commandKey}</kbd>`;
24+
}
25+
26+
return `<kbd>${commandKey}</kbd> or <kbd>${getModifierKeyLabel()}</kbd> + <kbd>shift</kbd> + <kbd>p</kbd>`;
27+
}

0 commit comments

Comments
 (0)