Avalonia.FuncUI icon indicating copy to clipboard operation
Avalonia.FuncUI copied to clipboard

Getting the window icon working (MacOS)

Open Evelios opened this issue 3 years ago • 4 comments

I've been trying to figure out how to get my gui's window icon to register within the system dock within MacOS. I would like to get it working on all platforms, however I wasn't sure if there were extra quirks to MacOS that I was missing. This also seems like a good thing that could be added to the examples and templates for reference for people picking up the project for the first time.

Shell.fs

type MainWindow() as this =
    inherit HostWindow()

    do
        base.Title <- "Title"
        base.Width <- 600
        base.Height <- 400
        base.Icon <- WindowIcon "avares://Gui/Assets/Icon.ico"
        this.HasSystemDecorations <- true

Gui.fsproj

<Project Sdk="Microsoft.NET.Sdk">

    <ItemGroup>
        <AvaloniaResource Include="**\*.xaml" />
        <AvaloniaResource Include="Assets\*.ico" />
    </ItemGroup>

    ...

</Project>

I had also tried this without success

type MainWindow() as this =
    inherit HostWindow()
    do
        base.Icon <- WindowIcon "Assets/Icon.ico"
        <None Include="Assets\*" CopyToOutputDirectory="PreserveNewest" Link="Assets" />

Evelios avatar Mar 11 '22 14:03 Evelios

Could you take a look at the PR #185 and try out the same approach? The submitter mentions having the same problem of the icons not being correctly picked up by the Avalonia resources on Windows as well, so seems like it's not only happening on Mac.

Still it'd be interesting to take a further look to see if this is an issue with FuncUI or Avalonia itself.

sleepyfran avatar Mar 11 '22 23:03 sleepyfran

It looks like he was using the following approach, using the Content container instead of None and using the CopyToOutputDirectyory subelement instead of a data block. This didn't give any difference in results unfortunately.

<Project Sdk="Microsoft.NET.Sdk">
    <ItemGroup>        
        <Content Include="Assets\Icons\icon.ico">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>
    ...
</Project>

By the way, just wanted share the screenshot of the current state of the icon for reference

Screen Shot 2022-03-14 at 2 14 25 PM

I'm seeing this issue https://github.com/AvaloniaUI/Avalonia/issues/2649 and this pull request to avalonia https://github.com/AvaloniaUI/Avalonia/pull/6560 although it looks like it was merged into Avalonia 0.10.10

Edit:

I upgraded to Avalonia.FuncUI 0.5 which and Avalonia 10.11 and this did not solve the issue

Evelios avatar Mar 14 '22 18:03 Evelios

For macOS I believe you need to create an app bundle that includes an .icns icon for it to work.

https://docs.avaloniaui.net/docs/distribution-publishing/macos

iminashi avatar Mar 14 '22 21:03 iminashi

@iminashi Thanks, this seems to be the right road to go down. I tested my previous attempts on Linux and I'm able to get the icon working. I haven't gotten it working on Mac yet but I anticipate that with some more work and the Avalonia publishing guide, I should get there

Evelios avatar Mar 16 '22 21:03 Evelios