Skip to content

Commit de49a8d

Browse files
committed
add global settings page, support debug log export
1 parent cd65c09 commit de49a8d

File tree

10 files changed

+203
-16
lines changed

10 files changed

+203
-16
lines changed

Signal-Windows.Lib/SignalLogging.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,33 @@ public static void ForceAddUILog(string msg)
169169
}
170170
}
171171
}
172+
173+
public static void ExportUILog(StorageFile file)
174+
{
175+
lock(Lock)
176+
{
177+
var oldLog = File.OpenRead(ApplicationData.Current.LocalCacheFolder.Path + @"\Signal-Windows.ui.log.old");
178+
var newLog = File.OpenRead(ApplicationData.Current.LocalCacheFolder.Path + @"\Signal-Windows.ui.log");
179+
FileIO.WriteTextAsync(file, "").AsTask().Wait();
180+
CachedFileManager.DeferUpdates(file);
181+
var writer = file.OpenStreamForWriteAsync().Result;
182+
MoveFileContent(oldLog, writer);
183+
MoveFileContent(newLog, writer);
184+
Windows.Storage.Provider.FileUpdateStatus status = CachedFileManager.CompleteUpdatesAsync(file).AsTask().Result;
185+
oldLog.Dispose();
186+
newLog.Dispose();
187+
}
188+
}
189+
190+
private static void MoveFileContent(Stream source, Stream destination)
191+
{
192+
byte[] buffer = new byte[1024];
193+
int read;
194+
while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
195+
{
196+
destination.Write(buffer, 0, read);
197+
}
198+
destination.Flush();
199+
}
172200
}
173201
}

Signal-Windows/Controls/ConversationListElement.xaml.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ private void ThreadListItem_DataContextChanged(FrameworkElement sender, DataCont
120120

121121
public void UpdateConversationDisplay()
122122
{
123-
ConversationDisplayName.Text = Model.ThreadDisplayName;
124-
UnreadCount = Model.UnreadCount;
125-
LastMessage = Model.LastMessage?.Content.Content;
126-
Initials = Utils.GetInitials(Model.ThreadDisplayName);
127-
FillBrush = Model is SignalContact contact ?
128-
contact.Color != null ? Utils.GetBrushFromColor((contact.Color)) :
129-
Utils.GetBrushFromColor(Utils.CalculateDefaultColor(Model.ThreadDisplayName)) : Utils.Blue;
130-
LastMessageTimestamp = Utils.GetTimestamp(Model.LastActiveTimestamp);
123+
if (Model != null)
124+
{
125+
ConversationDisplayName.Text = Model.ThreadDisplayName;
126+
UnreadCount = Model.UnreadCount;
127+
LastMessage = Model.LastMessage?.Content.Content;
128+
Initials = Utils.GetInitials(Model.ThreadDisplayName);
129+
FillBrush = Model is SignalContact contact ?
130+
contact.Color != null ? Utils.GetBrushFromColor((contact.Color)) :
131+
Utils.GetBrushFromColor(Utils.CalculateDefaultColor(Model.ThreadDisplayName)) : Utils.Blue;
132+
LastMessageTimestamp = Utils.GetTimestamp(Model.LastActiveTimestamp);
133+
}
131134
}
132135
}
133136
}

