mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 21:07:05 -06:00
fix(tab_navigation): affecting server and mobile views
This commit is contained in:
parent
82d97ef26f
commit
7da9367dc9
@ -3,19 +3,19 @@ import "./TabHistoryNavigationButtons.css";
|
|||||||
import { useEffect, useMemo, useState } from "preact/hooks";
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
||||||
|
|
||||||
import { t } from "../services/i18n";
|
import { t } from "../services/i18n";
|
||||||
import { dynamicRequire } from "../services/utils";
|
import { dynamicRequire, isElectron } from "../services/utils";
|
||||||
import { handleHistoryContextMenu } from "./launch_bar/HistoryNavigation";
|
import { handleHistoryContextMenu } from "./launch_bar/HistoryNavigation";
|
||||||
import ActionButton from "./react/ActionButton";
|
import ActionButton from "./react/ActionButton";
|
||||||
import { useLauncherVisibility } from "./react/hooks";
|
import { useLauncherVisibility } from "./react/hooks";
|
||||||
|
|
||||||
export default function TabHistoryNavigationButtons() {
|
export default function TabHistoryNavigationButtons() {
|
||||||
const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []);
|
const webContents = useMemo(() => isElectron() ? dynamicRequire("@electron/remote").getCurrentWebContents() : undefined, []);
|
||||||
const onContextMenu = handleHistoryContextMenu(webContents);
|
const onContextMenu = webContents ? handleHistoryContextMenu(webContents) : undefined;
|
||||||
const { canGoBack, canGoForward } = useBackForwardState(webContents);
|
const { canGoBack, canGoForward } = useBackForwardState(webContents);
|
||||||
const legacyBackVisible = useLauncherVisibility("_lbBackInHistory");
|
const legacyBackVisible = useLauncherVisibility("_lbBackInHistory");
|
||||||
const legacyForwardVisible = useLauncherVisibility("_lbForwardInHistory");
|
const legacyForwardVisible = useLauncherVisibility("_lbForwardInHistory");
|
||||||
|
|
||||||
return (
|
return (isElectron() &&
|
||||||
<div className="tab-history-navigation-buttons">
|
<div className="tab-history-navigation-buttons">
|
||||||
{!legacyBackVisible && <ActionButton
|
{!legacyBackVisible && <ActionButton
|
||||||
icon="bx bx-left-arrow-alt"
|
icon="bx bx-left-arrow-alt"
|
||||||
@ -35,11 +35,13 @@ export default function TabHistoryNavigationButtons() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useBackForwardState(webContents: Electron.WebContents) {
|
function useBackForwardState(webContents: Electron.WebContents | undefined) {
|
||||||
const [ canGoBack, setCanGoBack ] = useState(webContents.navigationHistory.canGoBack());
|
const [ canGoBack, setCanGoBack ] = useState(webContents?.navigationHistory.canGoBack());
|
||||||
const [ canGoForward, setCanGoForward ] = useState(webContents.navigationHistory.canGoForward());
|
const [ canGoForward, setCanGoForward ] = useState(webContents?.navigationHistory.canGoForward());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!webContents) return;
|
||||||
|
|
||||||
const updateNavigationState = () => {
|
const updateNavigationState = () => {
|
||||||
setCanGoBack(webContents.navigationHistory.canGoBack());
|
setCanGoBack(webContents.navigationHistory.canGoBack());
|
||||||
setCanGoForward(webContents.navigationHistory.canGoForward());
|
setCanGoForward(webContents.navigationHistory.canGoForward());
|
||||||
@ -54,5 +56,9 @@ function useBackForwardState(webContents: Electron.WebContents) {
|
|||||||
};
|
};
|
||||||
}, [ webContents ]);
|
}, [ webContents ]);
|
||||||
|
|
||||||
|
if (!webContents) {
|
||||||
|
return { canGoBack: true, canGoForward: true };
|
||||||
|
}
|
||||||
|
|
||||||
return { canGoBack, canGoForward };
|
return { canGoBack, canGoForward };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import contextMenu, { MenuCommandItem } from "../../menus/context_menu";
|
|||||||
import froca from "../../services/froca";
|
import froca from "../../services/froca";
|
||||||
import link from "../../services/link";
|
import link from "../../services/link";
|
||||||
import tree from "../../services/tree";
|
import tree from "../../services/tree";
|
||||||
import { dynamicRequire } from "../../services/utils";
|
import { dynamicRequire, isElectron } from "../../services/utils";
|
||||||
import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets";
|
import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets";
|
||||||
|
|
||||||
interface HistoryNavigationProps {
|
interface HistoryNavigationProps {
|
||||||
@ -18,14 +18,14 @@ const HISTORY_LIMIT = 20;
|
|||||||
|
|
||||||
export default function HistoryNavigationButton({ launcherNote, command }: HistoryNavigationProps) {
|
export default function HistoryNavigationButton({ launcherNote, command }: HistoryNavigationProps) {
|
||||||
const { icon, title } = useLauncherIconAndTitle(launcherNote);
|
const { icon, title } = useLauncherIconAndTitle(launcherNote);
|
||||||
const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []);
|
const webContents = useMemo(() => isElectron() ? dynamicRequire("@electron/remote").getCurrentWebContents() : undefined, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LaunchBarActionButton
|
<LaunchBarActionButton
|
||||||
icon={icon}
|
icon={icon}
|
||||||
text={title}
|
text={title}
|
||||||
triggerCommand={command}
|
triggerCommand={command}
|
||||||
onContextMenu={handleHistoryContextMenu(webContents)}
|
onContextMenu={webContents ? handleHistoryContextMenu(webContents) : undefined}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user