Skip to content

Commit

Permalink
Created basic tray icon, and switched the app to use it on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sypwn committed Dec 1, 2023
1 parent 8ada456 commit 63eae41
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 3 deletions.
3 changes: 1 addition & 2 deletions WinAudioAssistant/App.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Application x:Class="WinAudioAssistant.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WinAudioAssistant"
StartupUri="Views\DevicePriorityView.xaml">
xmlns:local="clr-namespace:WinAudioAssistant">
<Application.Resources>

</Application.Resources>
Expand Down
3 changes: 2 additions & 1 deletion WinAudioAssistant/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows;
using WinAudioAssistant.Models;
using AudioSwitcher.AudioApi.CoreAudio;
using WinAudioAssistant.Views;

namespace WinAudioAssistant
{
Expand All @@ -29,9 +30,9 @@ protected override void OnStartup(StartupEventArgs e)
base.OnStartup(e);

UserSettings = UserSettings.LoadAtStartup();

SystemEventsHandler.RegisterAllEvents();
AudioEndpointManager.UpdateCachedEndpoints();
new TrayIconView();
}
}

Expand Down
Binary file added WinAudioAssistant/Resources/Icons/Icon1.ico
Binary file not shown.
44 changes: 44 additions & 0 deletions WinAudioAssistant/ViewModels/TrayIconViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using WinAudioAssistant.Views;

namespace WinAudioAssistant.ViewModels
{
class TrayIconViewModel
{

public ICommand DoubleClickCommand { get; }
public ICommand SettingsCommand { get; }
public ICommand ExitCommand { get; }

public TrayIconViewModel()
{
DoubleClickCommand = new RelayCommand(Settings);
SettingsCommand = new RelayCommand(Settings);
ExitCommand = new RelayCommand(Exit);
}

private void Settings(object? parameter)
{
foreach (var window in App.Current.Windows)
{
if (window is DevicePriorityView devicePriorityView)
{
devicePriorityView.Focus();
return;
}
}
new DevicePriorityView().Show();
}

private void Exit(object? parameter)
{
App.Current.Shutdown();
}

}
}
26 changes: 26 additions & 0 deletions WinAudioAssistant/Views/TrayIconView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Window x:Class="WinAudioAssistant.Views.TrayIconView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:WinAudioAssistant.Views"
xmlns:viewmodels="clr-namespace:WinAudioAssistant.ViewModels"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="TrayIcon">
<Window.DataContext>
<viewmodels:TrayIconViewModel/>
</Window.DataContext>
<Grid>
<tb:TaskbarIcon IconSource="/Resources/Icons/Icon1.ico" ToolTipText="WinAudioAssistant"
DoubleClickCommand="{Binding DoubleClickCommand}" >
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Settings" Command="{Binding SettingsCommand}" />
<MenuItem Header="Exit" Command="{Binding ExitCommand}" />
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
</Grid>
</Window>
27 changes: 27 additions & 0 deletions WinAudioAssistant/Views/TrayIconView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WinAudioAssistant.Views
{
/// <summary>
/// Interaction logic for TrayIconView.xaml
/// </summary>
public partial class TrayIconView : Window
{
public TrayIconView()
{
InitializeComponent();
}
}
}
3 changes: 3 additions & 0 deletions WinAudioAssistant/WinAudioAssistant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\Icons\Icon1.ico" />
<None Remove="Resources\Icons\MissingFile.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.1" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
</ItemGroup>
Expand Down Expand Up @@ -43,6 +45,7 @@
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\Icons\Icon1.ico" />
<Resource Include="Resources\Icons\MissingFile.ico" />
</ItemGroup>
</Project>

0 comments on commit 63eae41

Please sign in to comment.