Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ecbc3f

Browse files
authored
feat: add mocked tray app (#10)
1 parent29d485b commit6ecbc3f

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+
<ProjectSdk="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+
<ManifestInclude="$(ApplicationManifest)"/>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<PackageReferenceInclude="CommunityToolkit.Mvvm"Version="8.4.0"/>
20+
<PackageReferenceInclude="DependencyPropertyGenerator"Version="1.5.0">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
<PackageReferenceInclude="H.NotifyIcon.WinUI"Version="2.2.0"/>
25+
<PackageReferenceInclude="Microsoft.Windows.SDK.BuildTools"Version="10.0.26100.1742"/>
26+
<PackageReferenceInclude="Microsoft.WindowsAppSDK"Version="1.6.250108002"/>
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<PageUpdate="TrayIcon.xaml">
31+
<Generator>MSBuild:Compile</Generator>
32+
</Page>
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<PageUpdate="HorizontalRule.xaml">
37+
<Generator>MSBuild:Compile</Generator>
38+
</Page>
39+
</ItemGroup>
40+
41+
<!-- Publish Properties-->
42+
<PropertyGroup>
43+
<PublishReadyToRunCondition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
44+
<PublishReadyToRunCondition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
45+
<PublishTrimmedCondition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
46+
<PublishTrimmedCondition="'$(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+
<XamlControlsResourcesxmlns="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+
usingMicrosoft.UI.Xaml;
2+
3+
namespaceCoder.Desktop.App;
4+
5+
publicpartialclassApp:Application
6+
{
7+
privateTrayWindow?TrayWindow;
8+
9+
publicApp()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
privateboolHandleClosedEvents{get;}=true;
15+
16+
protectedoverridevoidOnLaunched(LaunchActivatedEventArgsargs)
17+
{
18+
TrayWindow=newTrayWindow();
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+
usingMicrosoft.UI.Xaml.Controls;
2+
3+
namespaceCoder.Desktop.App;
4+
5+
publicsealedpartialclassHorizontalRule:UserControl
6+
{
7+
publicHorizontalRule()
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+
<BitmapImagex:Key="IconLightTheme"UriSource="ms-appx:///Assets/coder_icon_32_dark.ico" />
16+
<BitmapImagex: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+
<SymbolIconSourceSymbol="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+
<SymbolIconSourceSymbol="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+
usingSystem.Diagnostics;
2+
usingSystem.Windows.Input;
3+
usingWindows.UI.ViewManagement;
4+
usingDependencyPropertyGenerator;
5+
usingMicrosoft.UI.Xaml;
6+
usingMicrosoft.UI.Xaml.Controls;
7+
usingMicrosoft.UI.Xaml.Media.Imaging;
8+
9+
namespaceCoder.Desktop.App;
10+
11+
[DependencyProperty<ICommand>("OpenCommand")]
12+
[DependencyProperty<ICommand>("ExitCommand")]
13+
publicsealedpartialclassTrayIcon:UserControl
14+
{
15+
privatereadonlyUISettings_uiSettings=new();
16+
17+
publicTrayIcon()
18+
{
19+
InitializeComponent();
20+
_uiSettings.ColorValuesChanged+=OnColorValuesChanged;
21+
UpdateTrayIconBasedOnTheme();
22+
}
23+
24+
privatevoidOnColorValuesChanged(UISettingssender,objectargs)
25+
{
26+
DispatcherQueue.TryEnqueue(UpdateTrayIconBasedOnTheme);
27+
}
28+
29+
privatevoidUpdateTrayIconBasedOnTheme()
30+
{
31+
varcurrentTheme=Application.Current.RequestedTheme;
32+
Debug.WriteLine("Theme update requested, found theme: "+currentTheme);
33+
34+
switch(currentTheme)
35+
{
36+
caseApplicationTheme.Dark:
37+
TaskbarIcon.IconSource=(BitmapImage)Resources["IconDarkTheme"];
38+
break;
39+
caseApplicationTheme.Light:
40+
default:
41+
TaskbarIcon.IconSource=(BitmapImage)Resources["IconLightTheme"];
42+
break;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp