Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Initial Tray
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Dec 25, 2021
1 parent ea8d0d3 commit e2620b1
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 29 deletions.
10 changes: 10 additions & 0 deletions DrasticMaui.Sample/DrasticMaui.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<None Remove="Icon\dotnet_bot.png" />
<None Remove="Icon\favicon.ico" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Icon\dotnet_bot.png" />
<EmbeddedResource Include="Icon\favicon.ico" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DrasticMaui\DrasticMaui.csproj" />
</ItemGroup>
Expand Down
Binary file added DrasticMaui.Sample/Icon/dotnet_bot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DrasticMaui.Sample/Icon/favicon.ico
Binary file not shown.
22 changes: 22 additions & 0 deletions DrasticMaui.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

using DrasticMaui.Tray;
using System.Reflection;

namespace DrasticMaui.Sample;

/// <summary>
Expand All @@ -15,6 +18,13 @@ public static class MauiProgram
/// <returns>MauiApp.</returns>
public static MauiApp CreateMauiApp()
{
var stream = GetResourceFileContent("Icon.favicon.ico");
if (stream is not null)
{
var tray = new TrayService("DrasticMaui", stream);
tray.SetupTrayIcon();
}

var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
Expand All @@ -25,4 +35,16 @@ public static MauiApp CreateMauiApp()

return builder.Build();
}

private static Stream? GetResourceFileContent(string fileName)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "DrasticMaui.Sample." + fileName;
if (assembly is null)
{
return null;
}

return assembly.GetManifestResourceStream(resourceName);
}
}
4 changes: 4 additions & 0 deletions DrasticMaui/DrasticMaui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@
<ItemGroup>
<ProjectReference Include="..\DrasticMaui.Contracts\DrasticMaui.Contracts.csproj" />
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion DrasticMaui/DrasticMauiWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public IReadOnlyList<IVisualTreeElement> GetVisualChildren()
}

/// <inheritdoc/>
public IVisualTreeElement? GetVisualParent() => Application.Current;
public IVisualTreeElement? GetVisualParent() => Microsoft.Maui.Controls.Application.Current;
}
}
2 changes: 1 addition & 1 deletion DrasticMaui/Overlays/BaseOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public virtual bool Deinitialize()
}

/// <inheritdoc/>
public virtual void Draw(ICanvas canvas, RectangleF dirtyRect)
public virtual void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectangleF dirtyRect)
{
}

Expand Down
8 changes: 4 additions & 4 deletions DrasticMaui/Overlays/DragAndDropOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class DragAndDropOverlay : BaseOverlay
/// <param name="window"><see cref="IWindow"/>.</param>
/// <param name="dragOverColor">Optional color to show when draging an item over the window.</param>
/// <param name="dragOverOverlayElement">Optional window element to show when draging an element over the window.</param>
public DragAndDropOverlay(IWindow window, Color? dragOverColor = null, IWindowOverlayElement? dragOverOverlayElement = null)
public DragAndDropOverlay(IWindow window, Microsoft.Maui.Graphics.Color? dragOverColor = null, IWindowOverlayElement? dragOverOverlayElement = null)
: base(window)
{
this.dropElement = new DropElementOverlay();
Expand Down Expand Up @@ -63,13 +63,13 @@ private class DropElementOverlay : IWindowOverlayElement

public bool IsDragging { get; set; }

public Color Color { get; set; } = Colors.Transparent;
public Microsoft.Maui.Graphics.Color Color { get; set; } = Microsoft.Maui.Graphics.Colors.Transparent;

// We are not going to use Contains for this.
// We're gonna set if it's invoked externally.
public bool Contains(Point point) => false;
public bool Contains(Microsoft.Maui.Graphics.Point point) => false;

public void Draw(ICanvas canvas, RectangleF dirtyRect)
public void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectangleF dirtyRect)
{
if (!this.IsDragging)
{
Expand Down
2 changes: 1 addition & 1 deletion DrasticMaui/Overlays/PageOverlay.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void Panel_PointerMoved(object sender, Microsoft.UI.Xaml.Input.PointerRo
}

var nativeElements = this.HitTestElements.Select(n => n.GetNative(true));
this.element.IsHitTestVisible = nativeElements.Any(n => n.GetBoundingBox().Contains(new Point(pointerPoint.Position.X, pointerPoint.Position.Y)));
this.element.IsHitTestVisible = nativeElements.Any(n => n.GetBoundingBox().Contains(new Microsoft.Maui.Graphics.Point(pointerPoint.Position.X, pointerPoint.Position.Y)));
}
}
}
12 changes: 6 additions & 6 deletions DrasticMaui/Tools/PlatformExtensions.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public static class PlatformExtensions
return view.Handler?.NativeView as FrameworkElement;
}

