Compare commits

...

3 commits

Author SHA1 Message Date
ad155026d1 Updated MainWindow
Switched from IsPressed to IsChecked, which works as intended.
2025-07-31 07:22:13 -05:00
08f5038abd Updated App
Added resetting of SettingsDirty when we ResetSettings(),
SaveSettings(), and first load in Settings.
Added more noise to know what is going on.
2025-07-31 07:21:57 -05:00
433797caae Updated Syncer
Added More noise to logging, so things can be seen happening.
2025-07-31 07:20:53 -05:00
3 changed files with 39 additions and 5 deletions

View file

@ -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();

View file

@ -28,11 +28,11 @@
<Grid
ColumnDefinitions="170,*"
RowDefinitions="*,*,*">
<ToggleSwitch Grid.Row="0" Grid.Column="0" IsPressed="{Binding SyncHistory, Mode=TwoWay}" OnContent="Sync History" />
<ToggleSwitch Grid.Row="0" Grid.Column="1" IsPressed="{Binding SyncPlaylist, Mode=TwoWay}" OnContent="Sync Playlists"/>
<ToggleSwitch Grid.Row="1" Grid.Column="0" IsPressed="{Binding SyncProfile, Mode=TwoWay}" OnContent="Sync Profiles"/>
<ToggleSwitch Grid.Row="1" Grid.Column="1" IsPressed="{Binding SyncSearchHistory, Mode=TwoWay}" OnContent="Sync Search History"/>
<ToggleSwitch Grid.Row="2" Grid.Column="0" IsPressed="{Binding SyncSettings, Mode=TwoWay}" OnContent="Sync Settings"/>
<ToggleSwitch Grid.Row="0" Grid.Column="0" IsChecked="{Binding SyncHistory, Mode=TwoWay}" OnContent="Sync History" />
<ToggleSwitch Grid.Row="0" Grid.Column="1" IsChecked="{Binding SyncPlaylist, Mode=TwoWay}" OnContent="Sync Playlists"/>
<ToggleSwitch Grid.Row="1" Grid.Column="0" IsChecked="{Binding SyncProfile, Mode=TwoWay}" OnContent="Sync Profiles"/>
<ToggleSwitch Grid.Row="1" Grid.Column="1" IsChecked="{Binding SyncSearchHistory, Mode=TwoWay}" OnContent="Sync Search History"/>
<ToggleSwitch Grid.Row="2" Grid.Column="0" IsChecked="{Binding SyncSettings, Mode=TwoWay}" OnContent="Sync Settings"/>
</Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">

View file

@ -67,17 +67,27 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
public async Task<bool> 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<T> : 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<T>(_restEndpoint, item);
}
@ -122,11 +133,16 @@ public class Syncer<T> : 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<T> : ISyncer where T : class, IDataModel, new()
if (!_isDirty)
return;
_syncing = true;
// TODO: Replace with Logger
Console.WriteLine($"Syncing {_dbPath}...");
var json = new List<string>();
foreach (var entry in _entries)
@ -187,6 +204,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
fh.Close();
}
_watcher.Locked = false;
// TODO: Replace with Logger
Console.WriteLine($"Updated {_dbPath}.");
_isDirty = false;
_syncing = false;