Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Customize "Avalonia Application" title in MacOS #3541

Closed
alessandrofrancesconi opened this issue Feb 9, 2020 · 5 comments
Closed

Customize "Avalonia Application" title in MacOS #3541

alessandrofrancesconi opened this issue Feb 9, 2020 · 5 comments
Labels

Comments

@alessandrofrancesconi
Copy link
Contributor

I've noticed that when running my project after dotnet publish on MacOS (Catalina), the title "Avalonia Application" appears in the upper bar

titlebar

Also there is an "About" submenu that opens this dialog:

about

How can I change this and maybe replace with custom graphics?

@alessandrofrancesconi alessandrofrancesconi changed the title Get rid of "Avalonia Application" title in MacOS Customize "Avalonia Application" title in MacOS Feb 9, 2020
@kekekeks
Copy link
Member

kekekeks commented Feb 9, 2020

  1. Set Name property on the Application in your App.xaml
  2. Add a customized native app menu to your App.xaml:
  <NativeMenu.Menu>
    <NativeMenu>
      <NativeMenuItem Header="About My App" Command="{Binding AboutCommand}" />
    </NativeMenu>
  </NativeMenu.Menu>

it will replace the default one.

We probably need that in our default app template.

@sandermvanvliet
Copy link

sandermvanvliet commented May 19, 2022

I've just found this issue after some googling and wanted to add some additional details.

When you set Name in your App.xaml but package your app in a bundle you'll find that if you set CFBundleName in the Info.plist to something else then macOS will use the value from CFBundleName

For example:

App.xaml

<Application
   ...
   Name="Test app">
</Application>

Info.plist

<plist version="1.0">
    <dict>
        ....
        <key>CFBundleName</key>
        <string>Something else</string>
        ....
    </dict>
</plist>

build and publish the app to TestApp.app and then from Finder run the app:

appname

You could omit CFBundleName from the Info.plist in the app bundle, however if you have CFBundleDisplayName specified then macOS will use that value as the title for the app.

When you specify both CFBundleName and CFBundleDisplayName then CFBundleName takes precedence.

The Apple Developer docs specify that CFBundleName:

may be displayed to users in situations such as the absence of a value for CFBundleDisplayName

Whereas CFBundleDisplayName documentation states:

specifies the display name of the bundle, visible to users and used by Siri.
Which means that this is a key you should most probably always include in your app bundle.

So to reduce the amount of head-scratching and debugging for other people, my recommendation would be to:

  1. Always set CFBundleDisplayName in Info.plist
  2. Set CFBundleName to the same value
  3. Ensure that Name in App.xaml is set to the same value

Depending on the build configuration it seems like a smart idea to generate the contents of Info.plist at publish time based on the Name in App.xaml.

I'll create a PR on the Avalonia documentation site to make sure this appears there too.

Note: I tried to actually call AvaloniaNativePlatform.SetupApplicationName() somewhere after the app starts but whatever you provide there is ignored by macOS.

Note 2: This all of course doesn't show up when you launch the app from Rider or the output directory...

@jeffdoolittle
Copy link

jeffdoolittle commented Oct 20, 2022

@kekekeks

Referring to this comment: #3541 (comment)

Where do you define the command since in this case the binding is happening in App.xaml?

@timunie
Copy link
Contributor

timunie commented Oct 21, 2022

Different possibility I think. If it was me I would have an AppViewModel which has a static instance and holds all of my Apps Commands. In the binding you can set that instance as source via x:static

@kekekeks
Copy link
Member

@jeffdoolittle App class can have it's own DataContext You are supposed to initialize it in OnFrameworkInitializationCompleted

@AvaloniaUI AvaloniaUI locked and limited conversation to collaborators Nov 3, 2022
@timunie timunie converted this issue into discussion #9346 Nov 3, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

6 participants