diff --git a/FreeTubeSyncer/App.axaml.cs b/FreeTubeSyncer/App.axaml.cs index 0026e01..cf3a496 100644 --- a/FreeTubeSyncer/App.axaml.cs +++ b/FreeTubeSyncer/App.axaml.cs @@ -98,6 +98,7 @@ public partial class App : Application _settings.SyncProfile = @new.SyncProfile; _settings.SyncSearchHistory = @new.SyncSearchHistory; _settings.SyncSettings = @new.SyncSettings; + _settings.SettingsDirty = false; } public void SaveSettings() @@ -110,6 +111,7 @@ public partial class App : Application Directory.CreateDirectory(dir); } File.WriteAllText(path, JsonSerializer.Serialize(_settings)); + _settings!.SettingsDirty = false; SettingsChanged?.Invoke(this, EventArgs.Empty); } @@ -131,15 +133,23 @@ public partial class App : Application private async Task SyncMonitor() { + // TODO: Replace with Logger + Console.WriteLine("Sync Monitor Starting Up."); + // TODO: Replace with Logger + Console.WriteLine("Starting API Validation Check."); while (_isRunning) { await _semaphoreSlim.WaitAsync(); + if (!await _syncers![0].PingApi()) { _semaphoreSlim.Release(); await Task.Delay(5000); continue; } + + // TODO: Replace with Logger + Console.WriteLine("Fetching initial data from Database."); foreach (var syncer in _syncers!) { await syncer.FetchDatabase(); @@ -149,6 +159,8 @@ public partial class App : Application break; } + // TODO: Replace with Logger + Console.WriteLine("Starting Filesystem Sync Monitoring."); var lastCheck = DateTime.Now; while (_isRunning) { @@ -188,6 +200,9 @@ public partial class App : Application // TODO: Replace with Logger Console.WriteLine($"Sync completed in {syncEnd}."); } + + // TODO: Replace with Logger + Console.WriteLine($"Filesystem Sync Monitor Shutdown."); } private async void HandleSettingsChanged(object? sender, EventArgs e) @@ -218,6 +233,7 @@ public partial class App : Application { DataContext = _settings }; + _settings!.SettingsDirty = false; } StampSettings(); desktop.MainWindow!.Show(); diff --git a/FreeTubeSyncer/MainWindow.axaml b/FreeTubeSyncer/MainWindow.axaml index d98322d..9377531 100644 --- a/FreeTubeSyncer/MainWindow.axaml +++ b/FreeTubeSyncer/MainWindow.axaml @@ -28,11 +28,11 @@ - - - - - + + + + + diff --git a/FreeTubeSyncer/REST/Syncer.cs b/FreeTubeSyncer/REST/Syncer.cs index cf1360f..49b7ea3 100644 --- a/FreeTubeSyncer/REST/Syncer.cs +++ b/FreeTubeSyncer/REST/Syncer.cs @@ -67,17 +67,27 @@ public class Syncer : ISyncer where T : class, IDataModel, new() public async Task PingApi() { + // TODO: Replace with Logger + Console.WriteLine($"Pinging API at {_client.BuildUri(new RestRequest("/ping"))}..."); try { var res = await _client.ExecuteHeadAsync(new RestRequest("/ping")); if (res.StatusCode == HttpStatusCode.NotFound) + { + // TODO: Replace with Logger + Console.WriteLine($"Ping response 404 Not Found, Server Online!"); return true; + } } catch (Exception ex) { + // TODO: Replace with Logger + Console.WriteLine($"Network Error: {ex.Message}, API not alive."); return false; } + // TODO: Replace with Logger + Console.WriteLine("Responded with something other then 404, API not what we expected."); return false; } @@ -104,6 +114,7 @@ public class Syncer : ISyncer where T : class, IDataModel, new() if (_entries.Any(x => x.EqualId(item.Id()))) _entries.RemoveAll(x => x.EqualId(item.Id())); _entries.Add(item); + // TODO: Replace with Logger Console.WriteLine($"Posting {item.Id()}"); await _client.PostJsonAsync(_restEndpoint, item); } @@ -122,11 +133,16 @@ public class Syncer : ISyncer where T : class, IDataModel, new() if (data.Equals(entry)) continue; + // TODO: Replace with Logger Console.WriteLine($"Updated Entry for {_dbName} - {entry.Id()}"); _entries.RemoveAll(x => x.EqualId(entry.Id())); } else + { + // TODO: Replace with Logger Console.WriteLine($"New Entry for {_dbName} - {entry.Id()}"); + } + _entries.Add(entry); _isDirty = true; } @@ -174,6 +190,7 @@ public class Syncer : ISyncer where T : class, IDataModel, new() if (!_isDirty) return; _syncing = true; + // TODO: Replace with Logger Console.WriteLine($"Syncing {_dbPath}..."); var json = new List(); foreach (var entry in _entries) @@ -187,6 +204,7 @@ public class Syncer : ISyncer where T : class, IDataModel, new() fh.Close(); } _watcher.Locked = false; + // TODO: Replace with Logger Console.WriteLine($"Updated {_dbPath}."); _isDirty = false; _syncing = false;