diff --git a/src/Anrufmonitor.App/App.xaml.cs b/src/Anrufmonitor.App/App.xaml.cs index a0cc363..9b1b80b 100644 --- a/src/Anrufmonitor.App/App.xaml.cs +++ b/src/Anrufmonitor.App/App.xaml.cs @@ -77,6 +77,7 @@ public partial class App : System.Windows.Application var sipMonitor = _host.Services.GetRequiredService(); var lookupService = _host.Services.GetRequiredService(); var logger = _host.Services.GetRequiredService>(); + var cache = _host.Services.GetRequiredService(); _trayIconManager = new TrayIconManager( onSyncNow: async () => @@ -84,6 +85,7 @@ public partial class App : System.Windows.Application var syncService = _host.Services.GetRequiredService(); await syncService.SyncOnceAsync(CancellationToken.None); }, + onShowHistory: () => CallHistoryWindow.ShowAsync(cache), onExit: () => System.Windows.Application.Current.Shutdown()); _trayIconManager.Show(); @@ -103,9 +105,14 @@ public partial class App : System.Windows.Application { var contact = await lookupService.ResolveAsync(args.CallerNumber, CancellationToken.None); logger.LogInformation("App: Kontakt aufgeloest zu {Name}", contact.DisplayName); + + await cache.AddCallAsync(new CallLogEntry( + args.CallId, DateTime.UtcNow, args.CallerNumber, contact.DisplayName, + contact.Company, args.CalledNumber), CancellationToken.None); + System.Windows.Application.Current.Dispatcher.Invoke(() => { - var popup = new CallPopupWindow(contact, args.CallId); + var popup = new CallPopupWindow(contact, args.CallId, args.CalledNumber); popup.Show(); }); } diff --git a/src/Anrufmonitor.App/CallHistoryWindow.xaml b/src/Anrufmonitor.App/CallHistoryWindow.xaml new file mode 100644 index 0000000..f389665 --- /dev/null +++ b/src/Anrufmonitor.App/CallHistoryWindow.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/src/Anrufmonitor.App/CallHistoryWindow.xaml.cs b/src/Anrufmonitor.App/CallHistoryWindow.xaml.cs new file mode 100644 index 0000000..e8bfc4f --- /dev/null +++ b/src/Anrufmonitor.App/CallHistoryWindow.xaml.cs @@ -0,0 +1,34 @@ +using System.Windows; +using Anrufmonitor.Contacts; + +namespace Anrufmonitor.App; + +/// Liste der letzten eingehenden Anrufe (aus der SQLite-Tabelle CallLog). Einzelinstanz. +public partial class CallHistoryWindow : Window +{ + private static CallHistoryWindow? _instance; + + private CallHistoryWindow() + { + InitializeComponent(); + Closed += (_, _) => _instance = null; + } + + public static async Task ShowAsync(ContactCache cache) + { + var entries = await cache.GetRecentCallsAsync(200, CancellationToken.None); + + _instance ??= new CallHistoryWindow(); + _instance.Grid.ItemsSource = entries.Select(e => new + { + Time = e.TimestampUtc.ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss"), + e.DisplayName, + e.Company, + e.Number, + e.CalledNumber, + }).ToList(); + + _instance.Show(); + _instance.Activate(); + } +} diff --git a/src/Anrufmonitor.App/CallPopupWindow.xaml b/src/Anrufmonitor.App/CallPopupWindow.xaml index 2907b0c..329427d 100644 --- a/src/Anrufmonitor.App/CallPopupWindow.xaml +++ b/src/Anrufmonitor.App/CallPopupWindow.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Anrufmonitor" - Width="360" Height="140" + Width="360" Height="160" WindowStyle="None" AllowsTransparency="True" Background="Transparent" @@ -16,6 +16,7 @@ + @@ -28,6 +29,8 @@ + +