Skip to content

Commit

Permalink
feat: Added MAUI package.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jul 8, 2023
1 parent d851dfa commit 7edbe67
Show file tree
Hide file tree
Showing 24 changed files with 276 additions and 82 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ jobs:
/target:libs\H_NotifyIcon_Uno_WinUI
/target:libs\H_NotifyIcon_WinUI
/target:libs\H_NotifyIcon_Wpf
/target:libs\H_NotifyIcon_Maui
secrets:
nuget-key: ${{ secrets.NUGET_KEY }}
38 changes: 38 additions & 0 deletions H.NotifyIcon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "H.GeneratedIcons.System.Dra
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "H.GeneratedIcons.SkiaSharp", "src\libs\H.GeneratedIcons.SkiaSharp\H.GeneratedIcons.SkiaSharp.csproj", "{EECF393D-0F55-4BFE-AEA8-7FD90383C05D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "H.NotifyIcon.Maui", "src\libs\H.NotifyIcon.Maui\H.NotifyIcon.Maui.csproj", "{84E993AA-5343-4502-9612-B9A416AF243F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "H.NotifyIcon.Apps.Maui", "src\apps\H.NotifyIcon.Apps.Maui\H.NotifyIcon.Apps.Maui.csproj", "{6C5EA367-5663-420E-B10C-8E5543EBF8DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -329,6 +333,38 @@ Global
{EECF393D-0F55-4BFE-AEA8-7FD90383C05D}.Release|x64.Build.0 = Release|Any CPU
{EECF393D-0F55-4BFE-AEA8-7FD90383C05D}.Release|x86.ActiveCfg = Release|Any CPU
{EECF393D-0F55-4BFE-AEA8-7FD90383C05D}.Release|x86.Build.0 = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|arm64.ActiveCfg = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|arm64.Build.0 = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|x64.ActiveCfg = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|x64.Build.0 = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|x86.ActiveCfg = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Debug|x86.Build.0 = Debug|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|Any CPU.Build.0 = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|arm64.ActiveCfg = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|arm64.Build.0 = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|x64.ActiveCfg = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|x64.Build.0 = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|x86.ActiveCfg = Release|Any CPU
{84E993AA-5343-4502-9612-B9A416AF243F}.Release|x86.Build.0 = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|arm64.ActiveCfg = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|arm64.Build.0 = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|x64.Build.0 = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Debug|x86.Build.0 = Debug|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|Any CPU.Build.0 = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|arm64.ActiveCfg = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|arm64.Build.0 = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|x64.ActiveCfg = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|x64.Build.0 = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|x86.ActiveCfg = Release|Any CPU
{6C5EA367-5663-420E-B10C-8E5543EBF8DD}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -350,6 +386,8 @@ Global
{A04E983D-5631-4C68-B34A-796970E060C0} = {52FA15AF-CAE7-4822-9975-F5E812EDEF33}
{A4A97F4E-71C1-42FA-84DC-7D4A41079A13} = {FCF55611-6E25-4F1E-8E88-705896171E71}
{EECF393D-0F55-4BFE-AEA8-7FD90383C05D} = {FCF55611-6E25-4F1E-8E88-705896171E71}
{84E993AA-5343-4502-9612-B9A416AF243F} = {FCF55611-6E25-4F1E-8E88-705896171E71}
{6C5EA367-5663-420E-B10C-8E5543EBF8DD} = {52FA15AF-CAE7-4822-9975-F5E812EDEF33}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C139BD97-A4F7-411B-99B1-824CE1ABA403}
Expand Down
9 changes: 9 additions & 0 deletions src/apps/H.NotifyIcon.Apps.Maui/H.NotifyIcon.Apps.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);MT0182</NoWarn>

<!-- Display name -->
<ApplicationTitle>H.NotifyIcon.Apps.Maui</ApplicationTitle>
Expand All @@ -30,6 +31,13 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<!-- https://github.com/xamarin/xamarin-macios/issues/15897 -->
<Target Name="_SetPublishFolderTypeNoneOnDocFileItems" BeforeTargets="_ComputePublishLocation">
<ItemGroup>
<ResolvedFileToPublish Update="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.Extension)' == '.xml' And '%(ResolvedFileToPublish.PublishFolderType)' == ''" PublishFolderType="None" />
</ItemGroup>
</Target>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand All @@ -54,6 +62,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\H.NotifyIcon.Maui\H.NotifyIcon.Maui.csproj" />
<ProjectReference Include="..\..\libs\H.NotifyIcon\H.NotifyIcon.csproj" />
<ProjectReference Include="..\..\libs\H.GeneratedIcons.SkiaSharp\H.GeneratedIcons.SkiaSharp.csproj" />
</ItemGroup>
Expand Down
16 changes: 11 additions & 5 deletions src/apps/H.NotifyIcon.Apps.Maui/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="H.NotifyIcon.Apps.Maui.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:tb="https://notifyicon.com/"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:skia="clr-namespace:SkiaSharp.Views.Maui.Controls;assembly=SkiaSharp.Views.Maui.Controls"
x:Class="H.NotifyIcon.Apps.Maui.MainPage"
>

