Arlodotexe / strix-music

Combine any music sources into a single library. It's your music. Play it your way.
http://www.strixmusic.com
138 stars 4 forks source link

[Feature] File-based cores finish InitAsync() before metadata scan starts emitting data #151

Closed Arlodotexe closed 2 years ago

Arlodotexe commented 2 years ago

Describe the problem

Right now, when you call InitAsync() on a file-based core (OneDrive, LocalFilesCore), the task completes before the core has a chance to scan audio files for metadata, meaning the core appears to not have any data.

Worse, even if a dev knows this, there's no reliable way for them to know when data becomes available, short of hooking into every event in the ILibrary.

Describe the proposed change

We need to fix this in a way to doesn't break the CoreModel standard. Waiting for this shouldn't require locating an extra property, or subscribing to some event, that doesn't exist on the ICore interface.

Instead, we can add a FileScanBehavior enum:

namespace StrixMusic.Cores.Files;

/// <summary>
/// The wait behavior of <see cref="IAsyncInit.InitAsync"> on a file-based <see cref="ICore"/> relative to the metadata scanner.
/// </summary>
public enum InitAsyncScannerBehavior
{
    /// <summary>
    /// <see cref="IAsyncInit.InitAsync"> will only wait for the scanner to complete if it there's no cached scan data.
    /// </summary>
    WaitIfNoData,

    /// <summary>
    /// <see cref="IAsyncInit.InitAsync"> will always wait for the scanner to complete.
    /// </summary>
    AlwaysWait,

    /// <summary>
    /// <see cref="IAsyncInit.InitAsync"> will never wait for the scanner to complete.
    /// </summary>
    NeverWait
}

This should be exposed as a property or on the constructor, with WaitIfNoData as the default value, and InitAsync on each file-based core respecting the option.

Alternatives

No response

Additional info

No response

Help us help you

No response

amaid commented 2 years ago

In case dev don't forget about that the scanner has an init configurable state , maybe make it optional constructor parameter.

Arlodotexe commented 2 years ago

In case dev don't forget about that the scanner has an init configurable state , maybe make it optional constructor parameter.

I think until we can simplify the existing constructors, we should just add a property and give it the best default value for the majority of users.