diff --git a/Handlers/SnapcastHandler.cs b/Handlers/SnapcastHandler.cs index 4313840..f3e4f47 100644 --- a/Handlers/SnapcastHandler.cs +++ b/Handlers/SnapcastHandler.cs @@ -1,4 +1,6 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; +using System.Windows; namespace unison { @@ -6,20 +8,34 @@ namespace unison { private readonly Process _snapcast = new(); public bool Started { get; private set; } - private string _snapcastVersion = "snapclient_0.25.0-1_win64"; + private string _snapcastPath; public SnapcastHandler() { + // wip: this will have to be moved after the mpd connection, later on + _snapcastPath = Properties.Settings.Default.snapcast_path; + if (Properties.Settings.Default.snapcast_startup) + Start(); } - public void Start(string host) + public void Start() { if (!Started) { - _snapcast.StartInfo.FileName = _snapcastVersion + @"\snapclient.exe"; - _snapcast.StartInfo.Arguments = "--host " + host; + _snapcast.StartInfo.FileName = _snapcastPath + @"\snapclient.exe"; + _snapcast.StartInfo.Arguments = $"--host {Properties.Settings.Default.mpd_host}"; _snapcast.StartInfo.CreateNoWindow = true; - _snapcast.Start(); + try + { + _snapcast.Start(); + } + catch (Exception err) + { + MessageBox.Show($"[Snapcast error]\nInvalid path: {err.Message}\n\nCurrent path: {_snapcastPath}\nYou can reset it in the settings if needed.", + "unison", MessageBoxButton.OK, MessageBoxImage.Error); + Trace.WriteLine(err.Message); + return; + } Started = true; } else diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index b18ba0b..78e8bdf 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -82,5 +82,17 @@ namespace unison.Properties { this["snapcast_path"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1704")] + public int snapcast_port { + get { + return ((int)(this["snapcast_port"])); + } + set { + this["snapcast_port"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index a4a83aa..24940ea 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -17,5 +17,8 @@ snapclient_0.25.0-1_win64 + + 1704 + \ No newline at end of file diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs index 56907ef..bc28e34 100644 --- a/Views/MainWindow.xaml.cs +++ b/Views/MainWindow.xaml.cs @@ -205,7 +205,7 @@ namespace unison { SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"]; if (!snapcast.Started) - snapcast.Start(_mpd.MpdHost); + snapcast.Start(); else snapcast.Stop(); } diff --git a/Views/Settings.xaml b/Views/Settings.xaml index bb35767..5324d3c 100644 --- a/Views/Settings.xaml +++ b/Views/Settings.xaml @@ -55,9 +55,11 @@ + + - - + + You can change to your own locally installed version of the Snapcast client with an absolute path.