Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions GalaxyBudsClient/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,9 @@ public override void Initialize()

#if OSX
NSApplication.Init();
NSApplication.Notifications.ObserveDidBecomeActive((_, _) =>
{
Dispatcher.UIThread.InvokeAsync(delegate
{
MainWindow.Instance.BringToFront();
});
});
// For menu bar applications (LSUIElement=true), hide the dock icon immediately at startup.
// The dock icon will only appear when the settings window is explicitly opened.
GalaxyBudsClient.Platform.OSX.AppUtils.setHideInDock(true);
#endif

AvaloniaXamlLoader.Load(this);
Expand Down Expand Up @@ -108,8 +104,16 @@ public override void OnFrameworkInitializationCompleted()
{
// Initialize MainWindow singleton
var mainWindow = MainWindow.Instance;

#if OSX
// On macOS with LSUIElement=true, always start as a menu bar app (no main window attached initially)
// The window will be shown when the user clicks the tray icon
desktop.MainWindow = null;
mainWindow.IsVisible = false;
#else
// Stay initially minimized: don't attach a main window
desktop.MainWindow = StartMinimized ? null : mainWindow;
#endif

TrayManager.Init();
BatteryHistoryManager.Init();
Expand Down Expand Up @@ -353,4 +357,4 @@ private async void HandleOtherTouchOption(object? sender, TouchOptions e)
break;
}
}
}
}
2 changes: 2 additions & 0 deletions GalaxyBudsClient/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<string>Galaxy Buds Manager</string>
<key>CFBundleDisplayName</key>
<string>Galaxy Buds Manager</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
51 changes: 43 additions & 8 deletions GalaxyBudsClient/Interface/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ private void OnLanguageUpdated()

protected override async void OnClosing(WindowClosingEventArgs e)
{
#if OSX
// On macOS with LSUIElement, minimize to tray if setting is enabled
if (Settings.Data.MinimizeToTray && e.CloseReason is not (WindowCloseReason.OSShutdown or WindowCloseReason.ApplicationShutdown))
{
BringToTray();
e.Cancel = true;
Log.Debug("MainWindow.OnClosing: macOS menu bar app - minimized to tray");
base.OnClosing(e);
return;
}

// If MinimizeToTray is off, quit the app when closing the window
if (!Settings.Data.MinimizeToTray)
{
Log.Debug("MainWindow.OnClosing: macOS - MinimizeToTray disabled, closing app");
}
#else
if (Settings.Data.MinimizeToTray && PlatformUtils.SupportsTrayIcon)
{
// check if the cause of the termination is due to shutdown or application close request
Expand All @@ -77,6 +94,7 @@ protected override async void OnClosing(WindowClosingEventArgs e)
{
Log.Debug("MainWindow.OnClosing: Now closing session");
}
#endif

await BluetoothImpl.Instance.SendRequestAsync(MsgIds.FIND_MY_EARBUDS_STOP);
await BluetoothImpl.Instance.DisconnectAsync();
Expand Down Expand Up @@ -124,26 +142,32 @@ public void BringToFront()
{
Dispatcher.UIThread.InvokeAsync(() =>
{
#if OSX
// On macOS, show in dock first, then make window visible
GalaxyBudsClient.Platform.OSX.AppUtils.setHideInDock(false);
#endif

if (App.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop &&
desktop.MainWindow == null)
{
desktop.MainWindow = this;
}

if (WindowState == WindowState.Minimized)
{
WindowState = WindowState.Normal;
}
// Ensure window state is normal before showing
WindowState = WindowState.Normal;

if (PlatformUtils.IsLinux)
{
IsVisible = false; // Workaround for some Linux DMs
}

IsVisible = true;

#if OSX
GalaxyBudsClient.Platform.OSX.AppUtils.setHideInDock(false);
// On macOS, re-apply theme to restore blur/transparency effects
// This is needed because effects don't persist when window is hidden/shown
(this as IStyledWindow).ApplyTheme(this);
#endif
IsVisible = true;

Activate();
Topmost = true;
Expand Down Expand Up @@ -172,11 +196,22 @@ public void ToggleVisibility()
private void BringToTray()
{
#if OSX
// On macOS, we need to hide the window completely without minimizing to dock
// First hide visibility, then hide from dock
IsVisible = false;
ShowInTaskbar = false;
GalaxyBudsClient.Platform.OSX.AppUtils.setHideInDock(true);
#endif

// Detach the main window so macOS doesn't try to show the app in dock
if (App.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = null;
}
#else
ShowInTaskbar = false;
WindowState = WindowState.Minimized;
IsVisible = false;
#endif
}

private void OnBluetoothError(object? sender, BluetoothException e)
Expand All @@ -195,4 +230,4 @@ private void OnBluetoothError(object? sender, BluetoothException e)
}
});
}
}
}