<ScrollView>
<skia:SKCanvasView x:Name="CanvasView" />
</ScrollView>
<Grid>
<tb:TaskbarIcon
IconSource="red.ico"
x:Name="TrayIcon"
/>
</Grid>
<!-- <ScrollView> -->
<!-- <skia:SKCanvasView x:Name="CanvasView" /> -->
<!-- </ScrollView> -->

</ContentPage>
75 changes: 36 additions & 39 deletions src/apps/H.NotifyIcon.Apps.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
using SkiaSharp;
using SkiaSharp.Views.Maui;

namespace H.NotifyIcon.Apps.Maui;
namespace H.NotifyIcon.Apps.Maui;

public partial class MainPage
{
public MainPage()
{
InitializeComponent();

CanvasView.PaintSurface += CanvasViewOnPaintSurface;
//CanvasView.PaintSurface += CanvasViewOnPaintSurface;
}

private static void CanvasViewOnPaintSurface(object? sender, SKPaintSurfaceEventArgs args)
{
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;

canvas.Clear();

using var backgroundBrush = new SKPaint();
backgroundBrush.Style = SKPaintStyle.Stroke;
backgroundBrush.Color = SKColors.Black;
backgroundBrush.StrokeWidth = 24;
backgroundBrush.StrokeCap = SKStrokeCap.Round;

using var foregroundBrush = new SKPaint();
foregroundBrush.Style = SKPaintStyle.Stroke;
foregroundBrush.Color = SKColors.White;
foregroundBrush.StrokeWidth = 1;
foregroundBrush.StrokeCap = SKStrokeCap.Round;
foregroundBrush.TextSize = 48;

canvas.DrawBitmap(SkiaSharpIconGenerator.Generate(
backgroundBrush: backgroundBrush,
foregroundBrush: foregroundBrush,
text: "H",
font: new SKFont(SKTypeface.Default, size: 48F),
pen: new SKPaint
{
Style = SKPaintStyle.Stroke,
StrokeWidth = 5,
Color = SKColors.Aqua,
}), info.Rect);
}
//
// private static void CanvasViewOnPaintSurface(object? sender, SKPaintSurfaceEventArgs args)
// {
// SKImageInfo info = args.Info;
// SKSurface surface = args.Surface;
// SKCanvas canvas = surface.Canvas;
//
// canvas.Clear();
//
// using var backgroundBrush = new SKPaint();
// backgroundBrush.Style = SKPaintStyle.Stroke;
// backgroundBrush.Color = SKColors.Black;
// backgroundBrush.StrokeWidth = 24;
// backgroundBrush.StrokeCap = SKStrokeCap.Round;
//
// using var foregroundBrush = new SKPaint();
// foregroundBrush.Style = SKPaintStyle.Stroke;
// foregroundBrush.Color = SKColors.White;
// foregroundBrush.StrokeWidth = 1;
// foregroundBrush.StrokeCap = SKStrokeCap.Round;
// foregroundBrush.TextSize = 48;
//
// canvas.DrawBitmap(SkiaSharpIconGenerator.Generate(
// backgroundBrush: backgroundBrush,
// foregroundBrush: foregroundBrush,
// text: "H",
// font: new SKFont(SKTypeface.Default, size: 48F),
// pen: new SKPaint
// {
// Style = SKPaintStyle.Stroke,
// StrokeWidth = 5,
// Color = SKColors.Aqua,
// }), info.Rect);
// }
}

1 change: 1 addition & 0 deletions src/apps/H.NotifyIcon.Apps.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static MauiApp CreateMauiApp()
builder
.UseMauiApp<App>()
.UseSkiaSharp()
.UseNotifyIcon()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand Down
18 changes: 7 additions & 11 deletions src/apps/H.NotifyIcon.Apps.Maui/Platforms/MacCatalyst/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using ObjCRuntime;
using H.NotifyIcon.Apps.Maui;
using UIKit;

namespace H.NotifyIcon.Apps.Maui;

public class Program
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
Thread.Sleep(TimeSpan.FromSeconds(5));
}
#endif

UIApplication.Main(args, null, typeof(AppDelegate));
18 changes: 7 additions & 11 deletions src/apps/H.NotifyIcon.Apps.Maui/Platforms/iOS/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using ObjCRuntime;
using H.NotifyIcon.Apps.Maui;
using UIKit;

