2023-03-28 23:59:51 -07:00
|
|
|
import { lazy } from 'react';
|
2022-12-19 15:59:14 -08:00
|
|
|
import isElectron from 'is-electron';
|
2023-09-22 17:52:00 -07:00
|
|
|
import { useNavigate } from 'react-router';
|
2022-12-19 15:59:14 -08:00
|
|
|
import styled from 'styled-components';
|
2023-05-18 02:15:03 -07:00
|
|
|
import {
|
2023-07-01 19:10:05 -07:00
|
|
|
useWindowSettings,
|
|
|
|
|
useSettingsStore,
|
|
|
|
|
useHotkeySettings,
|
|
|
|
|
useGeneralSettings,
|
|
|
|
|
useSettingsStoreActions,
|
2023-05-18 02:15:03 -07:00
|
|
|
} from '/@/renderer/store/settings.store';
|
2023-03-28 23:59:51 -07:00
|
|
|
import { Platform, PlaybackType } from '/@/renderer/types';
|
|
|
|
|
import { MainContent } from '/@/renderer/layouts/default-layout/main-content';
|
|
|
|
|
import { PlayerBar } from '/@/renderer/layouts/default-layout/player-bar';
|
2023-06-11 19:45:13 +00:00
|
|
|
import { HotkeyItem, useHotkeys } from '@mantine/hooks';
|
2023-05-18 02:15:03 -07:00
|
|
|
import { CommandPalette } from '/@/renderer/features/search/components/command-palette';
|
|
|
|
|
import { useCommandPalette } from '/@/renderer/store';
|
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-09-22 02:34:57 -07:00
|
|
|
const Layout = styled.div<{ $windowBarStyle: Platform }>`
|
2023-07-01 19:10:05 -07:00
|
|
|
display: grid;
|
|
|
|
|
grid-template-areas:
|
|
|
|
|
'window-bar'
|
|
|
|
|
'main-content'
|
|
|
|
|
'player';
|
|
|
|
|
grid-template-rows: ${(props) =>
|
2023-09-22 02:34:57 -07:00
|
|
|
props.$windowBarStyle === Platform.WINDOWS || props.$windowBarStyle === Platform.MACOS
|
2023-07-01 19:10:05 -07:00
|
|
|
? '30px calc(100vh - 120px) 90px'
|
|
|
|
|
: '0px calc(100vh - 90px) 90px'};
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
gap: 0;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
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();
|
2023-07-01 19:10:05 -07:00
|
|
|
const localSettings = isElectron() ? window.electron.localSettings : null;
|
|
|
|
|
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)],
|
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 (
|
|
|
|
|
<>
|
|
|
|
|
<Layout
|
2023-09-22 02:34:57 -07:00
|
|
|
$windowBarStyle={windowBarStyle}
|
2023-07-01 19:10:05 -07:00
|
|
|
id="default-layout"
|
|
|
|
|
>
|
|
|
|
|
{windowBarStyle !== Platform.WEB && <WindowBar />}
|
|
|
|
|
<MainContent shell={shell} />
|
|
|
|
|
<PlayerBar />
|
|
|
|
|
</Layout>
|
|
|
|
|
<CommandPalette modalProps={{ handlers, opened }} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DefaultLayout.defaultProps = {
|
2023-07-01 19:10:05 -07:00
|
|
|
shell: false,
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|