Skip to content

Commit

Permalink
system tray icon is back
Browse files Browse the repository at this point in the history
  • Loading branch information
davidortinau committed Oct 30, 2021
1 parent 4558aa5 commit b5dba8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/WeatherTwentyOne/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public static MauiApp CreateMauiApp()
});
builder.ConfigureLifecycleEvents(lifecycle => {
#if WINDOWS
lifecycle
.AddWindows(windows => windows.OnLaunched((app, args) => {
MauiWinUIApplication.Current.MainWindow.SetIcon("Platforms/Windows/trayicon.ico");
}));
lifecycle
.AddWindows(windows => windows.OnLaunched((app, args) => {
var winuiApp = (Microsoft.UI.Xaml.Window)MauiWinUIApplication.Current.Application.Windows[0].Handler!.NativeView!;
winuiApp.SetIcon("Platforms/Windows/trayicon.ico");
}));
#endif
});
});

var services = builder.Services;
#if WINDOWS
Expand Down
6 changes: 5 additions & 1 deletion src/WeatherTwentyOne/Platforms/Windows/TrayService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Hardcodet.Wpf.TaskbarNotification.Interop;
using Microsoft.Maui;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -19,7 +21,9 @@ public void Initialize()
tray = new WindowsTrayIcon("Platforms/Windows/trayicon.ico");
tray.LeftClick = () =>
{
Microsoft.Maui.MauiWinUIApplication.Current.MainWindow.BringToFront();
var winuiApp = (Window)MauiWinUIApplication.Current.Application.Windows[0].Handler!.NativeView!;
winuiApp.BringToFront();
//Microsoft.Maui.MauiWinUIApplication.Current.Application.Windows[0].BringToFront();
ClickHandler?.Invoke();
};
}
Expand Down
1 change: 0 additions & 1 deletion src/WeatherTwentyOne/Views/WidgetsPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
</Border.StrokeShape>
<Grid
Margin="20"
BackgroundColor="Red"
ColumnDefinitions="*"
RowDefinitions="*">
<Grid.GestureRecognizers>
Expand Down
10 changes: 10 additions & 0 deletions src/WeatherTwentyOne/WeatherTwentyOne.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
</ItemGroup>

<ItemGroup>
<None Remove="Platforms\Windows\trayicon.ico" />
</ItemGroup>

<ItemGroup>
<Content Include="Platforms\Windows\trayicon.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Expand Down

0 comments on commit b5dba8c

Please sign in to comment.