Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mocked tray app #10

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions App/App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Coder.Desktop.App</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Manifest Include="$(ApplicationManifest)"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0"/>
<PackageReference Include="DependencyPropertyGenerator" Version="1.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.2.0"/>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742"/>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250108002"/>
</ItemGroup>

<ItemGroup>
<Page Update="TrayIcon.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<ItemGroup>
<Page Update="HorizontalRule.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<!-- Publish Properties -->
<PropertyGroup>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions App/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<Application
x:Class="Coder.Desktop.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
29 changes: 29 additions & 0 deletions App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.UI.Xaml;

namespace Coder.Desktop.App;

public partial class App : Application
{
private TrayWindow? TrayWindow;

public App()
{
InitializeComponent();
}

private bool HandleClosedEvents { get; } = true;

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
TrayWindow = new TrayWindow();
TrayWindow.Closed += (sender, args) =>
{
// TODO: wire up HandleClosedEvents properly
if (HandleClosedEvents)
{
args.Handled = true;
TrayWindow.AppWindow.Hide();
}
};
}
}
Binary file added App/Assets/coder_icon_32_dark.ico
Binary file not shown.
Binary file added App/Assets/coder_icon_32_light.ico
Binary file not shown.
16 changes: 16 additions & 0 deletions App/HorizontalRule.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<UserControl
x:Class="Coder.Desktop.App.HorizontalRule"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Border
Background="{ThemeResource DefaultTextForegroundThemeBrush}"
Opacity="0.3"
Height="1"
HorizontalAlignment="Stretch" />
</UserControl>
11 changes: 11 additions & 0 deletions App/HorizontalRule.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.UI.Xaml.Controls;

namespace Coder.Desktop.App;

public sealed partial class HorizontalRule : UserControl
{
public HorizontalRule()
{
InitializeComponent();
}
}
72 changes: 72 additions & 0 deletions App/TrayIcon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>

<UserControl
x:Class="Coder.Desktop.App.TrayIcon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="using:H.NotifyIcon"
mc:Ignorable="d">

<UserControl.Resources>
<!-- Icons are used from .cs -->
<!-- ReSharper disable Xaml.RedundantResource -->
<BitmapImage x:Key="IconLightTheme" UriSource="ms-appx:///Assets/coder_icon_32_dark.ico" />
<BitmapImage x:Key="IconDarkTheme" UriSource="ms-appx:///Assets/coder_icon_32_light.ico" />
<!-- ReSharper restore Xaml.RedundantResource -->
</UserControl.Resources>

<tb:TaskbarIcon
x:Name="TaskbarIcon"
Visibility="Visible"
ToolTipText="Coder"
ContextMenuMode="SecondWindow"
LeftClickCommand="{x:Bind OpenCommand}"
NoLeftClickDelay="True">

<tb:TaskbarIcon.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem>
<MenuFlyoutItem.Command>
<XamlUICommand
Label="Show Window"
Description="Show Window"
Command="{x:Bind OpenCommand}">

<XamlUICommand.IconSource>
<SymbolIconSource Symbol="OpenPane" />
</XamlUICommand.IconSource>
<XamlUICommand.KeyboardAccelerators>
<KeyboardAccelerator
Key="S"
Modifiers="Control" />
</XamlUICommand.KeyboardAccelerators>
</XamlUICommand>
</MenuFlyoutItem.Command>
</MenuFlyoutItem>

<MenuFlyoutSeparator />

<MenuFlyoutItem>
<MenuFlyoutItem.Command>
<XamlUICommand
Label="Exit"
Description="Exit"
Command="{x:Bind ExitCommand}">

<XamlUICommand.IconSource>
<SymbolIconSource Symbol="ClosePane" />
</XamlUICommand.IconSource>
<XamlUICommand.KeyboardAccelerators>
<KeyboardAccelerator
Key="E"
Modifiers="Control" />
</XamlUICommand.KeyboardAccelerators>
</XamlUICommand>
</MenuFlyoutItem.Command>
</MenuFlyoutItem>
</MenuFlyout>
</tb:TaskbarIcon.ContextFlyout>
</tb:TaskbarIcon>
</UserControl>
45 changes: 45 additions & 0 deletions App/TrayIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Diagnostics;
using System.Windows.Input;
using Windows.UI.ViewManagement;
using DependencyPropertyGenerator;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;

namespace Coder.Desktop.App;

[DependencyProperty<ICommand>("OpenCommand")]
[DependencyProperty<ICommand>("ExitCommand")]
public sealed partial class TrayIcon : UserControl
{
private readonly UISettings _uiSettings = new();

public TrayIcon()
{
InitializeComponent();
_uiSettings.ColorValuesChanged += OnColorValuesChanged;
UpdateTrayIconBasedOnTheme();
}

private void OnColorValuesChanged(UISettings sender, object args)
{
DispatcherQueue.TryEnqueue(UpdateTrayIconBasedOnTheme);
}

private void UpdateTrayIconBasedOnTheme()
{
var currentTheme = Application.Current.RequestedTheme;
Debug.WriteLine("Theme update requested, found theme: " + currentTheme);

switch (currentTheme)
{
case ApplicationTheme.Dark:
TaskbarIcon.IconSource = (BitmapImage)Resources["IconDarkTheme"];
break;
case ApplicationTheme.Light:
default:
TaskbarIcon.IconSource = (BitmapImage)Resources["IconLightTheme"];
break;
}
}
}
Loading