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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ Alle nennenswerten Änderungen an SyncDrive. Format nach [Keep a Changelog](http
Korrekturen heben PATCH. Die Version steht an einer Stelle (`04-umsetzung/Directory.Build.props`); ein Test prüft, dass sie mit dem obersten
Eintrag hier übereinstimmt. Jede Version bekommt ein Git-Tag `vX.Y.Z`. Die Versionen 0.1.0 bis 0.11.0 wurden nachträglich vergeben.

## [0.41.0] – 2026-10-23 – Mac: Klick aufs Symbol öffnet das Panel wie unter Windows

### Geändert
- **Mac: Ein Klick auf das Menüleisten-Symbol öffnet sofort das Panel** (Status, Zuletzt geändert, Benachrichtigungen, Schnellzugriffe)
wie unter Windows; die Menüliste entfällt. Avalonia meldet den Klick unter macOS nicht, deshalb legt SyncDrive das Symbol dort selbst
über AppKit an (`NSStatusItem`, Klick über ein kleines Objective-C-Ziel). Pause, Fehlersuche und Beenden stehen im „⋯“ des Panels.
Ein zweiter Klick schließt das offene Panel.
- „Zuletzt geändert“ zeigt nur noch Änderungen; bewusst Ausgelassenes (z. B. `.DS_Store`, Office-Sperrdateien) steht weiter im Protokoll.
- Mac-Build: Rauchtest auch für die Oberfläche (Menüleisten-Symbol anlegen, laufen lassen).

### Bestätigt
- Auf einem echten Mac (macOS 27, M1) gemessen: Mit 0.40.3 fragt der Daemon den Schlüsselbund nur noch einmal beim Start ab (vorher
326–568 Abfragen je Minute) und baut etwa eine Verbindung je Minute auf.

## [0.40.3] – 2026-10-23 – Kein Dauer-Nachladen mehr (Schlüsselbund, Server)

### Behoben
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Einzige Quelle der Produktversion (Semantic Versioning, siehe ../CHANGELOG.md). Vor 1.0.0 darf sich das Protokoll noch ändern.
Jeder Meilenstein hebt MINOR, reine Korrekturen PATCH; dazu ein Eintrag im CHANGELOG und ein Git-Tag vX.Y.Z. -->
<Version>0.40.3</Version>
<Version>0.41.0</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
Expand Down
7 changes: 7 additions & 0 deletions installer/build-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ SYNCDRIVE_CLIENT_HOME="$smoke" "$app/Contents/MacOS/syncdrive-daemon" & daemon=$
sleep 5
alive "$daemon" || { echo "Daemon startet nach einem Abbruch nicht wieder:" >&2; cat "$smoke/logs/daemon.log" >&2 || true; exit 1; }
kill "$daemon"

# Rauchtest der Oberfläche: Menüleisten-Symbol über AppKit anlegen (MacStatusItem) und laufen lassen; stürzt sie ab, scheitert der Build
SYNCDRIVE_CLIENT_HOME="$smoke" "$app/Contents/MacOS/syncdrive" --background & ui=$!
sleep 8
alive "$ui" || { echo "Oberfläche startet nicht" >&2; exit 1; }
kill "$ui"
pkill -f "$app/Contents/MacOS/syncdrive-daemon" || true
rm -rf "$smoke"

# 2. Programmsymbol aus dem Grundzeichen (dieselbe Zeichnung wie unter Windows)
Expand Down
73 changes: 42 additions & 31 deletions src/SyncDrive.Client.Tray/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,44 +112,55 @@ private static async Task OpenStartAsync(ShellViewModel shell, WindowManager win
});
}

