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

Commit

Permalink
Look at tray stuff more
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Dec 31, 2021
1 parent 04d2d68 commit aa05ec0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
16 changes: 8 additions & 8 deletions DrasticMaui.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public App()

private void App_HandlerChanged(object? sender, EventArgs e)
{
//var handler = this.Handler.MauiContext;
//var stream = MauiProgram.GetResourceFileContent("Icon.favicon.ico");
//if (stream is not null && handler is not null)
//{
// this.tray = new TrayService("DrasticMaui", stream, handler);
// this.tray.SetupPage(new TraySample());
// this.Dispatcher.Dispatch(this.tray.SetupTrayIcon);
//}
var handler = this.Handler.MauiContext;
var stream = MauiProgram.GetResourceFileContent("Icon.favicon.ico");
if (stream is not null && handler is not null)
{
this.tray = new TrayService("DrasticMaui", stream, handler);
this.tray.SetupPage(new TraySample());
this.Dispatcher.Dispatch(this.tray.SetupTrayIcon);
}
}

/// <inheritdoc/>
Expand Down
47 changes: 40 additions & 7 deletions DrasticMaui/Tray/TrayService.MacCatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using AppKit;
using CoreFoundation;
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Platform;
using ObjCRuntime;
using UIKit;

namespace DrasticMaui.Tray
{
Expand Down Expand Up @@ -99,21 +102,48 @@ void HandleClick(NSObject senderStatusBarButton)

private void ToggleWindow()
{
if (this.trayWindow is null)
if (this.context is null)
{
return;
}

if (this.trayWindow.IsVisible)
if (this.trayWindow?.Page is null)
{
this.trayWindow.IsVisible = false;
Microsoft.Maui.Controls.Application.Current?.CloseWindow(this.trayWindow);
return;
}
else

if (this.popoverObj is null)
{
this.trayWindow.IsVisible = true;
Microsoft.Maui.Controls.Application.Current?.OpenWindow(this.trayWindow);
return;
}

if (this.statusBarButton is null)
{
return;
}

if (this.nsViewControllerObj is null)
{
return;
}

var view = new UIView();
var testing = IntPtr_objc_msgSend(this.nsViewControllerObj.Handle, Selector.GetHandle("view"));
var viewHandle = Runtime.GetNSObject(IntPtr_objc_msgSend(this.nsViewControllerObj.Handle, Selector.GetHandle("view")));
if (viewHandle is null)
{
return;
}

var bounds = Runtime.GetNSObject(IntPtr_objc_msgSend(this.statusBarButton.Handle, Selector.GetHandle("bounds")));
if (bounds is null)
{
return;
}

var rect = this.popoverObj.GetMethodForSelector(new Selector("showRelativeToRect:ofView:preferredEdge:"));

//var test = IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(this.popoverObj.Handle, Selector.GetHandle("showRelativeToRect:ofView:preferredEdge:"), bounds.Handle, this.statusBarButton.Handle, 1);
}

public void SetupPage(Microsoft.Maui.Controls.Page page)
Expand All @@ -127,6 +157,9 @@ public void SetupPage(Microsoft.Maui.Controls.Page page)
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1);

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2, nfloat arg3);

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector);

Expand Down

0 comments on commit aa05ec0

Please sign in to comment.