namespace H.NotifyIcon.Apps.Maui;

public class Program
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
Thread.Sleep(TimeSpan.FromSeconds(5));
}
#endif

UIApplication.Main(args, null, typeof(AppDelegate));
Binary file not shown.
4 changes: 4 additions & 0 deletions src/libs/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
<Compile Remove="$(MSBuildThisFileDirectory)**\*.WinRT.*" />
<Compile Remove="$(MSBuildThisFileDirectory)**\WinRT\*.*" />
</ItemGroup>
<ItemGroup Condition="!$(DefineConstants.Contains('HAS_MAUI'))">
<Compile Remove="$(MSBuildThisFileDirectory)**\*.Maui.*" />
<Compile Remove="$(MSBuildThisFileDirectory)**\Maui\*.*" />
</ItemGroup>

</Project>
48 changes: 48 additions & 0 deletions src/libs/H.NotifyIcon.Maui/H.NotifyIcon.Maui.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-windows10.0.19041.0</TargetFrameworks>
<UseMaui>true</UseMaui>
<DefineConstants>$(DefineConstants);HAS_PLATFORM_CODE;HAS_MAUI</DefineConstants>
<NoWarn>$(NoWarn);CA1031;CS8002;CS0108;CA1501</NoWarn>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>

<PropertyGroup Label="NuGet">
<Description>This is an implementation of a NotifyIcon (aka system tray icon or taskbar icon) for the MAUI platform.
It does not just rely on the Windows Forms NotifyIcon component,
but is a purely independent control which leverages several features of the WinUI framework in order to display rich tooltips,
popups, context menus, and balloon messages. It can be used directly in code or embedded in any XAML file.
</Description>
<PackageTags>notifyicon;maui;tray</PackageTags>
</PropertyGroup>

<ItemGroup Label="AssemblyInfo">
<AssemblyAttribute Include="Microsoft.Maui.Controls.XmlnsPrefix">
<_Parameter1>https://notifyicon.com/</_Parameter1>
<_Parameter2>tb</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.Maui.Controls.XmlnsDefinition">
<_Parameter1>https://notifyicon.com/</_Parameter1>
<_Parameter2>H.NotifyIcon</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="DependencyPropertyGenerator">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="EventGenerator.Generator">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageVersion Remove="Microsoft.WindowsAppSDK" />
<PackageVersion Remove="Microsoft.Windows.SDK.BuildTools" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\H.NotifyIcon\H.NotifyIcon.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/libs/H.NotifyIcon.Maui/MauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace H.NotifyIcon;

/// <summary>
///
/// </summary>
[CLSCompliant(false)]
public static class MauiAppBuilderExtensions
{
/// <summary>
///
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static MauiAppBuilder UseNotifyIcon(this MauiAppBuilder builder)
{
return builder;
}
}
15 changes: 14 additions & 1 deletion src/libs/H.NotifyIcon.Shared/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using DependencyPropertyGenerator;
global using EventGenerator;
global using H.NotifyIcon.Core;
global using System.Runtime.Versioning;
#if HAS_AVALONIA
global using Avalonia;
global using Avalonia.Data;
Expand Down Expand Up @@ -42,7 +43,7 @@
#if HAS_UNO
global using WindowActivationState = Windows.UI.Core.CoreWindowActivationState;
#endif
#else
#elif HAS_UNO
global using Windows.UI.Core;
global using Windows.System;
global using Windows.UI;
Expand All @@ -57,6 +58,18 @@
global using Windows.Storage;
global using Windows.Foundation;
global using FontStyles = Windows.UI.Text.FontStyle;
#else
global using System.Windows.Input;
global using Microsoft.Maui;
global using Microsoft.Maui.Controls;
global using Microsoft.Maui.Media;
global using Microsoft.Maui.Graphics;
global using Microsoft.Maui.Primitives;
global using FontStyle = Microsoft.Maui.Controls.FontAttributes;
global using FontStyles = Microsoft.Maui.Controls.FontAttributes;
global using FontWeights = Microsoft.Maui.FontWeight;
global using FontFamily = System.String;
global using FrameworkElement = Microsoft.Maui.Controls.TemplatedView;
#endif
#if HAS_SYSTEM_DRAWING
global using Icon = System.Drawing.Icon;
Expand Down
1 change: 1 addition & 0 deletions src/libs/H.NotifyIcon.Shared/TaskbarIcon.IconSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Description = "Resolves an image source and updates the Icon property accordingly.", Category = CategoryName)]
public partial class TaskbarIcon
{
[SupportedOSPlatform("windows5.0")]
async partial void OnIconSourceChanged(ImageSource? oldValue, ImageSource? newValue)
{
if (newValue == null)
Expand Down
Loading

0 comments on commit 7edbe67

Please sign in to comment.