2025-05-18 14:03:18 -07:00
|
|
|
import { HotkeyItem, useHotkeys } from '@mantine/hooks';
|
2025-06-24 00:04:36 -07:00
|
|
|
import clsx from 'clsx';
|
2022-12-19 15:59:14 -08:00
|
|
|
import isElectron from 'is-electron';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { lazy } from 'react';
|
2023-09-22 17:52:00 -07:00
|
|
|
import { useNavigate } from 'react-router';
|
2025-06-24 00:04:36 -07:00
|
|
|
|
|
|
|
|
import styles from './default-layout.module.css';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2025-09-06 00:45:59 -07:00
|
|
|
import { ContextMenuProvider } from '/@/renderer/features/context-menu';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { CommandPalette } from '/@/renderer/features/search/components/command-palette';
|
|
|
|
|
import { MainContent } from '/@/renderer/layouts/default-layout/main-content';
|
|
|
|
|
import { PlayerBar } from '/@/renderer/layouts/default-layout/player-bar';
|
2025-09-06 01:01:48 -07:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { useCommandPalette } from '/@/renderer/store';
|
2023-05-18 02:15:03 -07:00
|
|
|
import {
|
2023-07-01 19:10:05 -07:00
|
|
|
useGeneralSettings,
|
2025-05-18 14:03:18 -07:00
|
|
|
useHotkeySettings,
|
|
|
|
|
useSettingsStore,
|
2023-07-01 19:10:05 -07:00
|
|
|
useSettingsStoreActions,
|
2025-05-18 14:03:18 -07:00
|
|
|
useWindowSettings,
|
2023-05-18 02:15:03 -07:00
|
|
|
} from '/@/renderer/store/settings.store';
|
2025-05-20 19:23:36 -07:00
|
|
|
import { Platform, PlaybackType } from '/@/shared/types/types';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
if (!isElectron()) {
|
2023-07-01 19:10:05 -07:00
|
|
|
useSettingsStore.getState().actions.setSettings({
|
|
|
|
|
playback: {
|
|
|
|
|
...useSettingsStore.getState().playback,
|
|
|
|
|
type: PlaybackType.WEB,
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-12-19 15:59:14 -08:00
|
|
|
}
|
|
|
|
|
|
2023-03-28 23:59:51 -07:00
|
|
|
const WindowBar = lazy(() =>
|
2023-07-01 19:10:05 -07:00
|
|
|
import('/@/renderer/layouts/window-bar').then((module) => ({
|
|
|
|
|
default: module.WindowBar,
|
|
|
|
|
})),
|
2023-03-28 23:59:51 -07:00
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
interface DefaultLayoutProps {
|
2023-07-01 19:10:05 -07:00
|
|
|
shell?: boolean;
|
2022-12-19 15:59:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DefaultLayout = ({ shell }: DefaultLayoutProps) => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const { windowBarStyle } = useWindowSettings();
|
|
|
|
|
const { opened, ...handlers } = useCommandPalette();
|
|
|
|
|
const { bindings } = useHotkeySettings();
|
2023-09-22 17:52:00 -07:00
|
|
|
const navigate = useNavigate();
|
2025-05-18 14:03:18 -07:00
|
|
|
const localSettings = isElectron() ? window.api.localSettings : null;
|
2023-07-01 19:10:05 -07:00
|
|
|
const settings = useGeneralSettings();
|
|
|
|
|
const { setSettings } = useSettingsStoreActions();
|
2023-05-18 02:15:03 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const updateZoom = (increase: number) => {
|
|
|
|
|
const newVal = settings.zoomFactor + increase;
|
|
|
|
|
if (newVal > 300 || newVal < 50 || !isElectron()) return;
|
|
|
|
|
setSettings({
|
|
|
|
|
general: {
|
|
|
|
|
...settings,
|
|
|
|
|
zoomFactor: newVal,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
localSettings?.setZoomFactor(settings.zoomFactor);
|
|
|
|
|
};
|
2023-06-11 19:45:13 +00:00
|
|
|
localSettings?.setZoomFactor(settings.zoomFactor);
|
|
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const zoomHotkeys: HotkeyItem[] = [
|
|
|
|
|
[bindings.zoomIn.hotkey, () => updateZoom(5)],
|
|
|
|
|
[bindings.zoomOut.hotkey, () => updateZoom(-5)],
|
|
|
|
|
];
|
2023-06-11 19:45:13 +00:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
useHotkeys([
|
|
|
|
|
[bindings.globalSearch.hotkey, () => handlers.open()],
|
2023-09-22 17:52:00 -07:00
|
|
|
[bindings.browserBack.hotkey, () => navigate(-1)],
|
|
|
|
|
[bindings.browserForward.hotkey, () => navigate(1)],
|
2025-09-06 01:01:48 -07:00
|
|
|
[bindings.navigateHome.hotkey, () => navigate(AppRoute.HOME)],
|
2023-07-01 19:10:05 -07:00
|
|
|
...(isElectron() ? zoomHotkeys : []),
|
|
|
|
|
]);
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
2025-09-06 00:45:59 -07:00
|
|
|
<ContextMenuProvider>
|
2025-06-24 00:04:36 -07:00
|
|
|
<div
|
|
|
|
|
className={clsx(styles.layout, {
|
|
|
|
|
[styles.macos]: windowBarStyle === Platform.MACOS,
|
|
|
|
|
[styles.windows]: windowBarStyle === Platform.WINDOWS,
|
|
|
|
|
})}
|
2023-07-01 19:10:05 -07:00
|
|
|
id="default-layout"
|
|
|
|
|
>
|
|
|
|
|
{windowBarStyle !== Platform.WEB && <WindowBar />}
|
|
|
|
|
<MainContent shell={shell} />
|
|
|
|
|
<PlayerBar />
|
2025-06-24 00:04:36 -07:00
|
|
|
</div>
|
2023-07-01 19:10:05 -07:00
|
|
|
<CommandPalette modalProps={{ handlers, opened }} />
|
2025-09-06 00:45:59 -07:00
|
|
|
</ContextMenuProvider>
|
2023-07-01 19:10:05 -07:00
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|