Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
QingXia-Ela committed Jul 28, 2024
1 parent ee91459 commit 5f93cbc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ quote = "1.0.36"
monster-siren-macro = { path = "../packages/monster-siren-macro" }
include_dir = "0.7.4"
rodio = "0.19.0"
id3 = "1.14.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/vanilla_injector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ pub async fn get_audio_duration_from_path(path: &str) -> Option<u64> {
}
None
}

// todo!: finish get audio img cover by id3 or mp4ameta lib, return a base64 string
pub async fn get_audio_cover_from_path(path: &str) -> Option<String> {
None
}
32 changes: 16 additions & 16 deletions src/hooks/useInjectorMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { invoke } from "@tauri-apps/api/tauri";
import { useEffect, useState } from "react";
import { invoke } from '@tauri-apps/api/tauri';
import { useEffect, useState } from 'react';

export const defaultMetadata = Object.freeze({
namespace: "",
cnNamespace: "未知",
color: "rgba(255, 255, 255, 0.2)",
})
namespace: '',
cnNamespace: '未知',
color: 'rgba(255, 255, 255, 0.2)',
});

export type InjectorMetadata = {
namespace: string
cnNamespace: string
color: string
}
namespace: string;
cnNamespace: string;
color: string;
};

function useInjectorMetadata() {
const [data, setData] = useState<InjectorMetadata[]>([])
const [data, setData] = useState<InjectorMetadata[]>([]);

async function refresh() {
const data = await invoke("get_all_injector_metadata", {});
const data = await invoke('get_all_injector_metadata', {});
setData(data);
}

useEffect(() => {
refresh()
}, [])
refresh();
}, []);

return { data, defaultMetadata, refresh }
return { data, defaultMetadata, refresh };
}

export default useInjectorMetadata
export default useInjectorMetadata;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import BlackMenu from '@/components/ContextMenu/BlackMenuV2';
import { useMenuState } from '@szhsin/react-menu';
import RetryTips from '../RetryTips';
import PendingTips from '../PendingTips';
import useInjectorMetadata, { InjectorMetadata } from '@/hooks/useInjectorMetadata';
import useInjectorMetadata, {
InjectorMetadata,
} from '@/hooks/useInjectorMetadata';

interface RightDetailsBottomListProps {
ContextMenu?: (...args: any) => JSX.Element;
Expand Down Expand Up @@ -66,19 +68,22 @@ const useControlledMenu = (options: any) => {
function parseU64Duration2Time(duration: number) {
const minute = Math.floor(duration / 60000);
const second = Math.floor((duration % 60000) / 1000);
return `${minute < 10 ? '0' + minute : minute}:${second < 10 ? '0' + second : second}`;
return `${minute < 10 ? '0' + minute : minute}:${
second < 10 ? '0' + second : second
}`;
}

function getTagsBySongCid(cid: string, data: InjectorMetadata[]) {
return data
.filter((item) => {
return cid.includes(`${item.namespace}:`)
}).map((data) => {
return cid.includes(`${item.namespace}:`);
})
.map((data) => {
return {
content: data.cnNamespace,
color: data.color
}
})
color: data.color,
};
});
}
const RightDetailsBottomList: FunctionComponent<
RightDetailsBottomListProps
Expand All @@ -92,15 +97,15 @@ const RightDetailsBottomList: FunctionComponent<
transition: true,
});

const { data: injectorData } = useInjectorMetadata()
const { data: injectorData } = useInjectorMetadata();

if (status === 'error') {
return <RetryTips />;
} else if (status === 'pending') {
return <PendingTips />;
}

console.log(list)
console.log(list);

return list.length ? (
<>
Expand All @@ -118,7 +123,11 @@ const RightDetailsBottomList: FunctionComponent<
name={list[idx].name}
author={list[idx].artists?.join(',')}
album={info.name}
time={list[idx].duration ? parseU64Duration2Time(list[idx].duration!) : ''}
time={
list[idx].duration
? parseU64Duration2Time(list[idx].duration!)
: ''
}
tags={getTagsBySongCid(list[idx].cid, injectorData)}
/>
),
Expand Down

0 comments on commit 5f93cbc

Please sign in to comment.