import clsx from "clsx"; import { useState, useEffect } from "react"; import "./index.css"; import { invoke } from "@tauri-apps/api/tauri"; import { listen } from '@tauri-apps/api/event'; import { appWindow } from '@tauri-apps/api/window'; import { platform } from '@tauri-apps/api/os'; import { ThemeProvider } from "@/components/theme-provider"; import { Button } from "@/components/ui/button"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { InstalledPrograms, WebSocketMessage, } from "./types"; import { compareVersions, extractVersion, isInstalled, sendStreamInfo, detectWindows, detectDistro, extractDistroId, detectDistroBase, detectMacOs, registerMacFiles } from "./lib/utils"; import { CircleCheck, TriangleAlert, CircleAlert } from 'lucide-react'; function App() { useEffect(() => { const handleCloseRequested = (event: any) => { event.preventDefault(); appWindow.hide(); }; appWindow.onCloseRequested(handleCloseRequested); }, []); const [isWindows, setIsWindows] = useState(false) const [windowsVersion, setWindowsVersion] = useState(null) const [isMacOs, setIsMacOs] = useState(false) const [macOsVersion, setMacOsVersion] = useState(null) const [distroId, setDistroId] = useState(null) const [distroBase, setDistroBase] = useState(null) const [installedPrograms, setInstalledPrograms] = useState({ winget: { installed: false, version: null, }, apt: { installed: false, version: null, }, dnf: { installed: false, version: null, }, brew: { installed: false, version: null, }, python: { installed: false, version: null, }, pip: { installed: false, version: null, }, python3: { installed: false, version: null, }, pip3: { installed: false, version: null, }, ffmpeg: { installed: false, version: null, }, pytubepp: { installed: false, version: null, }, }); useEffect(() => { const unlisten = listen('websocket-message', (event) => { if(event.payload.command === 'send-stream-info') { sendStreamInfo(event.payload.url); } else if(event.payload.command === 'download-stream') { const startDownload = async () => { try { await invoke('download_stream', { url: event.payload.url, stream: event.payload.argument }); await invoke('receive_frontend_response', { response: 'Download started' }); } catch (error) { console.error(error); } }; startDownload(); } else if (event.payload.command === 'autostart') { const handleAppAutostart = async () => { appWindow.hide(); await invoke('receive_frontend_response', { response: 'Appwindow Hidden' }); }; handleAppAutostart(); } }); return () => { unlisten.then(f => f()); }; }, []); function checkAllPrograms() { isInstalled('winget', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, winget: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('apt', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, apt: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('dnf', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, dnf: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('homebrew', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, brew: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('python', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, python: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('pip', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, pip: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('python3', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, python3: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('pip3', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, pip3: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('ffmpeg', '-version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, ffmpeg: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); isInstalled('pytubepp', '--version').then((result) => { setInstalledPrograms((prevState) => ({ ...prevState, pytubepp: { installed: result.installed, version: result.output ? extractVersion(result.output) : null, } })); }); } useEffect(() => { checkAllPrograms(); const runPlatformSpecificChecks = async () => { const currentPlatform = await platform(); switch (currentPlatform) { case 'win32': const windowsResult = await detectWindows(); if (windowsResult) { setIsWindows(true); setWindowsVersion(extractVersion(windowsResult)); } break; case 'darwin': const macResult = await detectMacOs(); if (macResult) { setIsMacOs(true); setMacOsVersion(extractVersion(macResult)); } break; case 'linux': const distroResult = await detectDistro(); if (distroResult) { setDistroId(extractDistroId(distroResult)); setDistroBase(detectDistroBase(extractDistroId(distroResult))); } break; default: console.log('Unsupported platform'); } }; runPlatformSpecificChecks().catch(console.error); }, []) return (

PytubePP Helper

{ isMacOs && macOsVersion && compareVersions(macOsVersion, '10.13') > 0 ? : null }
{ distroId && distroBase && distroBase === 'debian' ? /* Section for Debian */

Python: {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}

{installedPrograms.python3.installed ? installedPrograms.python3.version ? compareVersions(installedPrograms.python3.version, '3.8') < 0 ? : : installedPrograms.apt.installed ? : : null}

FFmpeg: {installedPrograms.ffmpeg.installed ? 'installed' : 'not installed'} {installedPrograms.ffmpeg.version ? `(${installedPrograms.ffmpeg.version})` : ''}

{installedPrograms.ffmpeg.installed ? : installedPrograms.apt.installed ? : null}

PytubePP: {installedPrograms.pytubepp.installed ? 'installed' : 'not installed'} {installedPrograms.pytubepp.version ? `(${installedPrograms.pytubepp.version})` : ''}

{installedPrograms.pytubepp.installed ? : installedPrograms.pip3.installed ? : null}
{(!installedPrograms.apt.installed && (!installedPrograms.python3.installed || !installedPrograms.ffmpeg.installed)) ? APT Not Found APT is required to install necessary debian packages. Please install it manually for your distro. : null} {(!installedPrograms.pip3.installed && !installedPrograms.pytubepp.installed) ? PIP Not Found PIP is required to install necessary python packages. Please install it now to continue: : null} {(installedPrograms.python3.installed && installedPrograms.ffmpeg.installed && installedPrograms.pytubepp.installed) ? Ready Everything looks ok! You can close this window now. Make sure it's always running in the background. : null}
: distroId && distroBase && distroBase === 'rhel' ? /* Section for RHEL */

Python: {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}

{installedPrograms.python3.installed ? installedPrograms.python3.version ? compareVersions(installedPrograms.python3.version, '3.8') < 0 ? : : installedPrograms.dnf.installed ? : : null}

FFmpeg: {installedPrograms.ffmpeg.installed ? 'installed' : 'not installed'} {installedPrograms.ffmpeg.version ? `(${installedPrograms.ffmpeg.version})` : ''}

{installedPrograms.ffmpeg.installed ? : installedPrograms.dnf.installed ? : null}

PytubePP: {installedPrograms.pytubepp.installed ? 'installed' : 'not installed'} {installedPrograms.pytubepp.version ? `(${installedPrograms.pytubepp.version})` : ''}

{installedPrograms.pytubepp.installed ? : installedPrograms.pip3.installed ? : null}
{(!installedPrograms.dnf.installed && (!installedPrograms.python3.installed || !installedPrograms.ffmpeg.installed)) ? DNF Not Found DNF is required to install necessary rpm packages. Please install it manually for your distro. : null} {(!installedPrograms.pip3.installed && !installedPrograms.pytubepp.installed) ? PIP Not Found PIP is required to install necessary python packages. Please install it now to continue: : null} {(installedPrograms.python3.installed && installedPrograms.ffmpeg.installed && installedPrograms.pytubepp.installed) ? Ready Everything looks ok! You can close this window now. Make sure it's always running in the background. : null}
: isWindows && windowsVersion && parseInt(windowsVersion) >= 17134 ? /* Section for Windows */

Python: {installedPrograms.python.installed ? 'installed' : 'not installed'} {installedPrograms.python.version ? `(${installedPrograms.python.version})` : ''}

{installedPrograms.python.installed ? installedPrograms.python.version ? compareVersions(installedPrograms.python.version, '3.8') < 0 ? : : installedPrograms.winget.installed ? : : null}

FFmpeg: {installedPrograms.ffmpeg.installed ? 'installed' : 'not installed'} {installedPrograms.ffmpeg.version ? `(${installedPrograms.ffmpeg.version})` : ''}

{installedPrograms.ffmpeg.installed ? : installedPrograms.winget.installed ? : null}

PytubePP: {installedPrograms.pytubepp.installed ? 'installed' : 'not installed'} {installedPrograms.pytubepp.version ? `(${installedPrograms.pytubepp.version})` : ''}

{installedPrograms.pytubepp.installed ? : installedPrograms.pip.installed ? : null}
{(!installedPrograms.winget.installed && (!installedPrograms.python.installed || !installedPrograms.ffmpeg.installed)) ? WinGet Not Found WinGet is required to install necessary packages. Please install it manually from here. : null} {(installedPrograms.python.installed && installedPrograms.ffmpeg.installed && installedPrograms.pytubepp.installed) ? Ready Everything looks ok! You can close this window now. Make sure it's always running in the background. : null}
: isMacOs && macOsVersion && compareVersions(macOsVersion, '10.13') > 0 ? /* Section for macOS */

Python: {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}

{installedPrograms.python3.installed ? installedPrograms.python3.version ? compareVersions(installedPrograms.python3.version, '3.8') < 0 ? : : installedPrograms.brew.installed ? : : null}

FFmpeg: {installedPrograms.ffmpeg.installed ? 'installed' : 'not installed'} {installedPrograms.ffmpeg.version ? `(${installedPrograms.ffmpeg.version})` : ''}

{installedPrograms.ffmpeg.installed ? : installedPrograms.brew.installed ? : null}

PytubePP: {installedPrograms.pytubepp.installed ? 'installed' : 'not installed'} {installedPrograms.pytubepp.version ? `(${installedPrograms.pytubepp.version})` : ''}

{installedPrograms.pytubepp.installed ? : installedPrograms.pip3.installed ? : null}
{(!installedPrograms.brew.installed && (!installedPrograms.python3.installed || !installedPrograms.ffmpeg.installed)) ? Homebrew Not Found Homebrew is required to install necessary unix packages. Please install it manually for your mac. : null} {(!installedPrograms.pip3.installed && !installedPrograms.pytubepp.installed) ? PIP Not Found PIP is required to install necessary python packages. Please install it now to continue: : null} {(installedPrograms.python3.installed && installedPrograms.ffmpeg.installed && installedPrograms.pytubepp.installed) ? Ready Everything looks ok! You can close this window now. Make sure it's always running in the background. : null}
:
Unsupported OS Sorry, your os/distro is currently not supported. If you think this is just a mistake or you want to request us to add support for your os/distro you can create a github issue here.
}
); } export default App;