import { useEffect, useState } from "react"; import { convertFileSrc, invoke } from "@tauri-apps/api/core"; import "./App.css"; import { Config } from "./types"; // import { EventEmitter } from "@tauri-apps/plugin-shell"; // import { listen } from "@tauri-apps/api/event"; // import { fetch } from "@tauri-apps/plugin-http"; import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"; const appWindow = getCurrentWebviewWindow(); function App() { const library = useState([]); const [queue, setQueue] = useState([]); const [playing, setPlaying] = useState(false); const [playlists, setPlaylists] = useState([]); const [viewName, setViewName] = useState("Library"); const [nowPlaying, setNowPlaying] = useState( } /> ); useEffect(() => { const unlisten = appWindow.listen("now_playing_change", ({ payload, }) => { const displayArtwork = () => { invoke('display_album_art', { uuid: payload.uuid }).then(() => {}) } // console.log(event); setNowPlaying( } /> ) }) return () => { unlisten.then((f) => f()) } }, []); useEffect(() => { const unlisten = appWindow.listen("queue_updated", (_) => { // console.log(event); invoke('get_queue').then((_songs) => { let songs = _songs as any[] setQueue( songs.filter((_, i) => i != 0).map((song, i) => ) ) }) }) return () => { unlisten.then((f) => f()) } }, []); useEffect(() => { const unlisten = appWindow.listen("playing", (_) => { setPlaying(true) }) return () => { unlisten.then((f) => f()) } }, []); useEffect(() => { const unlisten = appWindow.listen("paused", (_) => { setPlaying(false) }) return () => { unlisten.then((f) => f()) } }, []); useEffect(() => { getConfig(); }, []) return (
{ nowPlaying }
); } export default App; interface PlaylistHeadProps { playlists: JSX.Element[] setPlaylists: React.Dispatch>, setViewName: React.Dispatch>, setLibrary: React.Dispatch>, } function PlaylistHead({ playlists, setPlaylists, setViewName, setLibrary }: PlaylistHeadProps) { useEffect(() => { const unlisten = appWindow.listen("playlists_gotten", (_res) => { // console.log(event); let res = _res.payload; setPlaylists([ ...res.map( (item) => { return ( ) }) ]) }) return () => { unlisten.then((f) => f()) } }, []); let handle_import = () => { invoke('import_playlist').then((_res) => { let res = _res as any; setPlaylists([ ...playlists, ]) console.log(res.name); }) } return (
{ playlists }
) } interface MainViewProps { lib_ref: [JSX.Element[], React.Dispatch>], viewName: string } function MainView({ lib_ref, viewName }: MainViewProps) { const [library, setLibrary] = lib_ref; useEffect(() => { const unlisten = appWindow.listen("library_loaded", (_) => { console.log("library_loaded"); invoke('get_library').then((lib) => { setLibrary([...(lib as any[]).map((song) => { return ( ) })]) }) invoke('get_playlists').then(() => {}) }) return () => { unlisten.then((f) => f()) } }, []); return (

{ viewName }

{ library }
) } interface SongProps { location: any, playerLocation: string | {"Playlist" : any}, uuid: string, plays: number, format?: string, duration: string, last_played?: string, date_added?: string, date_modified?: string, tags: any } function Song(props: SongProps) { // console.log(props.tags); return(
{ invoke("play_now", { uuid: props.uuid, location: props.playerLocation }).then(() => {}) }} className="song">

{ props.tags.AlbumArtist }

{ props.tags.TrackTitle }

{ props.tags.AlbumTitle }

{ Math.round(+props.duration / 60) }: { (+props.duration % 60).toString().padStart(2, "0") }

{/* */}
) } interface PlayBarProps { playing: boolean, setPlaying: React.Dispatch> } function PlayBar({ playing, setPlaying }: PlayBarProps) { return (
{ invoke('set_volume', { volume: volume.target.value }).then(() => {}) }} />
) } interface NowPlayingProps { title: string, artist: string, album: string, artwork: JSX.Element } function NowPlaying({ title, artist, album, artwork }: NowPlayingProps) { return (
{ artwork }

{ title }

{ artist }

{ album }

) } interface QueueProps { songs: JSX.Element[], } function Queue({ songs }: QueueProps) { return (
{ songs }
) } interface QueueSongProps { song: any, location: "Library" | {"Playlist": string}, index: number, } function QueueSong({ song, location, index }: QueueSongProps) { console.log(song.tags); let removeFromQueue = () => { invoke('remove_from_queue', { index: index }).then(() => {}) } let playNow = () => { invoke('play_now', { uuid: song.uuid, location: location }).then(() => {}) } return (

{ song.tags.TrackTitle }

{ song.tags.TrackArtist }

) } function getConfig(): any { invoke('get_config').then( (_config) => { let config = _config as Config; if (config.libraries.libraries.length == 0) { newWindow() } else { // console.log("else"); invoke('lib_already_created').then(() => {}) } }) } function newWindow() { invoke('new_library_window').then(() => {}) }