Update Setlist for Beat Saber 1.44.1 startup scan
This commit is contained in:
+39
-22
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BeatSaberPlaylistsLib.Types;
|
||||
using IPA;
|
||||
using PlaylistManager.Utilities;
|
||||
using UnityEngine;
|
||||
using IPALogger = IPA.Logging.Logger;
|
||||
|
||||
namespace Setlist
|
||||
@@ -20,6 +22,9 @@ namespace Setlist
|
||||
/// <summary>Set after the ownership scan resolves the platform user id; used when syncing after PlaylistManager adds a song.</summary>
|
||||
internal static string CachedPlatformUserId { get; set; }
|
||||
|
||||
private const float PlaylistScanPollStepSeconds = 0.5f;
|
||||
private const float PlaylistScanWaitTimeoutSeconds = 10f;
|
||||
|
||||
[Init]
|
||||
public Plugin(IPALogger logger)
|
||||
{
|
||||
@@ -36,43 +41,55 @@ namespace Setlist
|
||||
|
||||
Events.playlistSongAdded += OnPlaylistSongAdded;
|
||||
|
||||
SetlistSyncHost.Instance.StartPlaylistOwnershipScan(Log);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal static IEnumerator CoScanAndLogPlaylistOwnership(IPALogger log)
|
||||
{
|
||||
var waited = 0f;
|
||||
while (waited <= PlaylistScanWaitTimeoutSeconds)
|
||||
{
|
||||
var playlists = BeatSaberPlaylistsLib.PlaylistManager.DefaultManager.GetAllPlaylists(
|
||||
includeChildren: true,
|
||||
out AggregateException loadErrors);
|
||||
|
||||
if (loadErrors != null)
|
||||
{
|
||||
Log.Error(loadErrors.Message);
|
||||
log.Error(loadErrors.Message);
|
||||
foreach (var inner in loadErrors.InnerExceptions)
|
||||
{
|
||||
Log.Error(inner.ToString());
|
||||
log.Error(inner.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (playlists == null || playlists.Length == 0)
|
||||
if (playlists != null && playlists.Length > 0)
|
||||
{
|
||||
Log.Info("No playlists loaded (or playlist library not initialized yet).");
|
||||
return;
|
||||
var entries = new List<(IPlaylist Playlist, string Title, bool HasSyncUrl, string BeatLeaderGuid, string OwnerId)>();
|
||||
foreach (var playlist in playlists)
|
||||
{
|
||||
BeatLeaderPlaylistOwnership.TryReadBeatLeaderMetadata(
|
||||
playlist,
|
||||
out var hasSyncUrl,
|
||||
out var blGuid,
|
||||
out var ownerId);
|
||||
|
||||
entries.Add((playlist, playlist.Title, hasSyncUrl, blGuid, ownerId));
|
||||
}
|
||||
|
||||
BeatLeaderPlaylistOwnership.ScheduleVerifyAndLog(entries, log);
|
||||
yield break;
|
||||
}
|
||||
|
||||
var entries = new List<(IPlaylist Playlist, string Title, bool HasSyncUrl, string BeatLeaderGuid, string OwnerId)>();
|
||||
foreach (var playlist in playlists)
|
||||
{
|
||||
BeatLeaderPlaylistOwnership.TryReadBeatLeaderMetadata(
|
||||
playlist,
|
||||
out var hasSyncUrl,
|
||||
out var blGuid,
|
||||
out var ownerId);
|
||||
|
||||
entries.Add((playlist, playlist.Title, hasSyncUrl, blGuid, ownerId));
|
||||
}
|
||||
|
||||
BeatLeaderPlaylistOwnership.ScheduleVerifyAndLog(entries, Log);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
waited += PlaylistScanPollStepSeconds;
|
||||
yield return new WaitForSeconds(PlaylistScanPollStepSeconds);
|
||||
}
|
||||
|
||||
log.Info("No playlists loaded after startup wait.");
|
||||
}
|
||||
|
||||
[OnExit]
|
||||
|
||||
Reference in New Issue
Block a user