Snapcast port and auto start working

This commit is contained in:
Théo Marchal 2021-08-15 01:18:23 +02:00
parent 7babd50c3f
commit ebd4e8e530
6 changed files with 49 additions and 12 deletions

View File

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

View File

@ -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;
}
}
}
}

View File

@ -17,5 +17,8 @@
<Setting Name="snapcast_path" Type="System.String" Scope="User">
<Value Profile="(Default)">snapclient_0.25.0-1_win64</Value>
</Setting>
<Setting Name="snapcast_port" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1704</Value>
</Setting>
</Settings>
</SettingsFile>

View File

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

View File

@ -55,9 +55,11 @@
<CheckBox x:Name="SnapcastStartup" Margin="5, 5, 0, 0">
<TextBlock Text="Launch at startup" TextWrapping="Wrap"/>
</CheckBox>
<TextBlock Text="Port" TextWrapping="Wrap" Margin="5,5,0,0"/>
<TextBox x:Name="SnapcastPort" MaxLength="5" PreviewTextInput="NumberValidationTextBox" TextWrapping="Wrap" Width="250" Margin="10,2,5,0" HorizontalAlignment="Left"/>
<TextBlock Text="Executable path" TextWrapping="Wrap" Margin="5,5,0,0"/>
<TextBox x:Name="SnapcastPath" TextWrapping="Wrap" Width="350" Margin="10,2,5,0"/>
<TextBlock TextWrapping="Wrap" Margin="5,5,0,0" TextAlignment="Left" Width="350">
<TextBox x:Name="SnapcastPath" TextWrapping="Wrap" Width="250" Margin="10,2,5,0" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" Margin="5,5,0,0" TextAlignment="Left" Width="250">
You can change to your own locally installed version of the Snapcast client with an <Run FontStyle="Italic" FontWeight="DemiBold">absolute</Run> path.
</TextBlock>
<Button Content="Reset" Margin="0,10,0,0" Width="120" Click="SnapcastReset_Clicked"/>
@ -148,7 +150,7 @@
<emoji:TextBlock Text="📝 License"/>
</GroupBox.Header>
<Grid VerticalAlignment="Top">
<TextBlock Text="{Binding GetLicense, Mode = OneWay}" TextWrapping="Wrap" Width="400" TextAlignment="Justify" />
<TextBlock Text="{Binding GetLicense, Mode = OneWay}" TextWrapping="Wrap" Width="500" TextAlignment="Justify" />
</Grid>
</GroupBox>
</DockPanel>

View File

@ -11,7 +11,8 @@ namespace unison
{
public partial class Settings : Window
{
private string defaultSnapcast = "snapclient_0.25.0-1_win64";
private string defaultSnapcastPath = "snapclient_0.25.0-1_win64";
private string defaultSnapcastPort = "1704";
public static string GetVersion => Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
@ -45,6 +46,7 @@ namespace unison
MpdPassword.Text = Properties.Settings.Default.mpd_password;
SnapcastStartup.IsChecked = Properties.Settings.Default.snapcast_startup;
SnapcastPath.Text = Properties.Settings.Default.snapcast_path;
SnapcastPort.Text = Properties.Settings.Default.snapcast_port.ToString();
}
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
@ -63,7 +65,8 @@ namespace unison
private void SnapcastReset_Clicked(object sender, RoutedEventArgs e)
{
SnapcastPath.Text = defaultSnapcast;
SnapcastPath.Text = defaultSnapcastPath;
SnapcastPort.Text = defaultSnapcastPort;
}
private void Window_Closing(object sender, CancelEventArgs e)
@ -75,6 +78,7 @@ namespace unison
Properties.Settings.Default.mpd_password = MpdPassword.Text;
Properties.Settings.Default.snapcast_startup = (bool)SnapcastStartup.IsChecked;
Properties.Settings.Default.snapcast_path = SnapcastPath.Text;
Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text);
Properties.Settings.Default.Save();
WindowState = WindowState.Minimized;