Fix exception and SaveSettings function

This commit is contained in:
Théo Marchal 2021-08-16 13:49:19 +02:00
parent f85eae1354
commit 5d29938589
2 changed files with 10 additions and 10 deletions

View File

@ -87,6 +87,7 @@ namespace MPDCtrl.Models
double dtime = double.NaN; double dtime = double.NaN;
try try
{ {
if (Time != "")
dtime = double.Parse(Time); dtime = double.Parse(Time);
} }
catch { } catch { }

View File

@ -68,12 +68,8 @@ namespace unison
private void MPDConnect_Clicked(object sender, RoutedEventArgs e) private void MPDConnect_Clicked(object sender, RoutedEventArgs e)
{ {
Properties.Settings.Default.mpd_host = MpdHost.Text; SaveSettings();
Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text, CultureInfo.InvariantCulture); MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
Properties.Settings.Default.mpd_password = MpdPassword.Text;
Properties.Settings.Default.Save();
var mpd = (MPDHandler)Application.Current.Properties["mpd"];
mpd.Connect(); mpd.Connect();
} }
@ -83,10 +79,8 @@ namespace unison
SnapcastPort.Text = defaultSnapcastPort; SnapcastPort.Text = defaultSnapcastPort;
} }
private void Window_Closing(object sender, CancelEventArgs e) public void SaveSettings()
{ {
e.Cancel = true;
Properties.Settings.Default.mpd_host = MpdHost.Text; Properties.Settings.Default.mpd_host = MpdHost.Text;
Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text, CultureInfo.InvariantCulture); Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text, CultureInfo.InvariantCulture);
Properties.Settings.Default.mpd_password = MpdPassword.Text; Properties.Settings.Default.mpd_password = MpdPassword.Text;
@ -94,7 +88,12 @@ namespace unison
Properties.Settings.Default.snapcast_path = SnapcastPath.Text; Properties.Settings.Default.snapcast_path = SnapcastPath.Text;
Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture); Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture);
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
SaveSettings();
WindowState = WindowState.Minimized; WindowState = WindowState.Minimized;
Hide(); Hide();
} }