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

Commit

Permalink
Keep hacking away
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Dec 26, 2021
1 parent 2fa6135 commit 432206a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 98 deletions.
12 changes: 0 additions & 12 deletions DrasticMaui.Contracts/DrasticMaui.Contracts.csproj

This file was deleted.

16 changes: 0 additions & 16 deletions DrasticMaui.Contracts/ITrayService.cs

This file was deleted.

25 changes: 0 additions & 25 deletions DrasticMaui.Mac/DrasticMaui.Mac.csproj

This file was deleted.

22 changes: 0 additions & 22 deletions DrasticMaui.Mac/WindowCoordinator.cs

This file was deleted.

2 changes: 1 addition & 1 deletion DrasticMaui.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void App_HandlerChanged(object? sender, EventArgs e)
{
this.tray = new TrayService("DrasticMaui", stream, handler);
this.tray.SetupPage(new TraySample());
this.tray.SetupTrayIcon();
this.Dispatcher.Dispatch(this.tray.SetupTrayIcon);
}
}

Expand Down
14 changes: 1 addition & 13 deletions DrasticMaui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ VisualStudioVersion = 17.1.32023.32
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrasticMaui.Sample", "DrasticMaui.Sample\DrasticMaui.Sample.csproj", "{BD39811E-11BA-47FA-9F6A-A322AAAE1057}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrasticMaui", "DrasticMaui\DrasticMaui.csproj", "{ABBB7C06-7C93-4091-81FB-FAB580FBE76D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrasticMaui.Mac", "DrasticMaui.Mac\DrasticMaui.Mac.csproj", "{E1076FC6-242D-437D-9F41-E0501C0335F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrasticMaui.Contracts", "DrasticMaui.Contracts\DrasticMaui.Contracts.csproj", "{983E759D-4003-462B-9024-553139F49C65}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrasticMaui", "DrasticMaui\DrasticMaui.csproj", "{ABBB7C06-7C93-4091-81FB-FAB580FBE76D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -26,14 +22,6 @@ Global
{ABBB7C06-7C93-4091-81FB-FAB580FBE76D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ABBB7C06-7C93-4091-81FB-FAB580FBE76D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ABBB7C06-7C93-4091-81FB-FAB580FBE76D}.Release|Any CPU.Build.0 = Release|Any CPU
{E1076FC6-242D-437D-9F41-E0501C0335F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1076FC6-242D-437D-9F41-E0501C0335F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1076FC6-242D-437D-9F41-E0501C0335F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1076FC6-242D-437D-9F41-E0501C0335F0}.Release|Any CPU.Build.0 = Release|Any CPU
{983E759D-4003-462B-9024-553139F49C65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{983E759D-4003-462B-9024-553139F49C65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{983E759D-4003-462B-9024-553139F49C65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{983E759D-4003-462B-9024-553139F49C65}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 0 additions & 4 deletions DrasticMaui/DrasticMaui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
<ItemGroup>
<Folder Include="Tray\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DrasticMaui.Contracts\DrasticMaui.Contracts.csproj" />
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
Expand Down
21 changes: 16 additions & 5 deletions DrasticMaui/Tray/TrayService.MacCatalyst.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// <copyright file="TrayService.MacCatalyst.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using CoreFoundation;
using Foundation;
Expand All @@ -18,6 +18,8 @@ public partial class TrayService : NSObject
private NSObject? statusBarButton;
private NSObject? statusBarImage;
private NSObject? popoverObj;
private NSObject? nsViewControllerObj;
private NSObject? nsViewController;

public Action? ClickHandler { get; set; }

Expand All @@ -29,12 +31,18 @@ public void SetupTrayIcon()
return;
}

this.popoverObj = Runtime.GetNSObject(Class.GetHandle("NSPopover"));
this.popoverObj = Runtime.GetNSObject(IntPtr_objc_msgSend(ObjCRuntime.Class.GetHandle("NSPopover"), Selector.GetHandle("alloc")));
if (this.popoverObj is null)
{
return;
}

this.nsViewControllerObj = Runtime.GetNSObject(IntPtr_objc_msgSend(ObjCRuntime.Class.GetHandle("NSViewController"), Selector.GetHandle("alloc")));
if (this.nsViewControllerObj is null)
{
return;
}

this.systemStatusBarObj = this.statusBarObj.PerformSelector(new Selector("systemStatusBar"));
this.statusBarItem = Runtime.GetNSObject(IntPtr_objc_msgSend_nfloat(this.systemStatusBarObj.Handle, Selector.GetHandle("statusItemWithLength:"), -1));
if (this.statusBarItem is null)
Expand All @@ -55,10 +63,13 @@ public void SetupTrayIcon()
return;
}

var imgPath = System.IO.Path.Combine(NSBundle.MainBundle.BundlePath, "Contents", "Resources", "MacCatalyst", "trayicon.png");
var imageFileStr = CFString.CreateNative(imgPath);
var nsImagePtr = IntPtr_objc_msgSend_IntPtr(this.statusBarImage.Handle, Selector.GetHandle("initWithContentsOfFile:"), imageFileStr);
var imageStream = Foundation.NSData.FromStream(this.iconStream);
if (imageStream is null)
{
return;
}

var nsImagePtr = IntPtr_objc_msgSend_IntPtr(this.statusBarImage.Handle, Selector.GetHandle("initWithData:"), imageStream.Handle);
void_objc_msgSend_IntPtr(this.statusBarButton.Handle, Selector.GetHandle("setImage:"), this.statusBarImage.Handle);
void_objc_msgSend_bool(nsImagePtr, Selector.GetHandle("setTemplate:"), true);

Expand Down

0 comments on commit 432206a

Please sign in to comment.