Database update feature

This commit is contained in:
2022-11-14 23:53:36 +01:00
parent 8c9e1cd91c
commit 7d71d90538
9 changed files with 173 additions and 33 deletions

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@ -11,6 +12,7 @@ using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Navigation;
using System.Windows.Threading;
using unison.Handlers;
namespace unison
@ -37,8 +39,7 @@ namespace unison
}
}
HotkeyHandler _hotkeys = (HotkeyHandler)Application.Current.Properties["hotkeys"];
readonly HotkeyHandler _hotkeys = (HotkeyHandler)Application.Current.Properties["hotkeys"];
public Settings()
{
@ -74,11 +75,13 @@ namespace unison
{
ConnectionStatus.Text = $"{unison.Resources.Resources.Settings_ConnectionStatusConnected} {mpd.GetVersion()}.";
ConnectButton.IsEnabled = false;
UpdateDatabaseButton.IsEnabled = true;
}
else
{
ConnectionStatus.Text = unison.Resources.Resources.Settings_ConnectionStatusOffline;
ConnectButton.IsEnabled = true;
UpdateDatabaseButton.IsEnabled = false;
}
}
@ -146,6 +149,37 @@ namespace unison
MPDConnect_Clicked(null, null);
}
private void MPDDatabaseUpdate_Clicked(object sender, RoutedEventArgs e)
{
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
if (mpd.IsConnected())
mpd.UpdateDB();
}
private static void TimedText(TextBlock textBlock, int time)
{
DispatcherTimer Timer = new DispatcherTimer();
Timer.Interval = TimeSpan.FromSeconds(time);
Timer.Tick += (sender, args) =>
{
Timer.Stop();
textBlock.Visibility = Visibility.Collapsed;
};
Timer.Start();
}
public void MPDDatabaseUpdate_Start()
{
UpdateDBMessage.Visibility = Visibility.Visible;
}
public void MPDDatabaseUpdate_Stop()
{
UpdateDBMessage2.Visibility = Visibility.Visible;
TimedText(UpdateDBMessage, 2);
TimedText(UpdateDBMessage2, 2);
}
private void CheckUpdates(object sender, RoutedEventArgs e)
{
UpdateHandler updater = (UpdateHandler)Application.Current.Properties["updater"];