Signal-Windows/Signal-Windows.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<Compile Include="ViewModels\AddContactPageViewModel.cs" />
174174
<Compile Include="ViewModels\ConversationSettingsPageViewModel.cs" />
175175
<Compile Include="ViewModels\FinishRegistrationPageViewModel.cs" />
176+
<Compile Include="ViewModels\GlobalSettingsPageViewModel.cs" />
176177
<Compile Include="ViewModels\LinkPageViewModel.cs" />
177178
<Compile Include="ViewModels\MainPageViewModel.cs" />
178179
<Compile Include="ViewModels\RegisterFinalizationPageViewModel.cs" />
@@ -188,6 +189,9 @@
188189
<Compile Include="Views\FinishRegistrationPage.xaml.cs">
189190
<DependentUpon>FinishRegistrationPage.xaml</DependentUpon>
190191
</Compile>
192+
<Compile Include="Views\GlobalSettingsPage.xaml.cs">
193+
<DependentUpon>GlobalSettingsPage.xaml</DependentUpon>
194+
</Compile>
191195
<Compile Include="Views\LinkPage.xaml.cs">
192196
<DependentUpon>LinkPage.xaml</DependentUpon>
193197
</Compile>
@@ -269,6 +273,10 @@
269273
<SubType>Designer</SubType>
270274
<Generator>MSBuild:Compile</Generator>
271275
</Page>
276+
<Page Include="Views\GlobalSettingsPage.xaml">
277+
<SubType>Designer</SubType>
278+
<Generator>MSBuild:Compile</Generator>
279+
</Page>
272280
<Page Include="Views\LinkPage.xaml">
273281
<SubType>Designer</SubType>
274282
<Generator>MSBuild:Compile</Generator>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using libsignalservice;
2+
using Microsoft.Extensions.Logging;
3+
using Signal_Windows.Storage;
4+
using Signal_Windows.Views;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Windows.Storage.Pickers;
11+
using Windows.UI.Core;
12+
13+
namespace Signal_Windows.ViewModels
14+
{
15+
public class GlobalSettingsPageViewModel
16+
{
17+
private readonly ILogger Logger = LibsignalLogging.CreateLogger<GlobalSettingsPageViewModel>();
18+
public GlobalSettingsPage View;
19+
20+
public void BackButton_Click(object sender, BackRequestedEventArgs e)
21+
{
22+
View.Frame.GoBack();
23+
e.Handled = true;
24+
}
25+
26+
public async Task OnNavigatedTo()
27+
{
28+
}
29+
30+
public async Task ExportUIDebugLog()
31+
{
32+
var savePicker = new FileSavePicker();
33+
savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
34+
savePicker.SuggestedFileName = "Signal-Windows.ui.log";
35+
var file = await savePicker.PickSaveFileAsync();
36+
if (file != null)
37+
{
38+
await Task.Run(() =>
39+
{
40+
SignalFileLoggerProvider.ExportUILog(file);
41+
});
42+
}
43+
else
44+
{
45+
Logger.LogTrace("No file was selected");
46+
}
47+
}
48+
}
49+
}

Signal-Windows/ViewModels/ViewModelLocator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public ViewModelLocator()
4040
SimpleIoc.Default.Register<LinkPageViewModel>();
4141
SimpleIoc.Default.Register<FinishRegistrationPageViewModel>();
4242
SimpleIoc.Default.Register<ConversationSettingsPageViewModel>();
43+
SimpleIoc.Default.Register<GlobalSettingsPageViewModel>();
4344
}
4445

4546
// <summary>
@@ -106,6 +107,11 @@ public ConversationSettingsPageViewModel ConversationSettingsPageInstance
106107
get { return ServiceLocator.Current.GetInstance<ConversationSettingsPageViewModel>(Key.ToString()); }
107108
}
108109

110+
public GlobalSettingsPageViewModel GlobalSettingsPageInstance
111+
{
112+
get { return ServiceLocator.Current.GetInstance<GlobalSettingsPageViewModel>(Key.ToString()); }
113+
}
114+
109115
// <summary>
110116
// The cleanup.
111117
// </summary>

Signal-Windows/Views/AddContactPage.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@
5353
</toolbox:PullToRefreshListView>
5454
<ProgressRing Width="75" Height="75" IsActive="{x:Bind Vm.RefreshingContacts, Mode=OneWay}"/>
5555
</Grid>
56-
5756
</Grid>
5857
</Page>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Page
2+
x:Class="Signal_Windows.Views.GlobalSettingsPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Signal_Windows.Views"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
DataContext="{Binding GlobalSettingsPageInstance, Source={StaticResource Locator}}">
10+
11+
<Page.Resources>
12+
</Page.Resources>
13+
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="10 10 10 10">
14+
<Grid HorizontalAlignment="Center">
15+
<TextBlock FontSize="24" Text="Settings"/>
16+
</Grid>
17+
<Grid HorizontalAlignment="Center">
18+
<Button Click="ExportUIDebugLog">Submit debug log</Button>
19+
</Grid>
20+
</StackPanel>
21+
</Page>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Signal_Windows.ViewModels;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.InteropServices.WindowsRuntime;
7+
using Windows.Foundation;
8+
using Windows.Foundation.Collections;
9+
using Windows.UI.Xaml;
10+
using Windows.UI.Xaml.Controls;
11+
using Windows.UI.Xaml.Controls.Primitives;
12+
using Windows.UI.Xaml.Data;
13+
using Windows.UI.Xaml.Input;
14+
using Windows.UI.Xaml.Media;
15+
using Windows.UI.Xaml.Navigation;
16+
17+
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
18+
19+
namespace Signal_Windows.Views
20+
{
21+
/// <summary>
22+
/// An empty page that can be used on its own or navigated to within a Frame.
23+
/// </summary>
24+
public sealed partial class GlobalSettingsPage : Page
25+
{
26+
public GlobalSettingsPage()
27+
{
28+
this.InitializeComponent();
29+
Vm.View = this;
30+
}
31+
32+
public GlobalSettingsPageViewModel Vm
33+
{
34+
get
35+
{
36+
return (GlobalSettingsPageViewModel)DataContext;
37+
}
38+
}
39+
40+
protected override async void OnNavigatedTo(NavigationEventArgs ev)
41+
{
42+
base.OnNavigatedTo(ev);
43+
Utils.EnableBackButton(Vm.BackButton_Click);
44+
await Vm.OnNavigatedTo();
45+
}
46+
47+
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
48+
{
49+
base.OnNavigatingFrom(e);
50+
Utils.DisableBackButton(Vm.BackButton_Click);
51+
}
52+
53+
private async void ExportUIDebugLog(object sender, RoutedEventArgs e)
54+
{
55+
await Vm.ExportUIDebugLog();
56+
}
57+
}
58+
}

