Skip to content

Commit 2bad73a

Browse files
committed
Testing background task support
1 parent 4b5f277 commit 2bad73a

File tree

11 files changed

+458
-8
lines changed

11 files changed

+458
-8
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Signal_Windows.Models;
7+
8+
namespace Signal_Windows.Lib.Events
9+
{
10+
public class SignalMessageEventArgs : EventArgs
11+
{
12+
public SignalMessage Message { get; private set; }
13+
14+
public SignalMessageEventArgs(SignalMessage message)
15+
{
16+
Message = message;
17+
}
18+
}
19+
}

Signal-Windows.Lib/LibUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ await dispatcher.RunAsync(priority, () =>
5656
}
5757
}
5858

59-
class LibUtils
59+
public class LibUtils
6060
{
6161
public const string GlobalSemaphoreName = "SignalWindowsPrivateMessenger_Mutex";
6262
public static string URL = "https://textsecure-service.whispersystems.org";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
107107
</PropertyGroup>
108108
<ItemGroup>
109+
<Compile Include="Events\SignalMessageEventArgs.cs" />
109110
<Compile Include="IncomingMessages.cs" />
110111
<Compile Include="LibUtils.cs" />
111112
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.cs" />
@@ -167,7 +168,11 @@
167168
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
168169
<Version>6.0.1</Version>
169170
</PackageReference>
171+
<PackageReference Include="System.ValueTuple">
172+
<Version>4.4.0</Version>
173+
</PackageReference>
170174
</ItemGroup>
175+
<ItemGroup />
171176
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
172177
<VisualStudioVersion>14.0</VisualStudioVersion>
173178
</PropertyGroup>

Signal-Windows.Lib/SignalLibHandle.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Collections.Concurrent;
1515
using libsignal;
1616
using System.Diagnostics;
17+
using Signal_Windows.Lib.Events;
1718

1819
namespace Signal_Windows.Lib
1920
{
@@ -44,6 +45,8 @@ public class SignalLibHandle
4445
private SignalServiceMessageReceiver MessageReceiver;
4546
public BlockingCollection<SignalMessage> OutgoingQueue = new BlockingCollection<SignalMessage>(new ConcurrentQueue<SignalMessage>());
4647

48+
public event EventHandler<SignalMessageEventArgs> SignalMessageEvent;
49+
4750
#region frontend api
4851
public SignalLibHandle(bool headless)
4952
{
@@ -128,6 +131,16 @@ await Task.Run(() =>
128131
SemaphoreSlim.Release();
129132
}
130133

134+
public void BackgroundAcquire()
135+
{
136+
CancelSource = new CancellationTokenSource();
137+
Instance = this;
138+
SignalDBContext.FailAllPendingMessages();
139+
Store = LibsignalDBContext.GetSignalStore();
140+
InitNetwork();
141+
Running = true;
142+
}
143+
131144
public async Task Reacquire()
132145
{
133146
Logger.LogTrace("Reacquire() locking");
@@ -169,6 +182,15 @@ public void Release()
169182
SemaphoreSlim.Release();
170183
}
171184

185+
public void BackgroundRelease()
186+
{
187+
Running = false;
188+
CancelSource.Cancel();
189+
IncomingMessagesTask?.Wait();
190+
OutgoingMessagesTask?.Wait();
191+
Instance = null;
192+
}
193+
172194
public async Task SendMessage(SignalMessage message, SignalConversation conversation)
173195
{
174196
await Task.Run(async () =>
@@ -254,6 +276,7 @@ internal void DispatchHandleMessage(SignalMessage message, SignalConversation co
254276
Frames[dispatcher].HandleMessage(message, conversation);
255277
}));
256278
}
279+
SignalMessageEvent?.Invoke(this, new SignalMessageEventArgs(message));
257280
Task.WaitAll(operations.ToArray());
258281
}
259282

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Signal-Windows.RC")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Signal-Windows.RC")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Version information for an assembly consists of the following four values:
18+
//
19+
// Major Version
20+
// Minor Version
21+
// Build Number
22+
// Revision
23+
//
24+
// You can specify all the values or you can default the Build and Revision Numbers
25+
// by using the '*' as shown below:
26+
// [assembly: AssemblyVersion("1.0.*")]
27+
[assembly: AssemblyVersion("1.0.0.0")]
28+
[assembly: AssemblyFileVersion("1.0.0.0")]
29+
[assembly: ComVisible(false)]
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F8AF07FF-395F-4BF7-84F7-D16EDE7B00DF}</ProjectGuid>
8+
<OutputType>winmdobj</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Signal_Windows.RC</RootNamespace>
11+
<AssemblyName>Signal-Windows.RC</AssemblyName>
12+
<DefaultLanguage>en-US</DefaultLanguage>
13+
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
14+
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
15+
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
16+
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
17+
<FileAlignment>512</FileAlignment>
18+
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
19+
<AllowCrossPlatformRetargeting>false</AllowCrossPlatformRetargeting>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
22+
<PlatformTarget>AnyCPU</PlatformTarget>
23+
<DebugSymbols>true</DebugSymbols>
24+
<DebugType>full</DebugType>
25+
<Optimize>false</Optimize>
26+
<OutputPath>bin\Debug\</OutputPath>
27+
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<PlatformTarget>AnyCPU</PlatformTarget>
33+
<DebugType>pdbonly</DebugType>
34+
<Optimize>true</Optimize>
35+
<OutputPath>bin\Release\</OutputPath>
36+
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
37+
<ErrorReport>prompt</ErrorReport>
38+
<WarningLevel>4</WarningLevel>
39+
</PropertyGroup>
40+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
41+
<PlatformTarget>x86</PlatformTarget>
42+
<DebugSymbols>true</DebugSymbols>
43+
<OutputPath>bin\x86\Debug\</OutputPath>
44+
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
45+
<NoWarn>;2008</NoWarn>
46+
<DebugType>full</DebugType>
47+
<PlatformTarget>x86</PlatformTarget>
48+
<UseVSHostingProcess>false</UseVSHostingProcess>
49+
<ErrorReport>prompt</ErrorReport>
50+
</PropertyGroup>
51+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
52+
<PlatformTarget>x86</PlatformTarget>
53+
<OutputPath>bin\x86\Release\</OutputPath>
54+
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
55+
<Optimize>true</Optimize>
56+
<NoWarn>;2008</NoWarn>
57+
<DebugType>pdbonly</DebugType>
58+
<PlatformTarget>x86</PlatformTarget>
59+
<UseVSHostingProcess>false</UseVSHostingProcess>
60+
<ErrorReport>prompt</ErrorReport>
61+
</PropertyGroup>
62+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
63+
<PlatformTarget>ARM</PlatformTarget>
64+
<DebugSymbols>true</DebugSymbols>
65+
<OutputPath>bin\ARM\Debug\</OutputPath>
66+
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
67+
<NoWarn>;2008</NoWarn>
68+
<DebugType>full</DebugType>
69+
<PlatformTarget>ARM</PlatformTarget>
70+
<UseVSHostingProcess>false</UseVSHostingProcess>
71+
<ErrorReport>prompt</ErrorReport>
72+
</PropertyGroup>
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
74+
<PlatformTarget>ARM</PlatformTarget>
75+
<OutputPath>bin\ARM\Release\</OutputPath>
76+
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
77+
<Optimize>true</Optimize>
78+
<NoWarn>;2008</NoWarn>
79+
<DebugType>pdbonly</DebugType>
80+
<PlatformTarget>ARM</PlatformTarget>
81+
<UseVSHostingProcess>false</UseVSHostingProcess>
82+
<ErrorReport>prompt</ErrorReport>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
85+
<PlatformTarget>x64</PlatformTarget>
86+
<DebugSymbols>true</DebugSymbols>
87+
<OutputPath>bin\x64\Debug\</OutputPath>
88+
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
89+
<NoWarn>;2008</NoWarn>
90+
<DebugType>full</DebugType>
91+
<PlatformTarget>x64</PlatformTarget>
92+
<UseVSHostingProcess>false</UseVSHostingProcess>
93+
<ErrorReport>prompt</ErrorReport>
94+
</PropertyGroup>
95+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
96+
<PlatformTarget>x64</PlatformTarget>
97+
<OutputPath>bin\x64\Release\</OutputPath>
98+
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
99+
<Optimize>true</Optimize>
100+
<NoWarn>;2008</NoWarn>
101+
<DebugType>pdbonly</DebugType>
102+
<PlatformTarget>x64</PlatformTarget>
103+
<UseVSHostingProcess>false</UseVSHostingProcess>
104+
<ErrorReport>prompt</ErrorReport>
105+
</PropertyGroup>
106+
<PropertyGroup>
107+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
108+
</PropertyGroup>
109+
<ItemGroup>
110+
<Compile Include="Properties\AssemblyInfo.cs" />
111+
<Compile Include="SignalBackgroundTask.cs" />
112+
</ItemGroup>
113+
<ItemGroup>
114+
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
115+
<Version>6.0.6</Version>
116+
</PackageReference>
117+
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
118+
<Version>2.1.1</Version>
119+
</PackageReference>
120+
</ItemGroup>
121+
<ItemGroup>
122+
<ProjectReference Include="..\Signal-Windows.Lib\Signal-Windows.Lib.csproj">
123+
<Project>{1934fd82-a5ea-4b71-b915-a1826593cb6e}</Project>
124+
<Name>Signal-Windows.Lib</Name>
125+
</ProjectReference>
126+
</ItemGroup>
127+
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
128+
<VisualStudioVersion>14.0</VisualStudioVersion>
129+
</PropertyGroup>
130+
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
131+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
132+
Other similar extension points exist, see Microsoft.Common.targets.
133+
<Target Name="BeforeBuild">
134+
</Target>
135+
<Target Name="AfterBuild">
136+
</Target>
137+
-->
138+
</Project>

0 commit comments

Comments
 (0)