UI update, almost complete support of Taskbar, classes separation and organization
This commit is contained in:
27
windowless/DelegateCommand.cs
Normal file
27
windowless/DelegateCommand.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public class DelegateCommand : ICommand
|
||||
{
|
||||
public Action CommandAction { get; set; }
|
||||
public Func<bool> CanExecuteFunc { get; set; }
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
CommandAction();
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return CanExecuteFunc == null || CanExecuteFunc();
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
}
|
||||
}
|
114
windowless/NotifyIconViewModel.cs
Normal file
114
windowless/NotifyIconViewModel.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using System;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public class NotifyIconViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private DispatcherTimer timer;
|
||||
|
||||
public NotifyIconViewModel()
|
||||
{
|
||||
//timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, OnTimerTick, Application.Current.Dispatcher);
|
||||
}
|
||||
|
||||
private void OnTimerTick(object sender, EventArgs e)
|
||||
{
|
||||
//fire a property change event for the timestamp
|
||||
//Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
|
||||
}
|
||||
|
||||
public string GetAppText => "unison v" + Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
|
||||
public 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
|
||||
};
|
||||
|
||||
public ICommand ExitApplicationCommand => new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
},
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
|
||||
public string SnapcastText
|
||||
{
|
||||
get
|
||||
{
|
||||
//Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
|
||||
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
|
||||
return snapcast.Started ? "Stop Snapcast" : "Start Snapcast";
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand Snapcast
|
||||
{
|
||||
get
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
|
||||
NotifyPropertyChanged("SnapcastText");
|
||||
return new DelegateCommand
|
||||
{
|
||||
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Snapcast_Clicked(null, null),
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DelegateCommand
|
||||
{
|
||||
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Settings_Clicked(null, null),
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSnapcastText
|
||||
{
|
||||
get
|
||||
{
|
||||
/*if (Application.Current.MainWindow != null)
|
||||
{
|
||||
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
|
||||
return snapcast.Started ? "Stop Snapcast" : "Start Snapcast";
|
||||
}
|
||||
return "not initialized";*/
|
||||
return SnapcastText;
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void NotifyPropertyChanged(string propertyName = "")
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user