/// <summary>
/// Windows: Symbol im Infobereich, Klick öffnet das Panel, Rechtsklick das Menü. macOS: Symbol in der Menüleiste direkt über AppKit
/// (<see cref="MacStatusItem"/>), jeder Klick öffnet das Panel; Pause, Fehlersuche und Beenden stehen dort im „⋯“ des Panels.
/// </summary>
private void SetUpTray(ShellViewModel shell, WindowManager windows, Texts texts)
{
var pause = new NativeMenuItem(shell.PauseMenuText) { Command = shell.TogglePauseCommand };
var settings = new NativeMenuItem(texts.MenuSettings) { Command = shell.OpenSettingsCommand };
var about = new NativeMenuItem(texts.MenuAbout) { Command = shell.AboutCommand };
var troubleshoot = new NativeMenuItem(texts.MenuTroubleshoot) { Command = shell.TroubleshootCommand };
var exit = new NativeMenuItem(texts.MenuExit) { Command = shell.ExitCommand };
var menu = new NativeMenu { pause, settings, new NativeMenuItemSeparator(), about, troubleshoot, new NativeMenuItemSeparator(), exit };
var openApp = new NativeMenuItem(texts.MenuOpenApp) { Command = new CommunityToolkit.Mvvm.Input.RelayCommand(windows.TogglePanel) };
var openFolder = new NativeMenuItem(texts.MenuOpenFolder) { Command = shell.Panel.OpenSyncFolderCommand };
var tasks = new NativeMenuItem(texts.NavSyncTasks) { Command = shell.OpenMainWindowCommand };
var spin = 0;
Action<int> showIcon;
Action refreshTexts;
if (OperatingSystem.IsMacOS())
{
// macOS meldet am Menüleisten-Symbol keinen Klick, es zeigt nur ein Menü (ohne Menü geschah beim Klick nichts): dort führt
// das Menü oben zum Panel, zum Sync-Ordner und zu den Aufgaben, darunter wie unter Windows.
menu.Items.Insert(0, openApp);
menu.Items.Insert(1, openFolder);
menu.Items.Insert(2, tasks);
menu.Items.Insert(3, new NativeMenuItemSeparator());
(showIcon, refreshTexts) = MacTray(shell, windows);
}
else
{
var pause = new NativeMenuItem(shell.PauseMenuText) { Command = shell.TogglePauseCommand };
var settings = new NativeMenuItem(texts.MenuSettings) { Command = shell.OpenSettingsCommand };
var about = new NativeMenuItem(texts.MenuAbout) { Command = shell.AboutCommand };
var troubleshoot = new NativeMenuItem(texts.MenuTroubleshoot) { Command = shell.TroubleshootCommand };
var exit = new NativeMenuItem(texts.MenuExit) { Command = shell.ExitCommand };
var menu = new NativeMenu { pause, settings, new NativeMenuItemSeparator(), about, troubleshoot, new NativeMenuItemSeparator(), exit };
var tray = new TrayIcon { Menu = menu, ToolTipText = shell.Tooltip, IsVisible = true };
tray.Clicked += (_, _) => windows.TogglePanel();
TrayIcon.SetIcons(this, [tray]);
showIcon = s => tray.Icon = TrayArt.Icon(shell, s);
refreshTexts = () =>
{
tray.ToolTipText = shell.Tooltip;
pause.Header = shell.PauseMenuText;
settings.Header = shell.Texts.MenuSettings; // Sprache kann gewechselt haben
about.Header = shell.Texts.MenuAbout;
troubleshoot.Header = shell.Texts.MenuTroubleshoot;
exit.Header = shell.Texts.MenuExit;
};
}

var tray = new TrayIcon { Menu = menu, ToolTipText = shell.Tooltip, IsVisible = true };
tray.Clicked += (_, _) => windows.TogglePanel();
MacOSProperties.SetIsTemplateIcon(tray, true); // nur macOS: Vorlagenbild, hell oder dunkel wie die Menüleiste
TrayIcon.SetIcons(this, [tray]);
var spin = 0;
var spinner = new DispatcherTimer(TimeSpan.FromMilliseconds(110), DispatcherPriority.Background, (_, _) =>
{
spin = (spin + 30) % 360; // zwölf Bilder je Umdrehung
tray.Icon = TrayArt.Icon(shell, spin);
showIcon(spin);
});
void UpdateIcon()
{
tray.Icon = TrayArt.Icon(shell, spin);
showIcon(spin);
spinner.IsEnabled = shell.TrayState == TrayState.Syncing; // kreisende Pfeile, solange abgeglichen wird
}

UpdateIcon();
refreshTexts();
shell.PropertyChanged += (_, e) =>
{
if (e.PropertyName is nameof(ShellViewModel.Settings))
Expand All @@ -161,19 +172,19 @@ void UpdateIcon()
or nameof(ShellViewModel.IsConnected))
{
UpdateIcon();
tray.ToolTipText = shell.Tooltip;
pause.Header = shell.PauseMenuText;
settings.Header = shell.Texts.MenuSettings; // Sprache kann gewechselt haben
about.Header = shell.Texts.MenuAbout;
troubleshoot.Header = shell.Texts.MenuTroubleshoot;
exit.Header = shell.Texts.MenuExit;
openApp.Header = shell.Texts.MenuOpenApp;
openFolder.Header = shell.Texts.MenuOpenFolder;
tasks.Header = shell.Texts.NavSyncTasks;
refreshTexts();
}
};
}

