Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tray-icon support #6560

Merged
merged 109 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
3438ac1
initial implementation of tray icon.
Sep 8, 2021
0b9601d
tidy win32 tray menu impl.
Sep 8, 2021
2d2d8fa
add example win32 tray icon.
Sep 8, 2021
bc772cc
dont create multiple message queues for tray icons.
Sep 8, 2021
35dc6ce
remove unused code.
Sep 8, 2021
26e221e
Win32 trayicon, make menu close when item is clicked.
Sep 8, 2021
30f6145
implement visible changed and tooltip.
Sep 8, 2021
8b410e8
add a managed native menu exporter for win32 tray icon menus.
Sep 9, 2021
f65f08e
implement trayicon lifetime management.
Sep 9, 2021
e00a4f6
implement example tray icon in control catalog with binding.
Sep 9, 2021
5e87cff
CompiledBinding correctly locates IDataContextProvider as anchor. (im…
Sep 9, 2021
0c55449
restore removed code.
Sep 9, 2021
433973b
Merge branch 'master' into feature/tray-icon-support
Sep 9, 2021
5cf644b
Merge branch 'feature/tray-icon-support' of github.com:AvaloniaUI/Ava…
Sep 9, 2021
6ae5921
add initial implementation for osx tray icon support.
Sep 9, 2021
0e703c9
Add trayicon menu export support for osx.
Sep 9, 2021
f4031c6
more complex test menu for tray icons.
Sep 9, 2021
a8c435e
show checks in tray menu.
Sep 9, 2021
9c0c6f7
fix sub-menus win32 trayicons
Sep 9, 2021
59e66f7
add some documentation.
Sep 10, 2021
b34ec3c
Merge remote-tracking branch 'origin/master' into feature/tray-icon-s…
Sep 10, 2021
59f3ce0
remove unused property.
Sep 10, 2021
abf4242
support trayicon clicked on osx.
Sep 10, 2021
c80e7ba
Merge remote-tracking branch 'origin/master' into feature/tray-icon-s…
Sep 10, 2021
5d568d1
handle items being programatically removed.
Sep 10, 2021
4e350e6
demo tray icon constantly shown and hidden.
Sep 10, 2021
a3c8396
Tray icon osx, implement visibility toggle and lifetime management.
Sep 10, 2021
33f4bb6
fix unit tests.
Sep 10, 2021
7451e6b
Merge remote-tracking branch 'origin/master' into feature/tray-icon-s…
Sep 10, 2021
00b82a2
fix unit tests.
Sep 10, 2021
3342d41
fix ios stub.
Sep 12, 2021
3b273b4
Merge remote-tracking branch 'origin/master' into feature/tray-icon-s…
Sep 12, 2021
ae6a9a0
add a tray icon stub to x11 platform.
Sep 14, 2021
95f4ed1
add diagnostics for debugging window deactivated issue.
Sep 14, 2021
a189f52
testing stuff for now
jmacato Sep 17, 2021
6016c56
connection made
jmacato Sep 17, 2021
b216b1a
some progress....
jmacato Sep 17, 2021
a19b202
more updates
jmacato Sep 17, 2021
7656558
converting x11 icons to pixmap
jmacato Sep 17, 2021
e2dc0ea
sigh... icons still not working here
jmacato Sep 17, 2021
a582f0f
clean stuff up
jmacato Sep 17, 2021
25c364e
Merge branch 'master' into feature/tray-icon-dbus-sni-test
jmacato Sep 18, 2021
efb260f
test upload
jmacato Sep 18, 2021
d327145
more stuff
jmacato Sep 18, 2021
98d8b20
dont throw the underlying data in X11IconLoader.cs
jmacato Sep 18, 2021
a70997b
fix conversion
jmacato Sep 18, 2021
eae2f5a
reuse Data array from X11IconLoader.cs
jmacato Sep 18, 2021
060e2b6
simplifying stuff
jmacato Sep 18, 2021
f462481
Make title/tooltip work
jmacato Sep 18, 2021
0ae373f
remove unnecessary code
jmacato Sep 18, 2021
f3a9a3b
80% done
jmacato Sep 18, 2021
f6a4bd9
some fixes
jmacato Sep 18, 2021
f811655
some fixes
jmacato Sep 18, 2021
e2a68ec
Merge remote-tracking branch 'origin/master' into feature/tray-icon-s…
Sep 18, 2021
557e35e
generate instead of set on guid
jmacato Sep 18, 2021
602dcff
make native menu work
jmacato Sep 18, 2021
691c4b7
test change
jmacato Sep 18, 2021
b8a74ef
Merge branch 'feature/tray-icon-support' into feature/tray-icon-dbus-…
Sep 20, 2021
069a8d4
fix dbus menu icon loading courtesy of @danwalmsley
jmacato Sep 21, 2021
88965c0
Merge remote-tracking branch 'origin/feature/tray-icon-dbus-sni-test'…
jmacato Sep 21, 2021
ce73334
Make a separate DBus connections so that things doesnt mix up in one …
jmacato Sep 23, 2021
a06198d
make visibility work somewhat
jmacato Sep 23, 2021
a7f3fbe
more refactoring
jmacato Sep 23, 2021
19003c0
Use single connection + new guid per SNI object...
jmacato Sep 27, 2021
fa6a12c
finally silence that good ol appmenu error in linux
jmacato Sep 27, 2021
1a97c6c
Revert "Use single connection + new guid per SNI object..."
jmacato Sep 29, 2021
f570e35
Clean up a little bit
jmacato Sep 29, 2021
fbb2206
Merge remote-tracking branch 'origin/feature/tray-icon-dbus-sni-test'…
Sep 29, 2021
d316d08
Merge branch 'master' into feature/tray-icon-support
jmacato Sep 30, 2021
912d3f4
Merge remote-tracking branch 'origin/master' into feature/tray-icon-s…
Oct 4, 2021
22b2f99
Merge branch 'feature/tray-icon-support' of github.com:AvaloniaUI/Ava…
Oct 4, 2021
69693d4
fix breaking change.
Oct 4, 2021
f86bb8c
update documentation.
Oct 4, 2021
a93d299
acceptable interface change.
Oct 4, 2021
d6dd823
rename property.
Oct 4, 2021
40fef49
fix comment.
Oct 4, 2021
34b96f4
make the trayicon menu property an explicit member of trayicon.
Oct 4, 2021
786375a
handle platforms that return null for the trayiconimpl.
Oct 4, 2021
77b9a4b
Merge branch 'master' into feature/tray-icon-support
Oct 5, 2021
f3436f1
remove debug code
jmacato Oct 5, 2021
7a54702
handle if we're unable to get a dbus connection
jmacato Oct 5, 2021
f97252c
fix warning.
Oct 5, 2021
65beb89
fix compiler error.
Oct 5, 2021
6978eab
fix some warnings.
Oct 5, 2021
285e483
remove unnecessary async Tasks and replace them with non-async Task.F…
jmacato Oct 5, 2021
b5b614b
fix warnings.
Oct 5, 2021
10a748a
make new win32 types internal.
Oct 5, 2021
52e1885
win32 - fix activate method, now same as wpf.
Oct 6, 2021
d13fc38
win32 - actually activate window correctly during show
Oct 6, 2021
261a0f0
fix tray icon closing.
Oct 6, 2021
ffc7948
fix review comments on X11TrayIconImpl.cs
jmacato Oct 6, 2021
4288565
fix nullable warnings
jmacato Oct 6, 2021
63e616c
zero warnings on X11TrayIconImpl.cs
jmacato Oct 6, 2021
8c4a702
use less verbose guid generation code
jmacato Oct 6, 2021
8183d24
add a comment re: SNIItemProps
jmacato Oct 6, 2021
daddc71
remove trayicon events from osx.
Oct 6, 2021
2962d88
Merge branch 'feature/tray-icon-support' of github.com:AvaloniaUI/Ava…
Oct 6, 2021
ca5d78d
fix warnings and use readonly fields.
Oct 6, 2021
f0dcaea
fix warnings and issues.
Oct 6, 2021
89f7742
more review fixes.
Oct 6, 2021
597239c
more review fixes.
Oct 6, 2021
15829fb
formatting.
Oct 6, 2021
24faaee
fix static variable.
Oct 6, 2021
ca39b41
use subscribe instead of assign.
Oct 6, 2021
dd3d394
fix variable name.
Oct 6, 2021
afd7203
fix formatting
Oct 7, 2021
7b0fbe6
minor nits
Oct 7, 2021
71616ac
nit
Oct 7, 2021
99d9834
fix errors related to old sdk
Oct 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
37E2330F21583241000CB7E2 /* KeyTransform.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37E2330E21583241000CB7E2 /* KeyTransform.mm */; };
520624B322973F4100C4DCEF /* menu.mm in Sources */ = {isa = PBXBuildFile; fileRef = 520624B222973F4100C4DCEF /* menu.mm */; };
522D5959258159C1006F7F7A /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 522D5958258159C1006F7F7A /* Carbon.framework */; };
523484CA26EA688F00EA0C2C /* trayicon.mm in Sources */ = {isa = PBXBuildFile; fileRef = 523484C926EA688F00EA0C2C /* trayicon.mm */; };
5B21A982216530F500CEE36E /* cursor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B21A981216530F500CEE36E /* cursor.mm */; };
5B8BD94F215BFEA6005ED2A7 /* clipboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B8BD94E215BFEA6005ED2A7 /* clipboard.mm */; };
AB00E4F72147CA920032A60A /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB00E4F62147CA920032A60A /* main.mm */; };
Expand Down Expand Up @@ -51,6 +52,8 @@
37E2330E21583241000CB7E2 /* KeyTransform.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyTransform.mm; sourceTree = "<group>"; };
520624B222973F4100C4DCEF /* menu.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = menu.mm; sourceTree = "<group>"; };
522D5958258159C1006F7F7A /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
523484C926EA688F00EA0C2C /* trayicon.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = trayicon.mm; sourceTree = "<group>"; };
523484CB26EA68AA00EA0C2C /* trayicon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = trayicon.h; sourceTree = "<group>"; };
5B21A981216530F500CEE36E /* cursor.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = cursor.mm; sourceTree = "<group>"; };
5B8BD94E215BFEA6005ED2A7 /* clipboard.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard.mm; sourceTree = "<group>"; };
5BF943652167AD1D009CAE35 /* cursor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cursor.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -114,6 +117,8 @@
AB00E4F62147CA920032A60A /* main.mm */,
37155CE3233C00EB0034DCE9 /* menu.h */,
520624B222973F4100C4DCEF /* menu.mm */,
523484C926EA688F00EA0C2C /* trayicon.mm */,
523484CB26EA68AA00EA0C2C /* trayicon.h */,
1A3E5EA723E9E83B00EDE661 /* rendertarget.mm */,
37A517B22159597E00FBA241 /* Screens.mm */,
37C09D8721580FE4006A6758 /* SystemDialogs.mm */,
Expand Down Expand Up @@ -204,6 +209,7 @@
1A1852DC23E05814008F0DED /* deadlock.mm in Sources */,
5B21A982216530F500CEE36E /* cursor.mm in Sources */,
37DDA9B0219330F8002E132B /* AvnString.mm in Sources */,
523484CA26EA688F00EA0C2C /* trayicon.mm in Sources */,
AB8F7D6B21482D7F0057DBA5 /* platformthreading.mm in Sources */,
1A3E5EA823E9E83B00EDE661 /* rendertarget.mm in Sources */,
1A3E5EAE23E9FB1300EDE661 /* cgl.mm in Sources */,
Expand Down
1 change: 1 addition & 0 deletions native/Avalonia.Native/src/OSX/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern AvnDragDropEffects ConvertDragDropEffects(NSDragOperation nsop);
extern IAvnCursorFactory* CreateCursorFactory();
extern IAvnGlDisplay* GetGlDisplay();
extern IAvnMenu* CreateAppMenu(IAvnMenuEvents* events);
extern IAvnTrayIcon* CreateTrayIcon();
extern IAvnMenuItem* CreateAppMenuItem();
extern IAvnMenuItem* CreateAppMenuItemSeparator();
extern IAvnNativeControlHost* CreateNativeControlHost(NSView* parent);
Expand Down
11 changes: 11 additions & 0 deletions native/Avalonia.Native/src/OSX/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ virtual HRESULT ObtainGlDisplay(IAvnGlDisplay** ppv) override
}
}

