From 6fb47905c051a602f1b4736b213d5a6fb9d68906 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Thu, 31 Jul 2025 03:35:26 -0500 Subject: [PATCH] Updated Program. Removed all code from console testing, and moved into App.xaml.cs for handling of the Syncing of things in co-op with the UI Thread. --- FreeTubeSyncer/Program.cs | 95 +-------------------------------------- 1 file changed, 1 insertion(+), 94 deletions(-) diff --git a/FreeTubeSyncer/Program.cs b/FreeTubeSyncer/Program.cs index 8360c95..6558e02 100644 --- a/FreeTubeSyncer/Program.cs +++ b/FreeTubeSyncer/Program.cs @@ -18,100 +18,7 @@ class Program // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] - public static void Main(string[] args) - { - GlobalJsonOptions.Options.Converters.Add(new StringToLongJsonConverter(false)); - var paths = new string[] - { - Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config/FreeTube/"), - Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - ".var/app/io.freetubeapp.FreeTube/config/FreeTube") - }; - - var path = ""; - - foreach (var tpath in paths) - { - if (!Directory.Exists(tpath)) continue; - path = tpath; - break; - } - var dbWatcher = new DBSyncWatcher(path); - var historySyncer = new Syncer(dbWatcher, Path.Join(path, "history.db"), "history.db", "/history"); - var playlistSyncer = new Syncer(dbWatcher, Path.Join(path, "playlists.db"), "playlists.db", "/playlist"); - var profileSyncer = new Syncer(dbWatcher, Path.Join(path, "profiles.db"), "profiles.db", "/profile"); - var searchHistorySyncer = new Syncer(dbWatcher, Path.Join(path, "search-history.db"), "search-history.db", "/searchHistory"); - var settingsSyncer = new Syncer(dbWatcher, Path.Join(path, "settings.db"), "settings.db", "/settings"); - - Task.Run(() => CheckCanSync(historySyncer, playlistSyncer, profileSyncer, searchHistorySyncer, settingsSyncer)); - Console.WriteLine("Watching databases... Press return to exit..."); - Console.ReadLine(); - } - - private static void CheckCanSync(Syncer? historySyncer = null, Syncer? playlistSyncer = null, - Syncer? profileSyncer = null, Syncer? searchHistorySyncer = null, - Syncer? settingsSyncer = null) - { - var syncers = new List() - { - historySyncer, - playlistSyncer, - profileSyncer, - searchHistorySyncer, - settingsSyncer - }; - var lastTime = DateTime.Now; - var checkInterval = TimeSpan.FromSeconds(30); - while (true) - { - if (syncers.Any(x => x != null && x.IsDirty() )) - { - Thread.Sleep(100); - var lastCheck = DateTime.Now - lastTime; - if (lastCheck > checkInterval) - { - var start = DateTime.Now; - Console.WriteLine("Checking for updates..."); - foreach (var syncer in syncers) - syncer.FetchDatabase().Wait(); - lastTime = DateTime.Now; - var end = DateTime.Now - start; - Console.WriteLine($"Check completed. Total Time: {end}"); - } - - var procs = Process.GetProcessesByName("FreeTube"); - if (procs.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); - var lastCheck = DateTime.Now - lastTime; - if (lastCheck < checkInterval) continue; - var start = DateTime.Now; - Console.WriteLine("Checking for updates..."); - foreach (var syncer in syncers) - syncer.FetchDatabase().Wait(); - lastTime = DateTime.Now; - var end = DateTime.Now - start; - Console.WriteLine($"Check completed. Total Time: {end}"); - } - } - } - // public static void Main(string[] args) => BuildAvaloniaApp() - // .StartWithClassicDesktopLifetime(args); + public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp()