feishin/src/renderer/router/app-outlet.tsx

39 lines
982 B
TypeScript
Raw Normal View History

2023-05-31 00:27:16 -07:00
import { useMemo } from 'react';
2022-12-19 15:59:14 -08:00
import isElectron from 'is-electron';
2023-05-31 00:27:16 -07:00
import { Navigate, Outlet } from 'react-router-dom';
2022-12-19 15:59:14 -08:00
import { AppRoute } from '/@/renderer/router/routes';
import { useCurrentServer } from '/@/renderer/store';
2022-12-25 01:25:46 -08:00
const localSettings = isElectron() ? window.electron.localSettings : null;
2022-12-19 15:59:14 -08:00
export const AppOutlet = () => {
const currentServer = useCurrentServer();
2023-05-31 00:27:16 -07:00
const isActionsRequired = useMemo(() => {
const isMpvRequired = () => {
if (!isElectron()) return false;
const mpvPath = localSettings.get('mpv_path');
if (mpvPath) return false;
return true;
2022-12-19 15:59:14 -08:00
};
2023-05-31 00:27:16 -07:00
const isServerRequired = !currentServer;
const actions = [isServerRequired, isMpvRequired()];
const isActionRequired = actions.some((c) => c);
2022-12-19 15:59:14 -08:00
2023-05-31 00:27:16 -07:00
return isActionRequired;
}, [currentServer]);
2022-12-19 15:59:14 -08:00
2023-05-31 00:27:16 -07:00
if (isActionsRequired) {
2022-12-19 15:59:14 -08:00
return (
<Navigate
replace
to={AppRoute.ACTION_REQUIRED}
/>
);
}
return <Outlet />;
};