Skip to content

Commit

Permalink
downloads feature is not available for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
mrakesh0608 committed Jul 28, 2024
1 parent 83860f3 commit 545d0f6
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Download and Install VLC Media player form [here](https://www.videolan.org/vlc/d

## 🤝 CONTRIBUTING

Contributions, issues, and feature requests are welcome! See [See Contribution Guide.](./CONTRIBUTING.md)
Contributions, issues, and feature requests are welcome! See [Contribution Guide.](./CONTRIBUTING.md)

## ⭐ SUPPORT

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisa",
"version": "1.1.0",
"version": "2.0.0",
"author": "",
"description": "",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ contextBridge.exposeInMainWorld('electronAPI', {
},
openExternal: (data) => ipcRenderer.invoke('open-external', data),
showItemInFolder: (data) => ipcRenderer.invoke('show-item-in-folder', data),
getPlatformOS: () => process.platform,
});
2 changes: 1 addition & 1 deletion src/components/ActiveDownloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function ActiveDownloads() {

function ActiveDownloadsEmpty() {
return (
<Flex alignItems={'center'} justifyContent="center">
<Flex alignItems={'center'} justifyContent="center" p={3} width={'100%'}>
<Box color="gray.500" mr="2">
<TbMoodSad size={24} />
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DownloadsHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function DownloadsHistoryItem({

function DownloadsHistoryEmpty() {
return (
<Flex alignItems={'center'} justifyContent="center" p={3} pt={2} width={'100%'}>
<Flex alignItems={'center'} justifyContent="center" p={3} width={'100%'}>
<Box color="gray.500" marginInline="2">
<TbMoodSad size={24} />
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useGetAnimeEpPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useGetAnimeEpPagination() {
stream: searchParams.get('stream'),
episodePageUrl: url,
},
{ replace: true },
{ replace: true, preventScrollReset: true },
);
}

Expand Down
25 changes: 20 additions & 5 deletions src/screens/DownloadsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import { Center, Stack } from '@chakra-ui/react';
import { useFeatureAvailable } from 'src/utils/fn';

import { ActiveDownloads } from '../components/ActiveDownloads';
import { DownloadsHistory } from '../components/DownloadsHistory';

export function DownloadScreen() {
const { isDownloadFeatureAvailable } = useFeatureAvailable();

if (isDownloadFeatureAvailable)
return (
<Center py={6} w="100%">
<Stack flex={1} flexDirection="column" rowGap={5} p={1} pt={2} maxWidth={'90%'}>
<ActiveDownloads />
<DownloadsHistory />
</Stack>
</Center>
);

return (
<Center py={6} w="100%">
<Stack flex={1} flexDirection="column" rowGap={5} p={1} pt={2} maxWidth={'90%'}>
<ActiveDownloads />
<DownloadsHistory />
</Stack>
<Center py={6} w="100%" h={'100vh'}>
<p
style={{
fontSize: 20,
}}>
Downloads feature is not available for MacOS.
</p>
</Center>
);
}
2 changes: 1 addition & 1 deletion src/screens/MyListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function MyListScreen() {

const { data, error, isLoading } = useQuery({
queryKey: [mode === 'manga' ? 'read-list' : 'watch-list', mode],
queryFn: () => getMyList({ url: mode === 'manga' ? 'readlist' : '/watchlist' }),
queryFn: () => getMyList({ url: mode === 'manga' ? '/readlist' : '/watchlist' }),
});

if (error) return <ErrorMessage error={error} />;
Expand Down
61 changes: 34 additions & 27 deletions src/screens/inbuiltPlayerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useDownloadVideo } from 'src/hooks/useDownloadVideo';
import { useGetAnimeDetails } from 'src/hooks/useGetAnimeDetails';
import { useGetAnimeEpPagination } from 'src/hooks/useGetAnimeEpPagination';
import { useGetAnimeStream } from 'src/hooks/useGetAnimeStream';
import { useFeatureAvailable } from 'src/utils/fn';

import { PaginateCard } from '../components/paginateCard';
import { VideoPlayer } from '../components/video-player';
Expand Down Expand Up @@ -109,6 +110,8 @@ export function InbuiltPlayerScreen() {
else onClose();
}, [downloadLoading]);

const { isDownloadFeatureAvailable } = useFeatureAvailable();

const animeTitle = anime.title || anime.jp_name || anime_details?.description?.eng_name;

return (
Expand Down Expand Up @@ -192,33 +195,37 @@ export function InbuiltPlayerScreen() {
</option>
))}
</Select>
<div
style={{
display: 'flex',
columnGap: 10,
}}>
<Menu>
<MenuButton disabled={eps_loading} as={Button}>
Download
</MenuButton>
<MenuList>
<MenuGroup title="Select quality">
{qualityOptions?.map(({ id, height }) => (
<MenuItem
key={id}
onClick={() => singleDownloadHandler(id)}>
{height}p
</MenuItem>
))}
</MenuGroup>
</MenuList>
</Menu>
{eps_details?.ep_details?.length > 1 ? (
<Button disabled={eps_loading} onClick={downloadPageHandler}>
Download all
</Button>
) : null}
</div>
{isDownloadFeatureAvailable ? (
<div
style={{
display: 'flex',
columnGap: 10,
}}>
<Menu>
<MenuButton disabled={eps_loading} as={Button}>
Download
</MenuButton>
<MenuList>
<MenuGroup title="Select quality">
{qualityOptions?.map(({ id, height }) => (
<MenuItem
key={id}
onClick={() => singleDownloadHandler(id)}>
{height}p
</MenuItem>
))}
</MenuGroup>
</MenuList>
</Menu>
{eps_details?.ep_details?.length > 1 ? (
<Button
disabled={eps_loading}
onClick={downloadPageHandler}>
Download all
</Button>
) : null}
</div>
) : null}
</Flex>
) : streamLoading ? (
<Flex
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ElectronAPI {
getDomainCookies: (data: any) => Promise<any>;
openExternal: (data: any) => Promise<any>;
showItemInFolder: (data: any) => Promise<any>;
getPlatformOS: () => Promise<NodeJS.Platform>;
}
declare global {
interface Window {
Expand Down
33 changes: 25 additions & 8 deletions src/utils/fn.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
export function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;

do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
import { useEffect, useState } from 'react';

export function openFileExplorer(file_location: string) {
if (!file_location || !window) return;
Expand All @@ -16,3 +9,27 @@ export function openExternalUrl(url: string) {
if (!url || !window) return;
window?.electronAPI?.openExternal(url);
}

export async function PlatformOS(): Promise<NodeJS.Platform> {
if (!window) return;
return await window?.electronAPI?.getPlatformOS();
}

export const isViteDEV = import.meta.env.DEV;
export const isVitePROD = import.meta.env.PROD;

export function useFeatureAvailable() {
const [isDownloadFeatureAvailable, setIsDownloadFeatureAvailable] = useState(true);

useEffect(() => {
(async () => {
const platformOS = await PlatformOS();

setIsDownloadFeatureAvailable(!(isVitePROD && platformOS === 'darwin'));
})();
}, []);

return {
isDownloadFeatureAvailable,
};
}

0 comments on commit 545d0f6

Please sign in to comment.