Skip to content

Commit 6a8e47b

Browse files
committed
Start creating global settings
1 parent 9a94841 commit 6a8e47b

27 files changed

+1086
-65
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Windows.Storage;
8+
9+
namespace Signal_Windows.Lib
10+
{
11+
public static class GlobalSettingsManager
12+
{
13+
private const string NotificationsContainer = "notifications";
14+
private const string PrivacyContainer = "privacy";
15+
private const string AppearanceContainer = "appearance";
16+
private const string ChatsAndMediaContainer = "chatsandmedia";
17+
private const string AdvancedContainer = "advanced";
18+
19+
private const string ShowNotificationText = "ShowNotificationText";
20+
public enum ShowNotificationTextSettings
21+
{
22+
NameAndMessage,
23+
NameOnly,
24+
NoNameOrMessage
25+
}
26+
private const string BlockScreenshots = "BlockScreenshots";
27+
private const string EnableReadReceipts = "EnableReadReceipts";
28+
29+
private static ApplicationDataContainer localSettings;
30+
private static IReadOnlyDictionary<string, ApplicationDataContainer> Containers
31+
{
32+
get { return localSettings.Containers; }
33+
}
34+
35+
static GlobalSettingsManager()
36+
{
37+
localSettings = ApplicationData.Current.LocalSettings;
38+
var containers = localSettings.Containers;
39+
if (!containers.ContainsKey(NotificationsContainer))
40+
{
41+
localSettings.CreateContainer(NotificationsContainer, ApplicationDataCreateDisposition.Always);
42+
}
43+
if (!containers.ContainsKey(PrivacyContainer))
44+
{
45+
localSettings.CreateContainer(PrivacyContainer, ApplicationDataCreateDisposition.Always);
46+
}
47+
if (!containers.ContainsKey(AppearanceContainer))
48+
{
49+
localSettings.CreateContainer(AppearanceContainer, ApplicationDataCreateDisposition.Always);
50+
}
51+
if (!containers.ContainsKey(ChatsAndMediaContainer))
52+
{
53+
localSettings.CreateContainer(ChatsAndMediaContainer, ApplicationDataCreateDisposition.Always);
54+
}
55+
if (!containers.ContainsKey(AdvancedContainer))
56+
{
57+
localSettings.CreateContainer(AdvancedContainer, ApplicationDataCreateDisposition.Always);
58+
}
59+
}
60+
61+
public static ShowNotificationTextSettings ShowNotificationTextSetting
62+
{
63+
get
64+
{
65+
return (ShowNotificationTextSettings)GetSetting(Containers[NotificationsContainer],
66+
ShowNotificationText, (int)ShowNotificationTextSettings.NameAndMessage);
67+
}
68+
set
69+
{
70+
Containers[NotificationsContainer].Values[ShowNotificationText] = (int)value;
71+
}
72+
}
73+
74+
public static bool BlockScreenshotsSetting
75+
{
76+
get
77+
{
78+
return GetSetting(Containers[PrivacyContainer], BlockScreenshots, false);
79+
}
80+
set
81+
{
82+
Containers[PrivacyContainer].Values[BlockScreenshots] = value;
83+
}
84+
}
85+
86+
public static bool EnableReadReceiptsSetting
87+
{
88+
get
89+
{
90+
return GetSetting(Containers[PrivacyContainer], EnableReadReceipts, true);
91+
}
92+
set
93+
{
94+
Containers[PrivacyContainer].Values[EnableReadReceipts] = value;
95+
}
96+
}
97+
98+
private static T GetSetting<T>(ApplicationDataContainer container, string key, T defaultValue)
99+
{
100+
if (container.Values.ContainsKey(key))
101+
{
102+
return (T)container.Values[key];
103+
}
104+
else
105+
{
106+
container.Values[key] = defaultValue;
107+
return defaultValue;
108+
}
109+
}
110+
}
111+
}

Signal-Windows.Lib/Signal-Windows.Lib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
</PropertyGroup>
108108
<ItemGroup>
109109
<Compile Include="Events\SignalMessageEventArgs.cs" />
110+
<Compile Include="GlobalSettingsManager.cs" />
110111
<Compile Include="IncomingMessages.cs" />
111112
<Compile Include="Util\LibUtils.cs" />
112113
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.cs" />

Signal-Windows.Lib/Util/LibUtils.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,28 +157,6 @@ public static EventWaitHandle OpenResetEventUnset()
157157
return new EventWaitHandle(false, EventResetMode.ManualReset, GlobalEventWaitHandleName, out bool createdNew);
158158
}
159159