[System.Runtime.Versioning.SupportedOSPlatform("macos")]
private static (Action<int> ShowIcon, Action RefreshTexts) MacTray(ShellViewModel shell, WindowManager windows)
{
var item = new MacStatusItem();
item.Clicked += () => Dispatcher.UIThread.Post(windows.TogglePanel);
return (s => item.SetImage(TrayArt.MacImage(shell, s)), () => item.SetToolTip(shell.Tooltip));
}

/// <summary>Startet <c>syncdrive-daemon</c> aus dem Programmordner (als .exe oder, in der Entwicklung, per <c>dotnet</c>).</summary>
private static void LaunchDaemon()
{
Expand Down
143 changes: 143 additions & 0 deletions src/SyncDrive.Client.Tray/MacStatusItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace SyncDrive.Client.Tray;

/// <summary>
/// Menüleisten-Symbol unter macOS direkt über AppKit (<c>NSStatusItem</c>). Avalonias TrayIcon meldet dort keinen Klick, ein Menü ginge
/// nur als Liste; SyncDrive öffnet aber wie unter Windows beim Klick das Panel. Ein kleines Objective-C-Ziel (zur Laufzeit angelegte
/// Klasse) leitet die Aktion des Knopfs an <see cref="Clicked"/> weiter. Muss im Hauptthread angelegt und benutzt werden (AppKit).
/// </summary>
[SupportedOSPlatform("macos")]
internal sealed class MacStatusItem
{
private const string ObjC = "/usr/lib/libobjc.A.dylib";
private const double VariableLength = -1; // NSVariableStatusItemLength
private const ulong LeftAndRightMouseUp = (1UL << 2) | (1UL << 4); // NSEventMaskLeftMouseUp | NSEventMaskRightMouseUp

private static MacStatusItem? _current;
private readonly IntPtr _item;
private readonly IntPtr _button;

public MacStatusItem()
{
var bar = Send(Class("NSStatusBar"), "systemStatusBar");
_item = Send(SendDouble(bar, Selector("statusItemWithLength:"), VariableLength), "retain");
_button = Send(_item, "button");
var target = Send(Send(TargetClass(), "alloc"), "init");
SendPtr(_button, Selector("setTarget:"), target);
SendPtr(_button, Selector("setAction:"), Selector("clicked:"));
SendULong(_button, Selector("sendActionOn:"), LeftAndRightMouseUp);
_current = this;
}

/// <summary>Klick (links oder rechts) auf das Symbol.</summary>
public event Action? Clicked;

/// <summary>Bild als PNG; als Vorlage (template) färbt macOS es passend zur Menüleiste; 18 Punkt hoch.</summary>
public void SetImage(byte[] png)
{
var data = DataFrom(png);
var image = SendPtr(Send(Class("NSImage"), "alloc"), Selector("initWithData:"), data);
SendBool(image, Selector("setTemplate:"), true);
SendSize(image, Selector("setSize:"), new CGSize(18, 18));
SendPtr(_button, Selector("setImage:"), image);
Send(image, "release");
}

public void SetToolTip(string text) => SendPtr(_button, Selector("setToolTip:"), NsString(text));

private static IntPtr TargetClass()
{
var existing = Class("SyncDriveStatusTarget");
if (existing != IntPtr.Zero)
{
return existing;
}

var type = objc_allocateClassPair(Class("NSObject"), Utf8("SyncDriveStatusTarget"), 0);
unsafe
{
delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> handler = &OnClicked;
class_addMethod(type, Selector("clicked:"), (IntPtr)handler, Utf8("v@:@"));
}

objc_registerClassPair(type);
return type;
}

[UnmanagedCallersOnly]
private static void OnClicked(IntPtr self, IntPtr selector, IntPtr sender) => _current?.Clicked?.Invoke();

private static IntPtr DataFrom(byte[] bytes)
{
unsafe
{
fixed (byte* p = bytes)
{
return SendPtrULong(Class("NSData"), Selector("dataWithBytes:length:"), (IntPtr)p, (ulong)bytes.Length);
}
}
}

private static IntPtr NsString(string text)
{
var utf8 = System.Text.Encoding.UTF8.GetBytes(text + "\0");
unsafe
{
fixed (byte* p = utf8)
{
return SendPtr(Class("NSString"), Selector("stringWithUTF8String:"), (IntPtr)p);
}
}
}

private static IntPtr Class(string name) => objc_getClass(Utf8(name));

private static IntPtr Selector(string name) => sel_registerName(Utf8(name));

/// <summary>C-Zeichenkette, wie die Objective-C-Laufzeit sie erwartet: UTF-8 mit abschließender Null.</summary>
private static byte[] Utf8(string text) => System.Text.Encoding.UTF8.GetBytes(text + "\0");

private static IntPtr Send(IntPtr receiver, string selector) => objc_msgSend(receiver, Selector(selector));

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern IntPtr objc_msgSend(IntPtr receiver, IntPtr selector);

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern IntPtr SendPtr(IntPtr receiver, IntPtr selector, IntPtr argument);

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern IntPtr SendPtrULong(IntPtr receiver, IntPtr selector, IntPtr argument, ulong length);

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern IntPtr SendDouble(IntPtr receiver, IntPtr selector, double argument);

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern void SendULong(IntPtr receiver, IntPtr selector, ulong argument);

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern void SendBool(IntPtr receiver, IntPtr selector, [MarshalAs(UnmanagedType.I1)] bool argument);

[DllImport(ObjC, EntryPoint = "objc_msgSend")]
private static extern void SendSize(IntPtr receiver, IntPtr selector, CGSize argument);

[DllImport(ObjC)]
private static extern IntPtr objc_getClass(byte[] name);

[DllImport(ObjC)]
private static extern IntPtr sel_registerName(byte[] name);

[DllImport(ObjC)]
private static extern IntPtr objc_allocateClassPair(IntPtr superclass, byte[] name, nuint extraBytes);

[DllImport(ObjC)]
private static extern void objc_registerClassPair(IntPtr type);

[DllImport(ObjC)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool class_addMethod(IntPtr type, IntPtr selector, IntPtr implementation, byte[] types);

[StructLayout(LayoutKind.Sequential)]
private readonly record struct CGSize(double Width, double Height);
}
1 change: 1 addition & 0 deletions src/SyncDrive.Client.Tray/SyncDrive.Client.Tray.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>syncdrive</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <!-- macOS: Objective-C-Laufzeit (MacStatusItem) -->
<RootNamespace>SyncDrive.Client.Tray</RootNamespace>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
22 changes: 18 additions & 4 deletions src/SyncDrive.Client.Tray/TrayArt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal static class TrayArt
/// <summary>Menüleiste: 18 Punkt hoch, auf Retina-Bildschirmen (alle M-Macs) doppelt.</summary>
private const int MenuBarSize = 36;
private static readonly Dictionary<(TrayState, bool, bool, int, bool, int), WindowIcon> Cache = [];
private static readonly Dictionary<(TrayState, bool, int), byte[]> MacCache = [];

public static WindowIcon Icon(ShellViewModel shell, int spin)
{
Expand All @@ -26,10 +27,7 @@ public static WindowIcon Icon(ShellViewModel shell, int spin)
if (!Cache.TryGetValue(key, out var icon))
{
using var stream = new MemoryStream();
var bitmap = OperatingSystem.IsMacOS()
? Badges.TemplateTrayBitmap(key.state, key.Item2, MenuBarSize, key.Item6) // macOS färbt das Vorlagenbild selbst
: Badges.TrayBitmap(key.state, key.Item2, key.Item3, key.Item4, key.Item5, key.Item6);
bitmap.Save(stream);
Badges.TrayBitmap(key.state, key.Item2, key.Item3, key.Item4, key.Item5, key.Item6).Save(stream);
stream.Position = 0;
icon = new WindowIcon(stream);
Cache[key] = icon;
Expand All @@ -38,6 +36,22 @@ public static WindowIcon Icon(ShellViewModel shell, int spin)
return icon;
}

/// <summary>macOS: Vorlagenbild der Menüleiste als PNG für <see cref="MacStatusItem"/>; je Zustand einmal gezeichnet.</summary>
public static byte[] MacImage(ShellViewModel shell, int spin)
{
var state = shell.TrayState;
var key = (state, shell.HasNotifications, state == TrayState.Syncing ? spin : 0);
if (!MacCache.TryGetValue(key, out var png))
{
using var stream = new MemoryStream();
Badges.TemplateTrayBitmap(state, shell.HasNotifications, MenuBarSize, key.Item3).Save(stream);
png = stream.ToArray();
MacCache[key] = png;
}

return png;
}

/// <summary>Kantenlänge eines kleinen Symbols bei der aktuellen Skalierung (16 bei 100 %, 24 bei 150 %, 32 bei 200 %).</summary>
private static int Size() => OperatingSystem.IsWindows() && GetSystemMetrics(SmallIconWidth) is >= 16 and <= 256 and var size ? size : 32;

Expand Down
9 changes: 8 additions & 1 deletion src/SyncDrive.Client.Tray/Views/PanelWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ public partial class PanelWindow : Window
public PanelWindow()
{
InitializeComponent();
Deactivated += (_, _) => Hide();
Deactivated += (_, _) =>
{
Hide();
HiddenAt = DateTimeOffset.UtcNow;
};
}

/// <summary>Wann das Panel zuletzt durch Fokusverlust zuging (ein Klick aufs Symbol soll es dann nicht sofort neu öffnen).</summary>
public DateTimeOffset HiddenAt { get; private set; } = DateTimeOffset.MinValue;

public void ShowNearTray(PanelViewModel viewModel)
{
DataContext = viewModel;
Expand Down
3 changes: 2 additions & 1 deletion src/SyncDrive.Client.Tray/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public void TogglePanel()
{
_panel.Hide();
}
else
else if (DateTimeOffset.UtcNow - _panel.HiddenAt > TimeSpan.FromMilliseconds(400))
{
// Der Klick aufs Symbol nimmt dem offenen Panel zuerst den Fokus (es schließt sich); er soll es nicht gleich wieder öffnen
_panel.ShowNearTray(_shell.Panel);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/SyncDrive.Client.Ui/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ public async Task RefreshAsync(CancellationToken ct)
var activity = await client.GetRecentActivityAsync(RecentCount, ct);
var notifications = await client.GetNotificationsAsync(ct);
var now = _clock.GetUtcNow();
var items = activity.Select(a => ToItem(a, now)).ToList();
// „Zuletzt geändert“ zeigt Änderungen; bewusst Ausgelassenes (z. B. .DS_Store, Thumbs.db) steht nur im Protokoll
var items = activity.Where(a => a.Entry.Result != App.Ports.ActivityResult.Unsynced).Select(a => ToItem(a, now)).ToList();
var notes = notifications.Select(n => NotificationItemViewModel.From(n, Texts, now)).ToList();
AnnounceNews(activity, notifications);
_ui.Post(() =>
Expand Down
Loading
Loading