unison/Views/SystrayViewModel.cs

103 lines
3.2 KiB
C#
Raw Normal View History

using System.Windows;
using System.Windows.Input;
using System.Reflection;
using System.ComponentModel;
using System;
namespace unison
{
public class SystrayViewModel : INotifyPropertyChanged
{
2021-09-01 00:35:37 +00:00
public event PropertyChangedEventHandler PropertyChanged;
2021-08-14 15:14:37 +00:00
public static string GetAppText => "unison v" + Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
2021-08-14 15:14:37 +00:00
public static ICommand ShowWindowCommand => new DelegateCommand
{
CommandAction = () =>
{
Window AppWindow = Application.Current.MainWindow;
AppWindow.Show();
AppWindow.Activate();
if (AppWindow.WindowState == WindowState.Minimized)
AppWindow.WindowState = WindowState.Normal;
},
CanExecuteFunc = () => true
};
2021-08-14 15:14:37 +00:00
public static ICommand ExitApplicationCommand => new DelegateCommand
{
2021-09-01 00:35:37 +00:00
CommandAction = () => Application.Current.Shutdown(),
CanExecuteFunc = () => true
};
2021-08-20 16:26:32 +00:00
public string SnapcastText
{
get
{
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
return snapcast.HasStarted ? unison.Resources.Resources.StopSnapcast : unison.Resources.Resources.StartSnapcast;
}
}
public ICommand Snapcast
{
get
{
return new DelegateCommand
{
CommandAction = () =>
{
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
2021-09-01 00:35:37 +00:00
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
snapcast.LaunchOrExit();
},
CanExecuteFunc = () => true
};
}
}
2021-10-04 12:06:20 +00:00
public ICommand Radios
{
get
{
return new DelegateCommand
{
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Radios_Clicked(null, null),
CanExecuteFunc = () => true
};
}
}
2021-10-05 12:23:23 +00:00
public ICommand Shuffle
{
get
{
return new DelegateCommand
{
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Shuffle_Clicked(null, null),
CanExecuteFunc = () => true
};
}
}
public ICommand Settings
{
get
{
return new DelegateCommand
{
2021-09-01 00:35:37 +00:00
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Settings_Clicked(null, null),
CanExecuteFunc = () => true
};
}
}
2021-08-20 16:26:32 +00:00
public virtual void OnPropertyChanged(string propertyName)
{
2021-08-14 15:14:37 +00:00
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}