Load and save settings
This commit is contained in:
@ -22,17 +22,17 @@
|
||||
<StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="Host" TextWrapping="Wrap" Margin="5,0,0,0"/>
|
||||
<TextBox Text="192.168.0.1" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
<TextBox x:Name="MpdHost" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Margin="0,5,0,0">
|
||||
<TextBlock Text="Port" TextWrapping="Wrap" Margin="5,0,0,0"/>
|
||||
<TextBox Text="6600" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
<TextBox x:Name="MpdPort" MaxLength="5" PreviewTextInput="NumberValidationTextBox" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Margin="0,5,0,0">
|
||||
<TextBlock Text="Password" TextWrapping="Wrap" Margin="5,0,0,0"/>
|
||||
<TextBox Text="" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
<TextBox x:Name="MpdPassword" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
</StackPanel>
|
||||
<Button Content="Connect" Margin="0,10,0,0" Width="120"/>
|
||||
</StackPanel>
|
||||
@ -52,15 +52,15 @@
|
||||
<Grid VerticalAlignment="Top">
|
||||
<StackPanel>
|
||||
<StackPanel>
|
||||
<CheckBox Margin="5, 5, 0, 0">
|
||||
<CheckBox x:Name="SnapcastStartup" Margin="5, 5, 0, 0">
|
||||
<TextBlock Text="Launch at startup" TextWrapping="Wrap"/>
|
||||
</CheckBox>
|
||||
<TextBlock Text="Executable path" TextWrapping="Wrap" Margin="5,5,0,0"/>
|
||||
<TextBox Text="snapclient_0.25.0-1_win64" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
|
||||
<TextBlock TextWrapping="Wrap" Margin="5,5,0,0" TextAlignment="Left" Width="250">
|
||||
<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">
|
||||
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"/>
|
||||
<Button Content="Reset" Margin="0,10,0,0" Width="120" Click="SnapcastReset_Clicked"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
@ -2,16 +2,20 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public partial class Settings : Window
|
||||
{
|
||||
public string GetVersion => Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
private string defaultSnapcast = "snapclient_0.25.0-1_win64";
|
||||
|
||||
public string GetLicense
|
||||
public static string GetVersion => Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
|
||||
public static string GetLicense
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -19,7 +23,7 @@ namespace unison
|
||||
{
|
||||
StreamReader Reader = new("LICENSE");
|
||||
string file = "";
|
||||
file = file + Reader.ReadToEnd();
|
||||
file += Reader.ReadToEnd();
|
||||
return file;
|
||||
}
|
||||
catch (IOException e)
|
||||
@ -35,6 +39,18 @@ namespace unison
|
||||
DataContext = this;
|
||||
|
||||
WindowState = WindowState.Minimized;
|
||||
|
||||
MpdHost.Text = Properties.Settings.Default.mpd_host;
|
||||
MpdPort.Text = Properties.Settings.Default.mpd_port.ToString();
|
||||
MpdPassword.Text = Properties.Settings.Default.mpd_password;
|
||||
SnapcastStartup.IsChecked = Properties.Settings.Default.snapcast_startup;
|
||||
SnapcastPath.Text = Properties.Settings.Default.snapcast_path;
|
||||
}
|
||||
|
||||
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new Regex("[^0-9]+");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
@ -45,9 +61,22 @@ namespace unison
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void SnapcastReset_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SnapcastPath.Text = defaultSnapcast;
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
|
||||
Properties.Settings.Default.mpd_host = MpdHost.Text;
|
||||
Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text);
|
||||
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.Save();
|
||||
|
||||
WindowState = WindowState.Minimized;
|
||||
Hide();
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ namespace unison
|
||||
{
|
||||
public class SystrayViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public string GetAppText => "unison v" + Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
public static string GetAppText => "unison v" + Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
|
||||
public ICommand ShowWindowCommand => new DelegateCommand
|
||||
public static ICommand ShowWindowCommand => new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
@ -24,7 +24,7 @@ namespace unison
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
|
||||
public ICommand ExitApplicationCommand => new DelegateCommand
|
||||
public static ICommand ExitApplicationCommand => new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
@ -33,7 +33,7 @@ namespace unison
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
|
||||
public string SnapcastText
|
||||
public static string SnapcastText
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -77,8 +77,7 @@ namespace unison
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user