Add debug notification for sync callbacks sync
authorThomas
Tue, 30 Apr 2019 12:42:30 +0200
branchsync
changeset 2623d0c935a45a22
parent 2622 ed338b3729ab
child 2624 c28e59231408
Add debug notification for sync callbacks
AdapterCallbacks.cs
UI/Notification.xaml
UI/Notification.xaml.cs
pEpForOutlook.csproj
     1.1 --- a/AdapterCallbacks.cs	Tue Apr 30 12:39:22 2019 +0200
     1.2 +++ b/AdapterCallbacks.cs	Tue Apr 30 12:42:30 2019 +0200
     1.3 @@ -25,7 +25,11 @@
     1.4                                      ref pEpIdentity partner,
     1.5                                      SyncHandshakeSignal signal)
     1.6          {
     1.7 -            Log.Verbose("NotifyHandshake: Started with signal " + signal.ToString());
     1.8 +            Log.Verbose("NotifyHandshake: Received signal " + signal.ToString());
     1.9 +
    1.10 +#if DEBUG
    1.11 +            this.ShowNotification(signal.ToString(), "NotifyHandshake called with signal " + signal.ToString());
    1.12 +#endif
    1.13  
    1.14              /* Close handshake dialog if it was still open and the signal type
    1.15               * is not "undefined", in which case the status quo should be preserved.
    1.16 @@ -161,6 +165,20 @@
    1.17          #region Helper methods
    1.18  
    1.19          /// <summary>
    1.20 +        /// Shows a notification with the given message.
    1.21 +        /// </summary>
    1.22 +        /// <param name="title">The title of the notification.</param>
    1.23 +        /// <param name="text">The content of the notification.</param>
    1.24 +        public void ShowNotification(string title, string text)
    1.25 +        {
    1.26 +            // Create STA thread for WPF window
    1.27 +            AdapterCallbacks.StartSTATask<bool?>(() =>
    1.28 +            {
    1.29 +                return new Notification(title, text).ShowDialog();
    1.30 +            });
    1.31 +        }
    1.32 +
    1.33 +        /// <summary>
    1.34          /// Wrapper method for the asynchronous call to show the handshake dialog in a separate STA thread.
    1.35          /// </summary>
    1.36          /// <param name="own">The personal identity for the handshake.</param>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/UI/Notification.xaml	Tue Apr 30 12:42:30 2019 +0200
     2.3 @@ -0,0 +1,46 @@
     2.4 +´╗┐<Window x:Class="pEp.UI.Notification"
     2.5 +            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     2.6 +            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     2.7 +            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     2.8 +            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     2.9 +            xmlns:local="clr-namespace:pEp.UI"
    2.10 +            mc:Ignorable="d" 
    2.11 +            AllowsTransparency="True"
    2.12 +            Background="Transparent"
    2.13 +            WindowStyle="None"
    2.14 +            ShowInTaskbar="False"
    2.15 +            Height="100" Width="300">
    2.16 +    <Grid RenderTransformOrigin="0,1" >
    2.17 +
    2.18 +        <!-- Notification area -->
    2.19 +        <Border BorderThickness="1" Background="Black" BorderBrush="Black">
    2.20 +            <StackPanel Margin="10">
    2.21 +                <TextBlock Foreground="White" FontWeight="DemiBold" Text="{Binding TitleText}" Margin="5,0,5,5"/>
    2.22 +                <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding NotificationText}" Margin="5,5,0,5"/>
    2.23 +            </StackPanel>
    2.24 +        </Border>
    2.25 +
    2.26 +        <!-- Animation -->
    2.27 +        <Grid.Triggers>
    2.28 +            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
    2.29 +                <BeginStoryboard>
    2.30 +                    <Storyboard Completed="Storyboard_Completed">
    2.31 +                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
    2.32 +                            <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
    2.33 +                            <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
    2.34 +                        </DoubleAnimationUsingKeyFrames>
    2.35 +                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
    2.36 +                            <SplineDoubleKeyFrame KeyTime="0:0:4" Value="1"/>
    2.37 +                            <SplineDoubleKeyFrame KeyTime="0:0:6" Value="0"/>
    2.38 +                        </DoubleAnimationUsingKeyFrames>
    2.39 +                    </Storyboard>
    2.40 +                </BeginStoryboard>
    2.41 +            </EventTrigger>
    2.42 +        </Grid.Triggers>
    2.43 +
    2.44 +        <Grid.RenderTransform>
    2.45 +            <ScaleTransform ScaleX="1" />
    2.46 +        </Grid.RenderTransform>
    2.47 +
    2.48 +    </Grid>
    2.49 +</Window>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/UI/Notification.xaml.cs	Tue Apr 30 12:42:30 2019 +0200
     3.3 @@ -0,0 +1,54 @@
     3.4 +´╗┐using System;
     3.5 +using System.Collections.Generic;
     3.6 +using System.Linq;
     3.7 +using System.Text;
     3.8 +using System.Threading.Tasks;
     3.9 +using System.Windows;
    3.10 +using System.Windows.Controls;
    3.11 +using System.Windows.Data;
    3.12 +using System.Windows.Documents;
    3.13 +using System.Windows.Input;
    3.14 +using System.Windows.Media;
    3.15 +using System.Windows.Media.Imaging;
    3.16 +using System.Windows.Navigation;
    3.17 +using System.Windows.Shapes;
    3.18 +using System.Windows.Threading;
    3.19 +
    3.20 +namespace pEp.UI
    3.21 +{
    3.22 +    /// <summary>
    3.23 +    /// Interaction logic for Notification.xaml
    3.24 +    /// </summary>
    3.25 +    public partial class Notification : Window
    3.26 +    {
    3.27 +        public string TitleText { get; private set; }
    3.28 +        public string NotificationText { get; private set; }
    3.29 +
    3.30 +        public Notification()
    3.31 +        {
    3.32 +            InitializeComponent();
    3.33 +            this.DataContext = this;
    3.34 +
    3.35 +            Dispatcher.BeginInvoke(new Action(() =>
    3.36 +            {
    3.37 +                var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
    3.38 +                var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
    3.39 +                var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom));
    3.40 +
    3.41 +                this.Left = corner.X - this.ActualWidth - 10;
    3.42 +                this.Top = corner.Y - this.ActualHeight - 10;
    3.43 +            }));
    3.44 +        }
    3.45 +
    3.46 +        public Notification(string title, string text) : this()
    3.47 +        {
    3.48 +            this.TitleText = title;
    3.49 +            this.NotificationText = text;
    3.50 +        }
    3.51 +
    3.52 +        private void Storyboard_Completed(object sender, EventArgs e)
    3.53 +        {            
    3.54 +            this.Close();
    3.55 +        }
    3.56 +    }
    3.57 +}
     4.1 --- a/pEpForOutlook.csproj	Tue Apr 30 12:39:22 2019 +0200
     4.2 +++ b/pEpForOutlook.csproj	Tue Apr 30 12:42:30 2019 +0200
     4.3 @@ -446,6 +446,9 @@
     4.4      <Compile Include="UI\KeySyncWizard.xaml.cs">
     4.5        <DependentUpon>KeySyncWizard.xaml</DependentUpon>
     4.6      </Compile>
     4.7 +    <Compile Include="UI\Notification.xaml.cs">
     4.8 +      <DependentUpon>Notification.xaml</DependentUpon>
     4.9 +    </Compile>
    4.10      <Compile Include="UI\RibbonCustomizations.cs" />
    4.11      <Compile Include="UI\SelectionItem.cs" />
    4.12      <Compile Include="Interfaces.cs" />
    4.13 @@ -616,6 +619,10 @@
    4.14      <Resource Include="Resources\ImagePrivacyStatusYellow.png" />
    4.15    </ItemGroup>
    4.16    <ItemGroup>
    4.17 +    <Page Include="UI\Notification.xaml">
    4.18 +      <SubType>Designer</SubType>
    4.19 +      <Generator>MSBuild:Compile</Generator>
    4.20 +    </Page>
    4.21      <Page Include="UI\UserControlPrivacyStatus.xaml">
    4.22        <SubType>Designer</SubType>
    4.23        <Generator>MSBuild:Compile</Generator>