virtual HRESULT CreateTrayIcon (IAvnTrayIcon** ppv) override
{
START_COM_CALL;

@autoreleasepool
{
*ppv = ::CreateTrayIcon();
return S_OK;
}
}

virtual HRESULT CreateMenu (IAvnMenuEvents* cb, IAvnMenu** ppv) override
{
START_COM_CALL;
Expand Down
33 changes: 33 additions & 0 deletions native/Avalonia.Native/src/OSX/trayicon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// trayicon.h
// Avalonia.Native.OSX
//
// Created by Dan Walmsley on 09/09/2021.
// Copyright © 2021 Avalonia. All rights reserved.
//

#ifndef trayicon_h
#define trayicon_h

#include "common.h"

class AvnTrayIcon : public ComSingleObject<IAvnTrayIcon, &IID_IAvnTrayIcon>
{
private:
NSStatusItem* _native;

public:
FORWARD_IUNKNOWN()

AvnTrayIcon();

~AvnTrayIcon ();

virtual HRESULT SetIcon (void* data, size_t length) override;

virtual HRESULT SetMenu (IAvnMenu* menu) override;

virtual HRESULT SetIsVisible (bool isVisible) override;
};

#endif /* trayicon_h */
85 changes: 85 additions & 0 deletions native/Avalonia.Native/src/OSX/trayicon.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "common.h"
#include "trayicon.h"
#include "menu.h"

extern IAvnTrayIcon* CreateTrayIcon()
{
@autoreleasepool
{
return new AvnTrayIcon();
}
}

AvnTrayIcon::AvnTrayIcon()
{
_native = [[NSStatusBar systemStatusBar] statusItemWithLength: NSSquareStatusItemLength];

}

AvnTrayIcon::~AvnTrayIcon()
{
if(_native != nullptr)
{
[[_native statusBar] removeStatusItem:_native];
_native = nullptr;
}
}

HRESULT AvnTrayIcon::SetIcon (void* data, size_t length)
{
START_COM_CALL;

@autoreleasepool
{
if(data != nullptr)
{
NSData *imageData = [NSData dataWithBytes:data length:length];
NSImage *image = [[NSImage alloc] initWithData:imageData];

NSSize originalSize = [image size];

NSSize size;
size.height = [[NSFont menuFontOfSize:0] pointSize] * 1.333333;

auto scaleFactor = size.height / originalSize.height;
size.width = originalSize.width * scaleFactor;

[image setSize: size];
[_native setImage:image];
}
else
{
[_native setImage:nullptr];
}
return S_OK;
}
}

HRESULT AvnTrayIcon::SetMenu (IAvnMenu* menu)
{
START_COM_CALL;

@autoreleasepool
{
auto appMenu = dynamic_cast<AvnAppMenu*>(menu);

if(appMenu != nullptr)
{
[_native setMenu:appMenu->GetNative()];
}
}

return S_OK;
}

HRESULT AvnTrayIcon::SetIsVisible(bool isVisible)
{
START_COM_CALL;

@autoreleasepool
{
[_native setVisible:isVisible];
}

return S_OK;
}
25 changes: 24 additions & 1 deletion samples/ControlCatalog/App.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:ControlCatalog.ViewModels"
x:DataType="vm:ApplicationViewModel"
x:CompileBindings="True"
x:Class="ControlCatalog.App">
<Application.Styles>
<Style Selector="TextBlock.h1">
Expand All @@ -22,6 +25,26 @@
<Style Selector="Label.h3">
<Setter Property="FontSize" Value="12" />
</Style>
<StyleInclude Source="/SideBar.xaml"/>
<StyleInclude Source="/SideBar.xaml" />
</Application.Styles>
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/test_icon.ico" ToolTipText="Avalonia Tray Icon ToolTip">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Settings">
<NativeMenu>
<NativeMenuItem Header="Option 1" ToggleType="Radio" IsChecked="True" Command="{Binding ToggleCommand}" />
<NativeMenuItem Header="Option 2" ToggleType="Radio" IsChecked="True" Command="{Binding ToggleCommand}" />
<NativeMenuItemSeparator />
<NativeMenuItem Header="Option 3" ToggleType="CheckBox" IsChecked="True" Command="{Binding ToggleCommand}" />
<NativeMenuItem Icon="/Assets/test_icon.ico" Header="Restore Defaults" Command="{Binding ToggleCommand}" />
</NativeMenu>
</NativeMenuItem>
<NativeMenuItem Header="Exit" Command="{Binding ExitCommand}" />
</NativeMenu>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>
</Application>
9 changes: 9 additions & 0 deletions samples/ControlCatalog/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.Styling;
using Avalonia.Styling;
using ControlCatalog.ViewModels;

namespace ControlCatalog
{
public class App : Application
{
public App()
{
DataContext = new ApplicationViewModel();
}

private static readonly StyleInclude DataGridFluent = new StyleInclude(new Uri("avares://ControlCatalog/Styles"))
{
Source = new Uri("avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml")
Expand Down Expand Up @@ -97,7 +104,9 @@ public override void Initialize()
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
desktopLifetime.MainWindow = new MainWindow();
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
singleViewLifetime.MainView = new MainView();

Expand Down
2 changes: 2 additions & 0 deletions samples/ControlCatalog/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public MainWindow()

var mainMenu = this.FindControl<Menu>("MainMenu");
mainMenu.AttachedToVisualTree += MenuAttached;

ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.OSXThickTitleBar;
}

public static string MenuQuitHeader => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "Quit Avalonia" : "E_xit";
Expand Down
26 changes: 26 additions & 0 deletions samples/ControlCatalog/ViewModels/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using MiniMvvm;

namespace ControlCatalog.ViewModels
{
public class ApplicationViewModel : ViewModelBase
{
public ApplicationViewModel()
{
ExitCommand = MiniCommand.Create(() =>
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
lifetime.Shutdown();
}
});

ToggleCommand = MiniCommand.Create(() => { });
}

public MiniCommand ExitCommand { get; }

public MiniCommand ToggleCommand { get; }
}
}
5 changes: 5 additions & 0 deletions src/Avalonia.Base/Logging/LogArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ public static class LogArea
/// The log event comes from Win32Platform.
/// </summary>
public const string Win32Platform = nameof(Win32Platform);

/// <summary>
/// The log event comes from X11Platform.
/// </summary>
public const string X11Platform = nameof(X11Platform);
}
}
4 changes: 3 additions & 1 deletion src/Avalonia.Controls/ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ MembersMustExist : Member 'public System.Action<Avalonia.Size> Avalonia.Controls
MembersMustExist : Member 'public void Avalonia.Controls.Embedding.Offscreen.OffscreenTopLevelImplBase.Resized.set(System.Action<Avalonia.Size>)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Controls.Embedding.Offscreen.OffscreenTopLevelImplBase.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public Avalonia.AvaloniaProperty Avalonia.AvaloniaProperty Avalonia.Controls.Notifications.NotificationCard.CloseOnClickProperty' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.Platform.ITopLevelNativeMenuExporter.SetNativeMenu(Avalonia.Controls.NativeMenu)' is present in the contract but not in the implementation.
EnumValuesMustMatch : Enum value 'Avalonia.Platform.ExtendClientAreaChromeHints Avalonia.Platform.ExtendClientAreaChromeHints.Default' is (System.Int32)2 in the implementation but (System.Int32)1 in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Nullable<Avalonia.Size> Avalonia.Platform.ITopLevelImpl.FrameSize' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Nullable<Avalonia.Size> Avalonia.Platform.ITopLevelImpl.FrameSize.get()' is present in the implementation but not in the contract.
Expand All @@ -55,4 +56,5 @@ InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platfor
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IWindowImpl.Resize(Avalonia.Size)' is present in the contract but not in the implementation.
MembersMustExist : Member 'public void Avalonia.Platform.IWindowImpl.Resize(Avalonia.Size)' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IWindowImpl.Resize(Avalonia.Size, Avalonia.Platform.PlatformResizeReason)' is present in the implementation but not in the contract.
Total Issues: 56
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.ITrayIconImpl Avalonia.Platform.IWindowingPlatform.CreateTrayIcon()' is present in the implementation but not in the contract.
Total Issues: 58
13 changes: 6 additions & 7 deletions src/Avalonia.Controls/NativeMenu.Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,10 @@ static void SetIsNativeMenuExported(TopLevel tl, bool value)
}