Signal-Windows/Views/MainPage.xaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,24 @@
2828
<SplitView.Pane>
2929
<Grid x:Name="ContactsGrid">
3030
<Grid.RowDefinitions>
31-
<RowDefinition Height="Auto"/>
32-
<RowDefinition Height="Auto"/>
33-
<RowDefinition Height="*"/>
31+
<RowDefinition Height="Auto" />
32+
<RowDefinition Height="Auto" />
33+
<RowDefinition Height="*" />
3434
</Grid.RowDefinitions>
35-
<TextBlock Grid.Row="0" Text="Signal" FontSize="34" FontWeight="Light" Margin="0,16" HorizontalAlignment="Center" Foreground="{ThemeResource ApplicationPageBackgroundThemeBrush}"/>
36-
<Button x:Name="AddContactButton" Grid.Row="0" HorizontalAlignment="Right" Background="{x:Null}" Click="AddContactButton_Click">
37-
<TextBlock Text="+" FontSize="34" FontWeight="Light" Foreground="{ThemeResource ApplicationPageBackgroundThemeBrush}"/>
38-
</Button>
35+
<Grid Grid.Row="0">
36+
<Grid.ColumnDefinitions>
37+
<ColumnDefinition Width="*" />
38+
<ColumnDefinition Width="Auto" />
39+
<ColumnDefinition Width="Auto" />
40+
</Grid.ColumnDefinitions>
41+
<TextBlock HorizontalAlignment="Center" Grid.Column="0" Text="Signal" FontSize="34" FontWeight="Light" Margin="0,16" Foreground="{ThemeResource ApplicationPageBackgroundThemeBrush}"/>
42+
<Button Grid.Column="1" x:Name="AddContactButton" Background="{x:Null}" Click="AddContactButton_Click">
43+
<SymbolIcon Symbol="AddFriend" Foreground="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
44+
</Button>
45+
<Button Grid.Column="2" x:Name="GlobalSettingsButton" Background="{x:Null}" Click="GlobalSettingsButton_Click">
46+
<SymbolIcon Symbol="Setting" Foreground="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
47+
</Button>
48+
</Grid>
3949
<AutoSuggestBox Grid.Row="1" Margin="16"/>
4050
<ListView Grid.Row="2" Name="ContactsList" ItemsSource="{x:Bind Vm.Conversations, Mode=TwoWay}" SelectionMode="Single" SelectionChanged="Vm.ConversationsList_SelectionChanged" SelectedItem="{x:Bind Vm.SelectedConversation, Mode=TwoWay}">
4151
<ListView.ItemsPanel>

Signal-Windows/Views/MainPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,10 @@ internal void Reload()
158158
{
159159
ConversationControl.Load(Vm.SelectedThread);
160160
}
161+
162+
private void GlobalSettingsButton_Click(object sender, RoutedEventArgs e)
163+
{
164+
Frame.Navigate(typeof(GlobalSettingsPage));
165+
}
161166
}
162167
}

0 commit comments

Comments
 (0)