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

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jan 2, 2022
1 parent fce8325 commit 85b1f6b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 69 deletions.
1 change: 0 additions & 1 deletion DrasticMaui.Sample/TraySample.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ private void OnReset(object sender, EventArgs e)
{
if (this.GetParentWindow() is DrasticTrayWindow win)
{
win.Setup();
}
}

Expand Down
53 changes: 7 additions & 46 deletions DrasticMaui/DrasticTrayWindow.MacCatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public partial class DrasticTrayWindow
private bool isActivated;
private DrasticTrayUIViewController? drasticViewController;

/// <summary>
/// Gets a value indicating whether the tray window should be visible.
/// </summary>
public bool IsVisible => true;
/// <inheritdoc/>
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
this.SetupWindow();
this.SetupTrayIcon();
}

private async void SetupWindow()
{
Expand All @@ -52,48 +55,6 @@ private async void SetupWindow()
}

this.uiWindow.RootViewController = this.drasticViewController = new DrasticTrayUIViewController(this.uiWindow, this.uiWindow.RootViewController, this.icon, this.options);

}

protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
//this.SetupWindow();
//this.SetupTrayIcon();
}

public void Setup()
{
this.SetupWindow();
this.SetupTrayIcon();
}

private void TestUIWindowToTray()
{
//if (this.statusBarButton is null)
//{
// return;
//}

//var nsWindow = window.GetNSWindowFromUIWindow();
//if (nsWindow is null)
//{
// return;
//}

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

//var cgRectWindowFrame = Runtime.GetNSObject(PlatformExtensions.IntPtr_objc_msgSend(buttonWindow.Handle, Selector.GetHandle("frame")));
//if (cgRectWindowFrame is null)
//{
// return;
//}

//PlatformExtensions.void_objc_msgSend_IntPtr_bool(nsWindow.Handle, Selector.GetHandle("setFrame:display:"), cgRectWindowFrame.Handle, false);
}

private void ShowWindow()
Expand Down
9 changes: 0 additions & 9 deletions DrasticMaui/DrasticTrayWindow.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public partial class DrasticTrayWindow
private Microsoft.UI.Windowing.AppWindow? appWindow;
private bool appLaunched;

/// <summary>
/// Gets a value indicating whether the tray window should be visible.
/// </summary>
public bool IsVisible => this.appWindow is not null ? this.appWindow.IsVisible : true;

///// <inheritdoc/>
protected override void OnCreated()
{
Expand Down Expand Up @@ -71,10 +66,6 @@ private void Window_VisibilityChanged(object sender, Microsoft.UI.Xaml.WindowVis
}
}

public void Setup()
{
}

private void ShowWindow()
{
if (this.appWindow is null)
Expand Down
16 changes: 7 additions & 9 deletions DrasticMaui/DrasticTrayWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public DrasticTrayWindow(DrasticTrayIcon icon, DrasticTrayWindowOptions? options
this.options = options ?? new DrasticTrayWindowOptions();
}

/// <summary>
/// Gets a value indicating whether the tray window should be visible.
/// </summary>
public bool IsVisible { get; private set; }

private void SetupTrayIcon()
{
if (this.icon is null)
Expand All @@ -50,15 +55,12 @@ private void Icon_LeftClicked(object? sender, EventArgs e)
{
this.ShowWindow();
}

this.IsVisible = !this.IsVisible;
}

#if !WINDOWS && !MACCATALYST

/// <summary>
/// Gets a value indicating whether the tray window should be visible.
/// </summary>
public bool IsVisible => true;

private void SetupWindow()
{
}
Expand All @@ -70,10 +72,6 @@ private void ShowWindow()
private void HideWindow()
{
}

public void Setup()
{
}
#endif
}
}
1 change: 1 addition & 0 deletions DrasticMaui/Tray/DrasticTrayIcon.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private void NotifyIcon_MouseClick(object? sender, MouseEventArgs e)

private void NativeElementDispose()
{
this.notifyIcon?.Dispose();
this.icon?.Dispose();
}

Expand Down
31 changes: 29 additions & 2 deletions DrasticMaui/Tray/DrasticTrayMenuItem.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
using System;
// <copyright file="DrasticTrayMenuItem.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DrasticMaui
{
/// <summary>
/// Drastic Tray Menu Item.
/// </summary>
public class DrasticTrayMenuItem
{
public DrasticTrayMenuItem (string text, Stream? icon = null)
/// <summary>
/// Initializes a new instance of the <see cref="DrasticTrayMenuItem"/> class.
/// </summary>
/// <param name="text">Menu Text.</param>
/// <param name="icon">Icon.</param>
/// <param name="action">Action to perform when clicked.</param>
public DrasticTrayMenuItem (string text, Stream? icon = null, Task<Action>? action = null)
{
this.Text = text;
this.Icon = icon;
this.Action = action;
}

/// <summary>
/// Gets the text for the menu item.
/// </summary>
public string Text { get; }

/// <summary>
/// Gets the icon for the menu item.
/// Optional.
/// </summary>
public Stream? Icon { get; }

/// <summary>
/// Gets the action to be performed when the item is clicked.
/// Optional.
/// </summary>
public Task<Action>? Action { get; }
}
}
24 changes: 22 additions & 2 deletions DrasticMaui/Tray/DrasticTrayUIViewController.MacCatalyst.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
// <copyright file="DrasticTrayUIViewController.MacCatalyst.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

using System;
using CoreGraphics;
using DrasticMaui.Options;
using DrasticMaui.Tools;
Expand All @@ -7,6 +11,11 @@

namespace DrasticMaui
{
/// <summary>
/// Drastic Tray UI View Controller.
/// Holds an existing MAUI UI View Controller and turns
/// it into a modal popover.
/// </summary>
public class DrasticTrayUIViewController : UIViewController
{
private UIViewController contentController;
Expand All @@ -15,6 +24,13 @@ public class DrasticTrayUIViewController : UIViewController
private DrasticTrayWindowOptions options;
private DrasticTrayIcon trayIcon;

/// <summary>
/// Initializes a new instance of the <see cref="DrasticTrayUIViewController"/> class.
/// </summary>
/// <param name="window">Containing UI Window.</param>
/// <param name="contentController">Embedded UI View Controller.</param>
/// <param name="trayIcon">Tray Icon.</param>
/// <param name="options">Options.</param>
public DrasticTrayUIViewController(
UIWindow window,
UIViewController contentController,
Expand All @@ -29,6 +45,9 @@ public DrasticTrayUIViewController(
this.SetupWindow();
}

/// <summary>
/// Toggle Visibility of the window.
/// </summary>
public async void ToggleVisibility()
{
if (this.contentController?.View is null)
Expand All @@ -49,7 +68,7 @@ public async void ToggleVisibility()
{
viewController.DismissViewController(true, null);
}
else
else
{
viewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
viewController.PopoverPresentationController.SourceView = this.View;
Expand All @@ -59,6 +78,7 @@ public async void ToggleVisibility()
}
}

/// <inheritdoc/>
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
Expand Down

0 comments on commit 85b1f6b

Please sign in to comment.