Fixed Systray NotifyPropertyChanged, shortcut setting window

This commit is contained in:
Théo Marchal 2021-08-14 11:27:26 +02:00
parent 6dd31fcdff
commit c95094a003
10 changed files with 63 additions and 73 deletions

View File

@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:unison"
ShutdownMode="OnExplicitShutdown">
<!--StartupUri="MainWindow.xaml"-->
<Application.Resources>
<ResourceDictionary>

View File

@ -61,7 +61,7 @@ namespace unison
if (msg == WM_HOTKEY && wParam.ToInt32() == HOTKEY_ID)
{
uint vkey = (((uint)lParam >> 16) & 0xFFFF);
uint vkey = ((uint)lParam >> 16) & 0xFFFF;
MainWindow AppWindow = (MainWindow)Application.Current.MainWindow;
switch (vkey)
{

View File

@ -8,7 +8,7 @@
xmlns:local="clr-namespace:unison"
mc:Ignorable="d"
Title="unison"
Closing="Window_Closing" Icon="/unison.ico" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight">
Closing="Window_Closing" Icon="/images/unison.ico" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight">
<Grid Background="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" MinHeight="270">
<Grid x:Name="TopLayout" Margin="10,0,10,0" VerticalAlignment="Stretch" Width="Auto" Height="Auto">

View File

@ -6,7 +6,7 @@
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
xmlns:local="clr-namespace:unison"
mc:Ignorable="d"
Closing="Window_Closing" Title="Settings" ResizeMode="CanMinimize" Icon="/unison.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
Closing="Window_Closing" Title="Settings" ResizeMode="CanMinimize" Icon="/images/unison.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
<Grid>
<StackPanel Orientation="Vertical">
<TabControl Margin="10">
@ -68,6 +68,47 @@
</DockPanel>
</TabItem>
<TabItem Header="Shortcuts">
<DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="⌨️ Shortcuts"/>
</StackPanel>
</GroupBox.Header>
<Grid>
<Grid MinWidth="220">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Next track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="0" Margin="1"/>
<TextBlock Text="Previous track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="1" Margin="1"/>
<TextBlock Text="Play / Pause" TextWrapping="Wrap" Grid.Column="0" Grid.Row="2" Margin="1"/>
<TextBlock Text="Volume up" TextWrapping="Wrap" Grid.Column="0" Grid.Row="3" Margin="1"/>
<TextBlock Text="Volume down" TextWrapping="Wrap" Grid.Column="0" Grid.Row="4" Margin="1"/>
<TextBlock Text="Show window" TextWrapping="Wrap" Grid.Column="0" Grid.Row="5" Margin="1"/>
<TextBlock Text="ctrl + media_next" TextWrapping="Wrap" Grid.Column="1" Grid.Row="0" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + media_prev" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + media_play" TextWrapping="Wrap" Grid.Column="1" Grid.Row="2" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + volume_up" TextWrapping="Wrap" Grid.Column="1" Grid.Row="3" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + volume_down" TextWrapping="Wrap" Grid.Column="1" Grid.Row="4" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + alt + enter" TextWrapping="Wrap" Grid.Column="1" Grid.Row="5" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
</Grid>
</Grid>
</GroupBox>
</DockPanel>
</TabItem>
<TabItem Header="About" Height="20" VerticalAlignment="Bottom">
<DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">

View File

@ -1,16 +1,15 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:unison">
<tb:TaskbarIcon x:Name="SystrayTaskbar" xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
IconSource="/unison.ico" ToolTipText="{Binding GetAppText}" DoubleClickCommand="{Binding ShowWindowCommand}" x:Key="SystrayTaskbar">
IconSource="/images/unison.ico" ToolTipText="{Binding GetAppText}" DoubleClickCommand="{Binding ShowWindowCommand}" x:Key="SystrayTaskbar">
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem IsEnabled="False">
<MenuItem.Icon>
<Image Source="/unison.ico" Width="16" Height="16"/>
<Image Source="/images/unison.ico" Width="16" Height="16"/>
</MenuItem.Icon>
<MenuItem.Header>
<TextBlock Text="{Binding GetAppText}" />
@ -46,7 +45,7 @@
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
<tb:TaskbarIcon.DataContext>
<local:NotifyIconViewModel />
<local:SystrayViewModel />
</tb:TaskbarIcon.DataContext>
</tb:TaskbarIcon>

View File

@ -1,23 +0,0 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
/*namespace unison
{
public partial class Systray : ResourceDictionary, INotifyPropertyChanged
{
public Systray()
{
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}*/

View File

@ -3,23 +3,13 @@ using System.Windows.Input;
using System.Reflection;
using System.ComponentModel;
using System;
using System.Windows.Threading;
namespace unison
{
public class NotifyIconViewModel : INotifyPropertyChanged
public class SystrayViewModel : INotifyPropertyChanged
{
private DispatcherTimer timer;
public NotifyIconViewModel()
public SystrayViewModel()
{
//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;
@ -51,7 +41,6 @@ namespace unison
{
get
{
//Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
return snapcast.Started ? "Stop Snapcast" : "Start Snapcast";
}
@ -61,11 +50,13 @@ namespace unison
{
get
{
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
NotifyPropertyChanged("SnapcastText");
return new DelegateCommand
{
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Snapcast_Clicked(null, null),
CommandAction = () =>
{
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
((MainWindow)Application.Current.MainWindow).Snapcast_Clicked(null, null);
},
CanExecuteFunc = () => true
};
}
@ -77,26 +68,15 @@ namespace unison
{
return new DelegateCommand
{
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Settings_Clicked(null, null),
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)
@ -104,11 +84,5 @@ namespace unison
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
private void NotifyPropertyChanged(string propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}

View File

@ -4,7 +4,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>unison.ico</ApplicationIcon>
<ApplicationIcon>images\unison.ico</ApplicationIcon>
<Win32Resource></Win32Resource>
<StartupObject>unison.App</StartupObject>
<Version>0.0.1</Version>
@ -13,6 +13,7 @@
<ItemGroup>
<None Remove="images\nocover-test.png" />
<None Remove="images\nocover.png" />
<None Remove="images\unison.ico" />
<None Remove="LICENSE" />
<None Remove="snapclient_0.25.0-1_win64\FLAC.dll" />
<None Remove="snapclient_0.25.0-1_win64\ogg.dll" />
@ -21,7 +22,6 @@
<None Remove="snapclient_0.25.0-1_win64\snapclient.exe" />
<None Remove="snapclient_0.25.0-1_win64\soxr.dll" />
<None Remove="snapclient_0.25.0-1_win64\vorbis.dll" />
<None Remove="unison.ico" />
</ItemGroup>
<ItemGroup>
@ -37,7 +37,7 @@
<Content Include="snapclient_0.25.0-1_win64\README.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Resource Include="unison.ico">
<Resource Include="images\unison.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Content Include="snapclient_0.25.0-1_win64\FLAC.dll">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB