Skip to content

Commit 6ecbc3f

Browse files
authored
feat: add mocked tray app (#10)
1 parent 29d485b commit 6ecbc3f

27 files changed

+1057
-51
lines changed

App/App.csproj

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
5+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
6+
<RootNamespace>Coder.Desktop.App</RootNamespace>
7+
<ApplicationManifest>app.manifest</ApplicationManifest>
8+
<Platforms>x86;x64;ARM64</Platforms>
9+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
10+
<UseWinUI>true</UseWinUI>
11+
<Nullable>enable</Nullable>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<Manifest Include="$(ApplicationManifest)"/>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0"/>
20+
<PackageReference Include="DependencyPropertyGenerator" Version="1.5.0">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.2.0"/>
25+
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742"/>
26+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250108002"/>
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Page Update="TrayIcon.xaml">
31+
<Generator>MSBuild:Compile</Generator>
32+
</Page>
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<Page Update="HorizontalRule.xaml">
37+
<Generator>MSBuild:Compile</Generator>
38+
</Page>
39+
</ItemGroup>
40+
41+
<!-- Publish Properties -->
42+
<PropertyGroup>
43+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
44+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
45+
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
46+
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
47+
</PropertyGroup>
48+
</Project>

App/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Application
4+
x:Class="Coder.Desktop.App.App"
5+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

App/App.xaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.UI.Xaml;
2+
3+
namespace Coder.Desktop.App;
4+
5+
public partial class App : Application
6+
{
7+
private TrayWindow? TrayWindow;
8+
9+
public App()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private bool HandleClosedEvents { get; } = true;
15+
16+
protected override void OnLaunched(LaunchActivatedEventArgs args)
17+
{
18+
TrayWindow = new TrayWindow();
19+
TrayWindow.Closed += (sender, args) =>
20+
{
21+
// TODO: wire up HandleClosedEvents properly
22+
if (HandleClosedEvents)
23+
{
24+
args.Handled = true;
25+
TrayWindow.AppWindow.Hide();
26+
}
27+
};
28+
}
29+
}

App/Assets/coder_icon_32_dark.ico

4.21 KB
Binary file not shown.

App/Assets/coder_icon_32_light.ico

4.21 KB
Binary file not shown.

App/HorizontalRule.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<UserControl
4+
x:Class="Coder.Desktop.App.HorizontalRule"
5+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<Border
12+
Background="{ThemeResource DefaultTextForegroundThemeBrush}"
13+
Opacity="0.3"
14+
Height="1"
15+
HorizontalAlignment="Stretch" />
16+
</UserControl>

App/HorizontalRule.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
3+
namespace Coder.Desktop.App;
4+
5+
public sealed partial class HorizontalRule : UserControl
6+
{
7+
public HorizontalRule()
8+
{
9+
InitializeComponent();
10+
}
11+
}

App/TrayIcon.xaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<UserControl
4+
x:Class="Coder.Desktop.App.TrayIcon"
5+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:tb="using:H.NotifyIcon"
10+
mc:Ignorable="d">
11+
12+
<UserControl.Resources>
13+
<!-- Icons are used from .cs -->
14+
<!-- ReSharper disable Xaml.RedundantResource -->
15+
<BitmapImage x:Key="IconLightTheme" UriSource="ms-appx:///Assets/coder_icon_32_dark.ico" />
16+
<BitmapImage x:Key="IconDarkTheme" UriSource="ms-appx:///Assets/coder_icon_32_light.ico" />
17+
<!-- ReSharper restore Xaml.RedundantResource -->
18+
</UserControl.Resources>
19+
20+
<tb:TaskbarIcon
21+
x:Name="TaskbarIcon"
22+
Visibility="Visible"
23+
ToolTipText="Coder"
24+
ContextMenuMode="SecondWindow"
25+
LeftClickCommand="{x:Bind OpenCommand}"
26+
NoLeftClickDelay="True">
27+
28+
<tb:TaskbarIcon.ContextFlyout>
29+
<MenuFlyout>
30+
<MenuFlyoutItem>
31+
<MenuFlyoutItem.Command>
32+
<XamlUICommand
33+
Label="Show Window"
34+
Description="Show Window"
35+
Command="{x:Bind OpenCommand}">
36+
37+
<XamlUICommand.IconSource>
38+
<SymbolIconSource Symbol="OpenPane" />
39+
</XamlUICommand.IconSource>
40+
<XamlUICommand.KeyboardAccelerators>
41+
<KeyboardAccelerator
42+
Key="S"
43+
Modifiers="Control" />
44+
</XamlUICommand.KeyboardAccelerators>
45+
</XamlUICommand>
46+
</MenuFlyoutItem.Command>
47+
</MenuFlyoutItem>
48+
49+
<MenuFlyoutSeparator />
50+
51+
<MenuFlyoutItem>
52+
<MenuFlyoutItem.Command>
53+
<XamlUICommand
54+
Label="Exit"
55+
Description="Exit"
56+
Command="{x:Bind ExitCommand}">
57+
58+
<XamlUICommand.IconSource>
59+
<SymbolIconSource Symbol="ClosePane" />
60+
</XamlUICommand.IconSource>
61+
<XamlUICommand.KeyboardAccelerators>
62+
<KeyboardAccelerator
63+
Key="E"
64+
Modifiers="Control" />
65+
</XamlUICommand.KeyboardAccelerators>
66+
</XamlUICommand>
67+
</MenuFlyoutItem.Command>
68+
</MenuFlyoutItem>
69+
</MenuFlyout>
70+
</tb:TaskbarIcon.ContextFlyout>
71+
</tb:TaskbarIcon>
72+
</UserControl>

App/TrayIcon.xaml.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Diagnostics;
2+
using System.Windows.Input;
3+
using Windows.UI.ViewManagement;
4+
using DependencyPropertyGenerator;
5+
using Microsoft.UI.Xaml;
6+
using Microsoft.UI.Xaml.Controls;
7+
using Microsoft.UI.Xaml.Media.Imaging;
8+
9+
namespace Coder.Desktop.App;
10+
11+
[DependencyProperty<ICommand>("OpenCommand")]
12+
[DependencyProperty<ICommand>("ExitCommand")]
13+
public sealed partial class TrayIcon : UserControl
14+
{
15+
private readonly UISettings _uiSettings = new();
16+
17+
public TrayIcon()
18+
{
19+
InitializeComponent();
20+
_uiSettings.ColorValuesChanged += OnColorValuesChanged;
21+
UpdateTrayIconBasedOnTheme();
22+
}
23+
24+
private void OnColorValuesChanged(UISettings sender, object args)
25+
{
26+
DispatcherQueue.TryEnqueue(UpdateTrayIconBasedOnTheme);
27+
}
28+
29+
private void UpdateTrayIconBasedOnTheme()
30+
{
31+
var currentTheme = Application.Current.RequestedTheme;
32+
Debug.WriteLine("Theme update requested, found theme: " + currentTheme);
33+
34+
switch (currentTheme)
35+
{
36+
case ApplicationTheme.Dark:
37+
TaskbarIcon.IconSource = (BitmapImage)Resources["IconDarkTheme"];
38+
break;
39+
case ApplicationTheme.Light:
40+
default:
41+
TaskbarIcon.IconSource = (BitmapImage)Resources["IconLightTheme"];
42+
break;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy