Updated Program
Now utilizing syncers in an Array for each checking of IsDirty() or not, and running code based upon the state of the syncers. May clean this up more. Added polling of the database to see if there's anything new to sync locally.
This commit is contained in:
parent
5887bc0961
commit
58e046c1f0
1 changed files with 43 additions and 15 deletions
|
|
@ -1,7 +1,9 @@
|
|||
using Avalonia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FreeTubeSyncer.Library;
|
||||
|
|
@ -50,23 +52,49 @@ class Program
|
|||
Syncer<Profile>? profileSyncer = null, Syncer<SearchHistory>? searchHistorySyncer = null,
|
||||
Syncer<Setting>? settingsSyncer = null)
|
||||
{
|
||||
var syncers = new List<ISyncer>()
|
||||
{
|
||||
historySyncer,
|
||||
playlistSyncer,
|
||||
profileSyncer,
|
||||
searchHistorySyncer,
|
||||
settingsSyncer
|
||||
};
|
||||
var lastTime = DateTime.Now;
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
if (Process.GetProcessesByName("FreeTube").Length > 0) continue;
|
||||
Console.WriteLine("FreeTube has closed, we're going to try and update.");
|
||||
Thread.Sleep(1500);
|
||||
|
||||
if (historySyncer is { IsDirty: true })
|
||||
historySyncer.Sync();
|
||||
if (playlistSyncer is { IsDirty: true })
|
||||
playlistSyncer.Sync();
|
||||
if (profileSyncer is { IsDirty: true})
|
||||
profileSyncer.Sync();
|
||||
if (searchHistorySyncer is { IsDirty: true})
|
||||
searchHistorySyncer.Sync();
|
||||
if (settingsSyncer is { IsDirty: true})
|
||||
settingsSyncer.Sync();
|
||||
if (syncers.Any(x => x != null && x.IsDirty() ))
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
if (lastTime - DateTime.Now > TimeSpan.FromSeconds(30))
|
||||
{
|
||||
foreach (var syncer in syncers)
|
||||
syncer.FetchDatabase().Wait();
|
||||
lastTime = DateTime.Now;
|
||||
}
|
||||
if (Process.GetProcessesByName("FreeTube").Length > 0) continue;
|
||||
Console.WriteLine("FreeTube has closed and we have updates, we're going to try and update.");
|
||||
Thread.Sleep(1500);
|
||||
|
||||
if (historySyncer != null && historySyncer.IsDirty())
|
||||
historySyncer.Sync();
|
||||
if (playlistSyncer != null && playlistSyncer.IsDirty())
|
||||
playlistSyncer.Sync();
|
||||
if (profileSyncer != null && profileSyncer.IsDirty())
|
||||
profileSyncer.Sync();
|
||||
if (searchHistorySyncer != null && searchHistorySyncer.IsDirty())
|
||||
searchHistorySyncer.Sync();
|
||||
if (settingsSyncer != null && settingsSyncer.IsDirty())
|
||||
settingsSyncer.Sync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
if (lastTime - DateTime.Now <= TimeSpan.FromSeconds(30)) continue;
|
||||
foreach (var syncer in syncers)
|
||||
syncer.FetchDatabase().Wait();
|
||||
lastTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
// public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue