Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,6 @@ FodyWeavers.xsd
*.msm
*.msp
nohup.out

# MAUI DevFlow runtime logs
mauidevflow-logs/
24 changes: 24 additions & 0 deletions src/MauiSherpa.LinuxGtk/LinuxIconTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace MauiSherpa;

/// <summary>
/// Registers the app's bundled symbolic icons with the GTK icon theme. Icons named
/// <c>*-symbolic</c> are recolored by GTK from the widget's foreground color, so they
/// follow light/dark switches without per-theme assets.
/// </summary>
internal static class LinuxIconTheme
{
private static bool _registered;

public static void EnsureRegistered()
{
if (_registered || Gdk.Display.GetDefault() is not { } display)
return;

var iconDirectory = Path.Combine(AppContext.BaseDirectory, "Resources", "icons");
if (!Directory.Exists(iconDirectory))
return;

Gtk.IconTheme.GetForDisplay(display).AddSearchPath(iconDirectory);
_registered = true;
}
}
214 changes: 214 additions & 0 deletions src/MauiSherpa.LinuxGtk/LinuxNavigationSidebar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
using MauiSherpa.Core.Interfaces;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platforms.Linux.Gtk4.Handlers;

namespace MauiSherpa;

/// <summary>
/// Native GTK navigation sidebar for the Linux head. Mirrors the Blazor sidebar's
/// sections and routes, and uses GTK's <c>navigation-sidebar</c> list styling so it
/// follows the active system theme.
/// </summary>
public sealed class LinuxNavigationSidebar : View
{
public const double SidebarWidth = 250;

public LinuxNavigationSidebar(IToolbarService toolbarService)
{
ToolbarService = toolbarService;
WidthRequest = SidebarWidth;
AutomationId = "linux-sidebar";
}

public IToolbarService ToolbarService { get; }
}

public sealed class LinuxNavigationSidebarHandler : GtkViewHandler<LinuxNavigationSidebar, Gtk.Box>
{
private sealed record NavItem(string Route, bool Exact, Gtk.ListBoxRow Row);

public static readonly IPropertyMapper<LinuxNavigationSidebar, LinuxNavigationSidebarHandler> Mapper =
new PropertyMapper<LinuxNavigationSidebar, LinuxNavigationSidebarHandler>(ViewMapper);

private readonly List<NavItem> _items = new();
private readonly List<Gtk.Widget> _widgets = new(); // keep GirCore wrappers alive
private Gtk.ListBox? _listBox;
private bool _syncingSelection;
private string? _pendingRoute;

public LinuxNavigationSidebarHandler() : base(Mapper)
{
}

protected override Gtk.Box CreatePlatformView()
{
LinuxIconTheme.EnsureRegistered();

var root = Gtk.Box.New(Gtk.Orientation.Horizontal, 0);
root.AddCssClass("sherpa-sidebar");

_listBox = Gtk.ListBox.New();
_listBox.AddCssClass("navigation-sidebar");
_listBox.SetSelectionMode(Gtk.SelectionMode.Single);
_listBox.OnRowActivated += OnRowActivated;
_listBox.OnRowSelected += OnRowSelected;

AddItem("Dashboard", "/", "sherpa-home-symbolic", exact: true);

AddHeader("Android", "sherpa-android-symbolic");
AddItem("Devices & Emulators", "/devices", "sherpa-mobile-screen-button-symbolic");
AddItem("SDK Packages", "/android-sdk", "sherpa-cube-symbolic");
AddItem("Keystores", "/keystores", "sherpa-key-symbolic");
AddItem("Push Testing", "/firebase-push", "sherpa-paper-plane-symbolic");

AddHeader("Apple", "sherpa-apple-symbolic");
AddItem("Registered Devices", "/apple-devices", "sherpa-mobile-screen-button-symbolic");
AddItem("Bundle IDs", "/bundle-ids", "sherpa-fingerprint-symbolic");
AddItem("Certificates", "/certificates", "sherpa-certificate-symbolic");
AddItem("Provisioning Profiles", "/profiles", "sherpa-id-card-symbolic");
AddItem("Push Testing", "/push-testing", "sherpa-paper-plane-symbolic");

AddHeader("Secrets", "sherpa-vault-symbolic");
AddItem("Secrets", "/secrets", "sherpa-key-symbolic", exact: true);
AddItem("Publish", "/secrets/publish", "sherpa-upload-symbolic");

AddHeader("Tools", "sherpa-toolbox-symbolic");
AddItem(".NET SDK Manager", "/dotnet-sdk", "sherpa-layer-group-symbolic");
AddItem("Profiling", "/profiling", "sherpa-chart-line-symbolic");
AddItem("App Inspector", "/devflow", "sherpa-wand-magic-sparkles-symbolic");

#if DEBUG
if (!MauiSherpa.Core.Screenshots.ScreenshotMode.Current.IsEnabled)
AddItem("Debug UI", "/debug", "sherpa-bug-symbolic");
#endif

var scroller = Gtk.ScrolledWindow.New();
scroller.SetPolicy(Gtk.PolicyType.Never, Gtk.PolicyType.Automatic);
scroller.SetHexpand(true);
scroller.SetVexpand(true);
scroller.SetChild(_listBox);

var separator = Gtk.Separator.New(Gtk.Orientation.Vertical);

root.Append(scroller);
root.Append(separator);
_widgets.Add(scroller);
_widgets.Add(separator);
return root;
}

protected override void ConnectHandler(Gtk.Box platformView)
{
base.ConnectHandler(platformView);
VirtualView.ToolbarService.RouteChanged += OnRouteChanged;
SelectRoute(VirtualView.ToolbarService.CurrentRoute);
}

protected override void DisconnectHandler(Gtk.Box platformView)
{
VirtualView.ToolbarService.RouteChanged -= OnRouteChanged;
base.DisconnectHandler(platformView);
}

private void AddHeader(string title, string iconName)
{
var box = Gtk.Box.New(Gtk.Orientation.Horizontal, 8);
box.SetMarginTop(12);
box.SetMarginStart(6);
box.AddCssClass("dim-label");

var icon = Gtk.Image.NewFromIconName(iconName);
icon.SetPixelSize(12);
var label = Gtk.Label.New(title);
label.SetXalign(0);
label.AddCssClass("caption-heading");
label.AddCssClass("heading");
box.Append(icon);
box.Append(label);

var row = Gtk.ListBoxRow.New();
row.SetChild(box);
row.SetSelectable(false);
row.SetActivatable(false);
row.SetFocusable(false);
_listBox!.Append(row);
_widgets.AddRange([box, icon, label, row]);
}

private void AddItem(string title, string route, string iconName, bool exact = false)
{
var box = Gtk.Box.New(Gtk.Orientation.Horizontal, 12);
var icon = Gtk.Image.NewFromIconName(iconName);
icon.SetPixelSize(16);
var label = Gtk.Label.New(title);
label.SetXalign(0);
label.SetEllipsize(Pango.EllipsizeMode.End);
box.Append(icon);
box.Append(label);

var row = Gtk.ListBoxRow.New();
row.SetChild(box);
row.SetTooltipText(title);
_listBox!.Append(row);
_items.Add(new NavItem(route, exact, row));
_widgets.AddRange([box, icon, label, row]);
}

private void OnRowActivated(Gtk.ListBox sender, Gtk.ListBox.RowActivatedSignalArgs args)
=> NavigateTo(args.Row);

// Selection also changes through keyboard and assistive technologies, which don't
// always emit row-activated.
private void OnRowSelected(Gtk.ListBox sender, Gtk.ListBox.RowSelectedSignalArgs args)
=> NavigateTo(args.Row);

private void NavigateTo(Gtk.ListBoxRow? row)
{
if (_syncingSelection || row == null)
return;

var handle = row.Handle.DangerousGetHandle();
var item = _items.FirstOrDefault(i => i.Row.Handle.DangerousGetHandle() == handle);
// A click emits both row-selected and row-activated; request each route once.
if (item == null || string.Equals(item.Route, _pendingRoute, StringComparison.OrdinalIgnoreCase))
return;

_pendingRoute = item.Route;
VirtualView?.ToolbarService.RequestNavigation(item.Route);
}

private void OnRouteChanged(string route)
{
GLib.Functions.IdleAdd(0, () =>
{
_pendingRoute = null;
SelectRoute(route);
return false;
});
}

private void SelectRoute(string route)
{
if (_listBox == null)
return;

var match = _items
.Where(i => string.Equals(route, i.Route, StringComparison.OrdinalIgnoreCase)
|| (!i.Exact && route.StartsWith(i.Route + "/", StringComparison.OrdinalIgnoreCase)))
.OrderByDescending(i => i.Route.Length)
.FirstOrDefault();

_syncingSelection = true;
try
{
if (match != null)
_listBox.SelectRow(match.Row);
else
_listBox.UnselectAll();
}
finally
{
_syncingSelection = false;
}
}
}
65 changes: 12 additions & 53 deletions src/MauiSherpa.LinuxGtk/LinuxToolbarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class LinuxToolbarManager
{
private readonly IToolbarService _toolbarService;
private readonly ICopilotContextService _copilotContext;
private readonly IThemeService _themeService;
private readonly IAppleIdentityService _appleIdentityService;
private readonly IAppleIdentityStateService _appleIdentityState;
private readonly IGoogleIdentityService _googleIdentityService;
Expand All @@ -27,7 +26,6 @@ public class LinuxToolbarManager
private readonly List<Gtk.Widget> _retainedWidgets = new(); // prevent GC of removed GTK widgets
private Gtk.SearchEntry? _searchEntry;
private Gtk.Button? _copilotButton;
private Gtk.Image? _copilotImage;
private Gtk.DropDown? _identityDropdown;
private CancellationTokenSource? _identityCts;
private bool _rebuildQueued;
Expand Down Expand Up @@ -62,19 +60,14 @@ public class LinuxToolbarManager
["fa-cog"] = "emblem-system-symbolic",
["fa-download"] = "document-save-symbolic",
["fa-sync-alt"] = "view-refresh-symbolic",
};

// Icons rendered from Font Awesome as PNGs (dark/white variants for theme support)
// Format: sfSymbol → (darkFile, whiteFile) relative to Resources/
private static readonly Dictionary<string, (string Dark, string White)> CustomIconMap = new(StringComparer.OrdinalIgnoreCase)
{
["fa-stethoscope"] = ("fa-stethoscope-24.png", "fa-stethoscope-white-24.png"),
// Bundled symbolic icons (Resources/icons) that GTK recolors for the active theme
["fa-stethoscope"] = "sherpa-stethoscope-symbolic",
};

public LinuxToolbarManager(
IToolbarService toolbarService,
ICopilotContextService copilotContext,
IThemeService themeService,
IAppleIdentityService appleIdentityService,
IAppleIdentityStateService appleIdentityState,
IGoogleIdentityService googleIdentityService,
Expand All @@ -84,7 +77,6 @@ public LinuxToolbarManager(
{
_toolbarService = toolbarService;
_copilotContext = copilotContext;
_themeService = themeService;
_appleIdentityService = appleIdentityService;
_appleIdentityState = appleIdentityState;
_googleIdentityService = googleIdentityService;
Expand All @@ -93,16 +85,18 @@ public LinuxToolbarManager(
_bridgeHolder = bridgeHolder;
_toolbarService.ToolbarChanged += OnToolbarChanged;
_toolbarService.RouteChanged += OnRouteChanged;
_themeService.ThemeChanged += OnThemeChanged;
}

public void AttachToWindow(Gtk.Window window)
{
_window = window;
LinuxIconTheme.EnsureRegistered();
_headerBar = Gtk.HeaderBar.New();
_headerBar.SetShowTitleButtons(true);
// Hide the window title text — app icon in the HeaderBar is sufficient
_headerBar.SetTitleWidget(Gtk.Label.New(""));
var titleLabel = Gtk.Label.New("");
_headerBar.SetTitleWidget(titleLabel);
_retainedWidgets.Add(titleLabel);

// App icon on the far left with spacing
var appIconPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Resources", "appicon-24.png");
Expand All @@ -112,13 +106,13 @@ public void AttachToWindow(Gtk.Window window)
appIcon.SetMarginStart(4);
appIcon.SetMarginEnd(4);
_headerBar.PackStart(appIcon);
_retainedWidgets.Add(appIcon);
}

// Copilot button next to app icon
_copilotButton = Gtk.Button.New();
_copilotButton.SetTooltipText("GitHub Copilot");
_copilotImage = CreateCopilotIcon();
_copilotButton.SetChild(_copilotImage);
_copilotButton.SetIconName("sherpa-copilot-symbolic");
_copilotButton.OnClicked += (s, _) => _copilotContext.ToggleOverlay();
_headerBar.PackStart(_copilotButton);

Expand All @@ -128,44 +122,19 @@ public void AttachToWindow(Gtk.Window window)
settingsButton.SetTooltipText("Settings");
settingsButton.OnClicked += (s, _) => OpenSettingsDialog();
_headerBar.PackStart(settingsButton);
_retainedWidgets.Add(settingsButton);

// Doctor button beside settings
var doctorButton = Gtk.Button.New();
var doctorIconName = _themeService.IsDarkMode ? "fa-stethoscope-white-24.png" : "fa-stethoscope-24.png";
var doctorIconPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Resources", doctorIconName);
if (System.IO.File.Exists(doctorIconPath))
doctorButton.SetChild(Gtk.Image.NewFromFile(doctorIconPath));
else
doctorButton.SetIconName("dialog-information-symbolic");
doctorButton.SetIconName("sherpa-stethoscope-symbolic");
doctorButton.SetTooltipText("Doctor");
doctorButton.OnClicked += (s, _) => _toolbarService.RequestNavigation("/doctor");
_headerBar.PackStart(doctorButton);
_retainedWidgets.Add(doctorButton);

_window.SetTitlebar(_headerBar);
}

private Gtk.Image CreateCopilotIcon()
{
var iconName = _themeService.IsDarkMode ? "ghcp-icon-white-24.png" : "ghcp-icon-24.png";
var iconPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Resources", iconName);
if (System.IO.File.Exists(iconPath))
return Gtk.Image.NewFromFile(iconPath);
// Fallback to a standard icon
return Gtk.Image.NewFromIconName("user-available-symbolic");
}

private void OnThemeChanged()
{
if (_copilotButton == null) return;
var newImage = CreateCopilotIcon();
_copilotButton.SetChild(newImage);
if (_copilotImage != null) _retainedWidgets.Add(_copilotImage);
_copilotImage = newImage;

// Rebuild toolbar buttons so custom PNG icons update for theme
if (_headerBar != null) RebuildToolbar();
}

private void OnToolbarChanged()
{
if (_headerBar == null) return;
Expand Down Expand Up @@ -360,17 +329,7 @@ private Gtk.Button CreateButton(ToolbarAction action)
{
var button = Gtk.Button.New();

if (CustomIconMap.TryGetValue(action.SfSymbol, out var pngFiles))
{
var fileName = _themeService.IsDarkMode ? pngFiles.White : pngFiles.Dark;
var path = System.IO.Path.Combine(AppContext.BaseDirectory, "Resources", fileName);
if (System.IO.File.Exists(path))
button.SetChild(Gtk.Image.NewFromFile(path));
else
button.SetLabel(action.Label);
button.SetTooltipText(action.ToolTip ?? action.Label);
}
else if (IconMap.TryGetValue(action.SfSymbol, out var gtkIcon))
if (IconMap.TryGetValue(action.SfSymbol, out var gtkIcon))
{
button.SetIconName(gtkIcon);
button.SetTooltipText(action.ToolTip ?? action.Label);
Expand Down
Loading
Loading