Skip to content

Commit 6f45e43

Browse files
committed
Export UI debug logs on crash
1 parent a31371a commit 6f45e43

File tree

4 files changed

+119
-103
lines changed

4 files changed

+119
-103
lines changed

Signal-Windows/App.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ private async void App_Suspending(object sender, SuspendingEventArgs e)
8787
Logger.LogDebug("Suspended");
8888
}
8989

90-
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs ex)
90+
private async void OnUnhandledException(object sender, UnhandledExceptionEventArgs ex)
9191
{
9292
Exception e = ex.Exception;
93+
ex.Handled = true;
9394
Logger.LogError("UnhandledException {0} occured ({1}):\n{2}", e.GetType(), e.Message, e.StackTrace);
95+
await AdvancedSettingsPageViewModel.EportUIDebugLog();
96+
Current.Exit();
9497
}
9598

9699
protected override async void OnActivated(IActivatedEventArgs args)
Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using GalaSoft.MvvmLight;
7-
using libsignalservice;
8-
using Microsoft.Extensions.Logging;
9-
using Signal_Windows.Storage;
10-
using Windows.Storage;
11-
using Windows.Storage.Pickers;
12-
13-
namespace Signal_Windows.ViewModels
14-
{
15-
public class AdvancedSettingsPageViewModel : ViewModelBase
16-
{
17-
private readonly ILogger Logger = LibsignalLogging.CreateLogger<AdvancedSettingsPageViewModel>();
18-
19-
public async Task ExportUIDebugLog()
20-
{
21-
FileSavePicker savePicker = new FileSavePicker();
22-
savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
23-
savePicker.SuggestedFileName = "Signal-Windows.ui.log";
24-
StorageFile file = await savePicker.PickSaveFileAsync();
25-
if (file != null)
26-
{
27-
await Task.Run(() =>
28-
{
29-
SignalFileLoggerProvider.ExportUILog(file);
30-
});
31-
}
32-
else
33-
{
34-
Logger.LogTrace("No file was selected");
35-
}
36-
}
37-
}
38-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using GalaSoft.MvvmLight;
7+
using libsignalservice;
8+
using Microsoft.Extensions.Logging;
9+
using Signal_Windows.Storage;
10+
using Windows.Storage;
11+
using Windows.Storage.Pickers;
12+
13+
namespace Signal_Windows.ViewModels
14+
{
15+
public class AdvancedSettingsPageViewModel : ViewModelBase
16+
{
17+
private static readonly ILogger Logger = LibsignalLogging.CreateLogger<AdvancedSettingsPageViewModel>();
18+
19+
public async Task _ExportUIDebugLog()
20+
{
21+
await EportUIDebugLog();
22+
}
23+
24+
public static async Task EportUIDebugLog()
25+
{
26+
FileSavePicker savePicker = new FileSavePicker();
27+
savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
28+
savePicker.SuggestedFileName = "Signal-Windows.ui.log";
29+
StorageFile file = await savePicker.PickSaveFileAsync();
30+
if (file != null)
31+
{
32+
await Task.Run(() =>
33+
{
34+
SignalFileLoggerProvider.ExportUILog(file);
35+
});
36+
}
37+
else
38+
{
39+
Logger.LogTrace("No file was selected");
40+
}
41+
}
42+
}
43+
}

Signal-Windows/Views/AdvancedSettingsPage.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<TextBlock Text="Advanced" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource TitleTextBlockStyle}"/>
1818
<StackPanel Grid.Row="1" Margin="32,0,0,0">
1919
<Button x:Name="ExportDebugLogButton" Content="Export debug log" Click="ExportDebugLogButton_Click"/>
20-
<Button x:Name="SyncButton" Content="Request contact and group sync" Margin="0,8,0,0" Click="SyncButton_Click"/>
20+
<Button x:Name="SyncButton" Content="Request contact and group sync" Margin="0,8,0,0" Click="SyncButton_Click"/>
21+
<Button x:Name="TestCrashButton" Content="Intentionally crash the app to test its debug log export" Click="TestCrashButton_Click"/>
2122
</StackPanel>
2223
</Grid>
2324
</Page>
Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,70 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Runtime.InteropServices.WindowsRuntime;
6-
using Signal_Windows.ViewModels;
7-
using Windows.Foundation;
8-
using Windows.Foundation.Collections;
9-
using Windows.UI.Core;
10-
using Windows.UI.Xaml;
11-
using Windows.UI.Xaml.Controls;
12-
using Windows.UI.Xaml.Controls.Primitives;
13-
using Windows.UI.Xaml.Data;
14-
using Windows.UI.Xaml.Input;
15-
using Windows.UI.Xaml.Media;
16-
using Windows.UI.Xaml.Navigation;
17-
18-
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
19-
20-
namespace Signal_Windows.Views
21-
{
22-
/// <summary>
23-
/// An empty page that can be used on its own or navigated to within a Frame.
24-
/// </summary>
25-
public sealed partial class AdvancedSettingsPage : Page
26-
{
27-
public AdvancedSettingsPage()
28-
{
29-
this.InitializeComponent();
30-
}
31-
32-
public AdvancedSettingsPageViewModel Vm
33-
{
34-
get { return (AdvancedSettingsPageViewModel)DataContext; }
35-
}
36-
37-
protected override void OnNavigatedTo(NavigationEventArgs e)
38-
{
39-
Utils.EnableBackButton(BackButton_Click);
40-
}
41-
42-
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
43-
{
44-
Utils.DisableBackButton(BackButton_Click);
45-
}
46-
47-
private void BackButton_Click(object sender, BackRequestedEventArgs e)
48-
{
49-
Frame.GoBack();
50-
e.Handled = true;
51-
}
52-
53-
private async void ExportDebugLogButton_Click(object sender, RoutedEventArgs e)
54-
{
55-
await Vm.ExportUIDebugLog();
56-
}
57-
58-
private void SyncButton_Click(object sender, RoutedEventArgs e)
59-
{
60-
App.Handle.RequestSync();
61-
}
62-
}
63-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Signal_Windows.ViewModels;
7+
using Windows.Foundation;
8+
using Windows.Foundation.Collections;
9+
using Windows.UI.Core;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
19+
20+
namespace Signal_Windows.Views
21+
{
22+
/// <summary>
23+
/// An empty page that can be used on its own or navigated to within a Frame.
24+
/// </summary>
25+
public sealed partial class AdvancedSettingsPage : Page
26+
{
27+
public AdvancedSettingsPage()
28+
{
29+
this.InitializeComponent();
30+
}
31+
32+
public AdvancedSettingsPageViewModel Vm
33+
{
34+
get { return (AdvancedSettingsPageViewModel)DataContext; }
35+
}
36+
37+
protected override void OnNavigatedTo(NavigationEventArgs e)
38+
{
39+
Utils.EnableBackButton(BackButton_Click);
40+
}
41+
42+
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
43+
{
44+
Utils.DisableBackButton(BackButton_Click);
45+
}
46+
47+
private void BackButton_Click(object sender, BackRequestedEventArgs e)
48+
{
49+
Frame.GoBack();
50+
e.Handled = true;
51+
}
52+
53+
private async void ExportDebugLogButton_Click(object sender, RoutedEventArgs e)
54+
{
55+
await Vm._ExportUIDebugLog();
56+
}
57+
58+
private void SyncButton_Click(object sender, RoutedEventArgs e)
59+
{
60+
App.Handle.RequestSync();
61+
}
62+
63+
private void TestCrashButton_Click(object sender, RoutedEventArgs e)
64+
{
65+
int i = 1;
66+
i--;
67+
i = 5 / i;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)