160-
public static ToastNotification CreateToastNotification(string text)
161-
{
162-
ToastContent toastContent = new ToastContent()
163-
{
164-
Visual = new ToastVisual()
165-
{
166-
BindingGeneric = new ToastBindingGeneric()
167-
{
168-
Children =
169-
{
170-
new AdaptiveText()
171-
{
172-
Text = text,
173-
HintWrap = true
174-
}
175-
}
176-
}
177-
}
178-
};
179-
return new ToastNotification(toastContent.GetXml());
180-
}
181-
182160
public static FileStream CreateTmpFile(string name)
183161
{
184162
return File.Open(ApplicationData.Current.LocalCacheFolder.Path + Path.AltDirectorySeparatorChar + name, FileMode.Create, FileAccess.ReadWrite);

Signal-Windows.Lib/Util/NotificationsUtils.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,42 @@ public static void SendMessageNotification(SignalMessage message)
7070
private static IList<AdaptiveText> GetNotificationText(SignalMessage message)
7171
{
7272
List<AdaptiveText> text = new List<AdaptiveText>();
73-
AdaptiveText title = new AdaptiveText()
73+
if (GlobalSettingsManager.ShowNotificationTextSetting == GlobalSettingsManager.ShowNotificationTextSettings.NameAndMessage)
7474
{
75-
Text = message.Author.ThreadDisplayName,
75+
text.Add(CreateToastTitle(message.Author.ThreadDisplayName));
76+
text.Add(CreateToastBody(message.Content.Content));
77+
}
78+
else if (GlobalSettingsManager.ShowNotificationTextSetting == GlobalSettingsManager.ShowNotificationTextSettings.NameOnly)
79+
{
80+
text.Add(CreateToastTitle(message.Author.ThreadDisplayName));
81+
}
82+
else if (GlobalSettingsManager.ShowNotificationTextSetting == GlobalSettingsManager.ShowNotificationTextSettings.NoNameOrMessage)
83+
{
84+
text.Add(CreateToastTitle("New message"));
85+
}
86+
else
87+
{
88+
text.Add(CreateToastTitle("New message"));
89+
}
90+
return text;
91+
}
92+
93+
private static AdaptiveText CreateToastTitle(string text)
94+
{
95+
return new AdaptiveText()
96+
{
97+
Text = text,
7698
HintMaxLines = 1
7799
};
78-
AdaptiveText messageText = new AdaptiveText()
100+
}
101+
102+
private static AdaptiveText CreateToastBody(string text)
103+
{
104+
return new AdaptiveText()
79105
{
80-
Text = message.Content.Content,
106+
Text = text,
81107
HintWrap = true
82108
};
83-
text.Add(title);
84-
text.Add(messageText);
85-
return text;
86109
}
87110

88111
public static void SendTileNotification(SignalMessage message)

Signal-Windows/App.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ private async Task CreateSecondaryWindowOrShowMain(ActivationViewSwitcher switch
199199
Window.Current.Content = frame;
200200
Window.Current.Activate();
201201
var currView = ApplicationView.GetForCurrentView();
202+
if (GlobalSettingsManager.BlockScreenshotsSetting)
203+
{
204+
currView.IsScreenCaptureEnabled = false;
205+
}
202206
currView.Consolidated += CurrView_Consolidated;
203207
newViewId = currView.Id;
204208
ViewModelLocator newVML = (ViewModelLocator)Resources["Locator"];
@@ -267,6 +271,10 @@ private async Task<bool> CreateMainWindow(string conversationId)
267271
rootFrame.NavigationFailed += OnNavigationFailed;
268272
Window.Current.Content = rootFrame;
269273
var currView = ApplicationView.GetForCurrentView();
274+
if (GlobalSettingsManager.BlockScreenshotsSetting)
275+
{
276+
currView.IsScreenCaptureEnabled = false;
277+
}
270278
var frontend = new SignalWindowsFrontend(Window.Current.Dispatcher, (ViewModelLocator)Resources["Locator"], currView.Id);
271279
Views.Add(currView.Id, frontend);
272280
MainViewId = currView.Id;

Signal-Windows/Signal-Windows.csproj

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,35 @@
174174
<Compile Include="SignalWindowsFrontend.cs" />
175175
<Compile Include="Utils.cs" />
176176
<Compile Include="ViewModels\AddContactPageViewModel.cs" />
177+
<Compile Include="ViewModels\AdvancedSettingsPageViewModel.cs" />
178+
<Compile Include="ViewModels\AppearanceSettingsPageViewModel.cs" />
179+
<Compile Include="ViewModels\ChatsAndMediaSettingsPageViewModel.cs" />
177180
<Compile Include="ViewModels\ConversationSettingsPageViewModel.cs" />
178181
<Compile Include="ViewModels\FinishRegistrationPageViewModel.cs" />
179182
<Compile Include="ViewModels\GlobalSettingsPageViewModel.cs" />
180183
<Compile Include="ViewModels\LinkPageViewModel.cs" />
181184
<Compile Include="ViewModels\MainPageViewModel.cs" />
185+
<Compile Include="ViewModels\NotificationSettingsPageViewModel.cs" />
186+
<Compile Include="ViewModels\PrivacySettingsPageViewModel.cs" />
182187
<Compile Include="ViewModels\RegisterFinalizationPageViewModel.cs" />
183188
<Compile Include="ViewModels\RegisterPageViewModel.cs" />
184189
<Compile Include="ViewModels\StartPageViewModel.cs" />
185190
<Compile Include="ViewModels\ViewModelLocator.cs" />
191+
<Compile Include="Views\AboutPage.xaml.cs">
192+
<DependentUpon>AboutPage.xaml</DependentUpon>
193+
</Compile>
186194
<Compile Include="Views\AddContactPage.xaml.cs">
187195
<DependentUpon>AddContactPage.xaml</DependentUpon>
188196
</Compile>
197+
<Compile Include="Views\AdvancedSettingsPage.xaml.cs">
198+
<DependentUpon>AdvancedSettingsPage.xaml</DependentUpon>
199+
</Compile>
200+
<Compile Include="Views\AppearanceSettingsPage.xaml.cs">
201+
<DependentUpon>AppearanceSettingsPage.xaml</DependentUpon>
202+
</Compile>
203+
<Compile Include="Views\ChatsAndMediaSettingsPage.xaml.cs">
204+
<DependentUpon>ChatsAndMediaSettingsPage.xaml</DependentUpon>
205+
</Compile>
189206
<Compile Include="Views\ConversationSettingsPage.xaml.cs">
190207
<DependentUpon>ConversationSettingsPage.xaml</DependentUpon>
191208
</Compile>
@@ -202,6 +219,12 @@
202219
<DependentUpon>MainPage.xaml</DependentUpon>
203220
</Compile>
204221
<Compile Include="Properties\AssemblyInfo.cs" />
222+
<Compile Include="Views\NotificationSettingsPage.xaml.cs">
223+
<DependentUpon>NotificationSettingsPage.xaml</DependentUpon>
224+
</Compile>
225+
<Compile Include="Views\PrivacySettingsPage.xaml.cs">
226+
<DependentUpon>PrivacySettingsPage.xaml</DependentUpon>
227+
</Compile>
205228
<Compile Include="Views\RegisterFinalizationPage.xaml.cs">
206229
<DependentUpon>RegisterFinalizationPage.xaml</DependentUpon>
207230
</Compile>
@@ -264,10 +287,26 @@
264287
<SubType>Designer</SubType>
265288
<Generator>MSBuild:Compile</Generator>
266289
</Page>
290+
<Page Include="Views\AboutPage.xaml">
291+
<SubType>Designer</SubType>
292+
<Generator>MSBuild:Compile</Generator>
293+
</Page>
267294
<Page Include="Views\AddContactPage.xaml">
268295
<SubType>Designer</SubType>
269296
<Generator>MSBuild:Compile</Generator>
270297
</Page>
298+
<Page Include="Views\AdvancedSettingsPage.xaml">
299+
<SubType>Designer</SubType>
300+
<Generator>MSBuild:Compile</Generator>
301+
</Page>
302+
<Page Include="Views\AppearanceSettingsPage.xaml">
303+
<SubType>Designer</SubType>
304+
<Generator>MSBuild:Compile</Generator>
305+
</Page>
306+
<Page Include="Views\ChatsAndMediaSettingsPage.xaml">
307+
<SubType>Designer</SubType>
308+
<Generator>MSBuild:Compile</Generator>
309+
</Page>
271310
<Page Include="Views\ConversationSettingsPage.xaml">
272311
<SubType>Designer</SubType>
273312
<Generator>MSBuild:Compile</Generator>
@@ -288,6 +327,14 @@
288327
<Generator>MSBuild:Compile</Generator>
289328
<SubType>Designer</SubType>
290329
</Page>
330+
<Page Include="Views\NotificationSettingsPage.xaml">
331+
<SubType>Designer</SubType>
332+
<Generator>MSBuild:Compile</Generator>
333+
</Page>
334+
<Page Include="Views\PrivacySettingsPage.xaml">
335+
<SubType>Designer</SubType>
336+
<Generator>MSBuild:Compile</Generator>
337+
</Page>
291338
<Page Include="Views\RegisterFinalizationPage.xaml">
292339
<SubType>Designer</SubType>
293340
<Generator>MSBuild:Compile</Generator>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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 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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
8+
namespace Signal_Windows.ViewModels
9+
{
10+
public class AppearanceSettingsPageViewModel : ViewModelBase
11+
{
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
8+
namespace Signal_Windows.ViewModels
9+
{
10+
public class ChatsAndMediaSettingsPageViewModel : ViewModelBase
11+
{
12+
}
13+
}

0 commit comments

Comments
 (0)