public static readonly AttachedProperty<NativeMenu> MenuProperty
= AvaloniaProperty.RegisterAttached<NativeMenu, AvaloniaObject, NativeMenu>("Menu"/*, validate:
(o, v) =>
{
if(!(o is Application || o is TopLevel))
throw new InvalidOperationException("NativeMenu.Menu property isn't valid on "+o.GetType());
return v;
}*/);
= AvaloniaProperty.RegisterAttached<NativeMenu, AvaloniaObject, NativeMenu>("Menu");

public static void SetMenu(AvaloniaObject o, NativeMenu menu) => o.SetValue(MenuProperty, menu);

public static NativeMenu GetMenu(AvaloniaObject o) => o.GetValue(MenuProperty);

static NativeMenu()
Expand All @@ -79,6 +74,10 @@ static NativeMenu()
{
GetInfo(tl).Exporter?.SetNativeMenu(args.NewValue.GetValueOrDefault());
}
else if(args.Sender is INativeMenuExporterProvider provider)
{
provider.NativeMenuExporter?.SetNativeMenu(args.NewValue.GetValueOrDefault());
}
});
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/Avalonia.Controls/Platform/ITopLevelNativeMenuExporter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
using System;
using System.Collections.Generic;
using Avalonia.Platform;

#nullable enable

namespace Avalonia.Controls.Platform
{
public interface ITopLevelNativeMenuExporter
public interface INativeMenuExporter
{
void SetNativeMenu(NativeMenu? menu);
}

public interface ITopLevelNativeMenuExporter : INativeMenuExporter
{
bool IsNativeMenuExported { get; }

event EventHandler OnIsNativeMenuExportedChanged;
void SetNativeMenu(NativeMenu menu);
}

public interface INativeMenuExporterProvider
{
INativeMenuExporter? NativeMenuExporter { get; }
}

public interface ITopLevelImplWithNativeMenuExporter : ITopLevelImpl
Expand Down