internal static Rectangle GetBoundingBox(this IView view)
internal static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this IView view)
=> view.GetNative(true).GetBoundingBox();

internal static Rectangle GetBoundingBox(this FrameworkElement? nativeView)
internal static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this FrameworkElement? nativeView)
{
if (nativeView == null)
return new Rectangle();
return new Microsoft.Maui.Graphics.Rectangle();

var rootView = nativeView.XamlRoot.Content;
if (nativeView == rootView)
{
if (rootView is not FrameworkElement el)
return new Rectangle();
return new Microsoft.Maui.Graphics.Rectangle();

return new Rectangle(0, 0, el.ActualWidth, el.ActualHeight);
return new Microsoft.Maui.Graphics.Rectangle(0, 0, el.ActualWidth, el.ActualHeight);
}

var topLeft = nativeView.TransformToVisual(rootView).TransformPoint(new WinPoint());
Expand All @@ -55,7 +55,7 @@ internal static Rectangle GetBoundingBox(this FrameworkElement? nativeView)
var x2 = new[] { topLeft.X, topRight.X, bottomLeft.X, bottomRight.X }.Max();
var y1 = new[] { topLeft.Y, topRight.Y, bottomLeft.Y, bottomRight.Y }.Min();
var y2 = new[] { topLeft.Y, topRight.Y, bottomLeft.Y, bottomRight.Y }.Max();
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
return new Microsoft.Maui.Graphics.Rectangle(x1, y1, x2 - x1, y2 - y1);
}
}
}
4 changes: 0 additions & 4 deletions DrasticMaui/Tray/TrayService.MacCatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace DrasticMaui.Tray
{
public partial class TrayService
{
public TrayService()
{
}

public void SetupTrayIcon()
{
}
Expand Down
29 changes: 22 additions & 7 deletions DrasticMaui/Tray/TrayService.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@
// </copyright>

using System;
using System.Windows.Forms;

namespace DrasticMaui.Tray
{
public partial class TrayService
{
public void SetupTrayIcon()
{
public partial class TrayService
{
private NotifyIcon? notifyIcon;

public void SetupTrayIcon()
{
this.notifyIcon = new NotifyIcon();
this.notifyIcon.Icon = new Icon(this.iconStream);
this.notifyIcon.Text = this.iconName;
this.notifyIcon.Visible = true;
this.notifyIcon.MouseClick += this.NotifyIcon_MouseClick;
}

}
}
}
private void NotifyIcon_MouseClick(object? sender, MouseEventArgs e)
{
if (e.Button is MouseButtons.Left)
{

}
}
}
}
19 changes: 14 additions & 5 deletions DrasticMaui/Tray/TrayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
// </copyright>

using System;

namespace DrasticMaui.Tray
{
public partial class TrayService
{
public partial class TrayService
{
private Stream iconStream;
private string iconName;

public TrayService(string name, Stream stream)
{
this.iconName = name;
this.iconStream = stream;
}

#if ANDROID || IOS
public void SetupTrayIcon()
{

}
#endif
}
}

}
}

0 comments on commit e2620b1

Please sign in to comment.