Compare commits
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import type { MenuComponentProps } from "@expo/ui/community/menu"
|
||||
import { Button, Host, Menu, RNHostView } from "@expo/ui/swift-ui"
|
||||
import { disabled, menuOrder } from "@expo/ui/swift-ui/modifiers"
|
||||
|
||||
// SwiftUI's automatic order reverses menus that open upward in the player.
|
||||
// Keep the same top-to-bottom order as the UIKit long-press menus.
|
||||
export function MenuView({
|
||||
actions,
|
||||
children,
|
||||
style,
|
||||
testID,
|
||||
onPressAction,
|
||||
}: MenuComponentProps) {
|
||||
return (
|
||||
<Host matchContents style={style} testID={testID} ignoreSafeArea="all">
|
||||
<Menu
|
||||
modifiers={[menuOrder("fixed")]}
|
||||
label={
|
||||
<RNHostView matchContents>
|
||||
<>{children}</>
|
||||
</RNHostView>
|
||||
}
|
||||
>
|
||||
{actions
|
||||
.filter((action) => !action.attributes?.hidden)
|
||||
.map((action) => (
|
||||
<Button
|
||||
key={action.id ?? action.title}
|
||||
label={action.title}
|
||||
systemImage={
|
||||
typeof action.image === "string" ? action.image : undefined
|
||||
}
|
||||
role={action.attributes?.destructive ? "destructive" : undefined}
|
||||
modifiers={[disabled(action.attributes?.disabled ?? false)]}
|
||||
onPress={() =>
|
||||
onPressAction?.({
|
||||
nativeEvent: { event: action.id ?? action.title },
|
||||
})
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</Menu>
|
||||
</Host>
|
||||
)
|
||||
}
|
||||
@@ -68,6 +68,21 @@ async function coverPathIfExists(path: string): Promise<string | null> {
|
||||
.catch(() => null)
|
||||
}
|
||||
|
||||
async function shouldReplaceCover(dbCover: string | null) {
|
||||
return dbCover === null || (await coverPathIfExists(dbCover)) === null
|
||||
}
|
||||
|
||||
function isCodecPath(filePath: string, codec: string) {
|
||||
return filePath.startsWith(`${DATA_DIR}/${codec}/`)
|
||||
}
|
||||
|
||||
function releaseDate(common: music.ICommonTagsResult) {
|
||||
if (common.date) {
|
||||
return common.date
|
||||
}
|
||||
return common.year ? `01-01-${common.year}` : ""
|
||||
}
|
||||
|
||||
async function syncArtistCover(
|
||||
ctx: ActionCtx,
|
||||
codec: string,
|
||||
@@ -77,13 +92,13 @@ async function syncArtistCover(
|
||||
) {
|
||||
const onDisk = await coverPathIfExists(diskPath)
|
||||
if (onDisk !== null) {
|
||||
if (dbCover !== onDisk) {
|
||||
if (await shouldReplaceCover(dbCover)) {
|
||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||
id,
|
||||
cover: onDisk,
|
||||
})
|
||||
}
|
||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
||||
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||
id,
|
||||
cover: null,
|
||||
@@ -100,13 +115,13 @@ async function syncAlbumCover(
|
||||
) {
|
||||
const onDisk = await coverPathIfExists(diskPath)
|
||||
if (onDisk !== null) {
|
||||
if (dbCover !== onDisk) {
|
||||
if (await shouldReplaceCover(dbCover)) {
|
||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||
id,
|
||||
cover: onDisk,
|
||||
})
|
||||
}
|
||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
||||
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||
id,
|
||||
cover: null,
|
||||
@@ -402,9 +417,8 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
name: metadata.common.album || potentialAlbum,
|
||||
folder: potentialAlbum,
|
||||
cover,
|
||||
year: metadata.common.year || 2026,
|
||||
date:
|
||||
metadata.common.date || `01-01-${metadata.common.year || 2026}`,
|
||||
year: metadata.common.year || 0,
|
||||
date: releaseDate(metadata.common),
|
||||
artist: dbArtist._id,
|
||||
})
|
||||
} catch {}
|
||||
@@ -494,11 +508,14 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
)
|
||||
|
||||
if (existingSong) {
|
||||
// A tracked path that still exists is a different file with the
|
||||
// same title; replacing it would flip-flop between scans.
|
||||
const trackedPath = existingSong.files[codec]
|
||||
if (
|
||||
!(codec in existingSong.files) ||
|
||||
existingSong.files[codec] !== path
|
||||
trackedPath === undefined ||
|
||||
!fsSync.existsSync(trackedPath)
|
||||
) {
|
||||
const update = { [codec]: path, ...existingSong.files }
|
||||
const update = { ...existingSong.files, [codec]: path }
|
||||
updateSongs.push({
|
||||
id: existingSong._id,
|
||||
files: update,
|
||||
@@ -550,10 +567,8 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
? null
|
||||
: metadata.common.disk.no,
|
||||
track: metadata.common.track.no || 0,
|
||||
year: metadata.common.year || 2026,
|
||||
date:
|
||||
metadata.common.date ||
|
||||
`01-01-${metadata.common.year || 2026}`,
|
||||
year: metadata.common.year || 0,
|
||||
date: releaseDate(metadata.common),
|
||||
genres: metadata.common.genre || [],
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user