Skip to content

Commit

Permalink
A lot!
Browse files Browse the repository at this point in the history
- Cleanup settings in themes
- Light theme improvements
- Move `DiscordClient` out of `App` class
- Fast connect™️
- Improved logging
- Improved reconnections
- Fixed an issue with DMs with no members
- Periodic background notifications test
  • Loading branch information
WamWooWam committed Sep 29, 2024
1 parent 1c5664a commit d147ec3
Show file tree
Hide file tree
Showing 81 changed files with 2,825 additions and 668 deletions.
65 changes: 65 additions & 0 deletions Unicord.Universal.Background.Tasks/PeriodicNotificationsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DSharpPlus;
using Unicord.Universal.Shared;
using Windows.ApplicationModel.Background;
using Windows.Security.Credentials;
using Windows.UI.Notifications;

namespace Unicord.Universal.Background.Tasks
{
public sealed class PeriodicNotificationsTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
try
{
if (!TryGetToken(out string token))
return;

var tileUpdateManager = TileUpdateManager.CreateTileUpdaterForApplication();
var toastNotifier = ToastNotificationManager.CreateToastNotifier();

var restClient = new DiscordRestClient(new DiscordConfiguration() { Token = token, TokenType = TokenType.User });
var mentions = await restClient.GetUserMentionsAsync(25, true, true);

foreach (var mention in mentions)
{
if (!NotificationUtils.WillShowToast(restClient, mention))
continue;

var tileNotification = NotificationUtils.CreateTileNotificationForMessage(restClient, mention);
var toastNotification = NotificationUtils.CreateToastNotificationForMessage(restClient, mention);

tileUpdateManager.Update(tileNotification);
toastNotifier.Show(toastNotification);
}
}
finally
{
deferral.Complete();
}
}

internal static bool TryGetToken(out string token)
{
try
{
var passwordVault = new PasswordVault();
var credential = passwordVault.Retrieve(Constants.TOKEN_IDENTIFIER, "Default");
credential.RetrievePassword();

token = credential.Password;
return true;
}
catch { }

token = null;
return false;
}
}
}
26 changes: 26 additions & 0 deletions Unicord.Universal.Background.Tasks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Unicord.Universal.Background.Tasks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Unicord.Universal.Background.Tasks")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{69F44648-37CD-4B20-8814-2BAF85B4F624}</ProjectGuid>
<OutputType>winmdobj</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Unicord.Universal.Background.Tasks</RootNamespace>
<AssemblyName>Unicord.Universal.Background.Tasks</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22000.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AllowCrossPlatformRetargeting>false</AllowCrossPlatformRetargeting>
<LangVersion>9</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<PlatformTarget>ARM64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
<PlatformTarget>ARM64</PlatformTarget>
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<Compile Include="PeriodicNotificationsTask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Libraries\DSharpPlus\DSharpPlus.Rest\DSharpPlus.Rest.csproj">
<Project>{c01b8589-13fe-4a6d-b159-6644977f58de}</Project>
<Name>DSharpPlus.Rest</Name>
</ProjectReference>
<ProjectReference Include="..\Libraries\DSharpPlus\DSharpPlus\DSharpPlus.csproj">
<Project>{0f4b3af7-9320-41ae-82d0-3737949499c7}</Project>
<Name>DSharpPlus</Name>
</ProjectReference>
<ProjectReference Include="..\Libraries\MomentSharp\MomentSharp\MomentSharp.csproj">
<Project>{8a4a933c-c579-4c36-9133-7d6721f99aec}</Project>
<Name>MomentSharp</Name>
</ProjectReference>
<ProjectReference Include="..\Libraries\WamWooWam.Core\WamWooWam.Core\WamWooWam.Core.csproj">
<Project>{6e8e3c2c-a7d2-4971-a97d-fa831e3ecf15}</Project>
<Name>WamWooWam.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Libraries\WindowsCommunityToolkit\Microsoft.Toolkit.Uwp.Notifications\Microsoft.Toolkit.Uwp.Notifications.csproj">
<Project>{921c4ba1-7a60-43a5-950f-0d72d5ed64e3}</Project>
<Name>Microsoft.Toolkit.Uwp.Notifications</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\Unicord.Universal.Shared\Unicord.Universal.Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
17 changes: 10 additions & 7 deletions Unicord.Universal.Background/NotificationApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private async Task InitialiseAsync()
{
TokenType = TokenType.User,
Token = _token,
MessageCacheSize = 0
MessageCacheSize = 0,
ReconnectIndefinitely = true
});

_badgeManager = new BadgeManager(_discord);
Expand All @@ -96,8 +97,9 @@ private async Task InitialiseAsync()

await _discord.ConnectAsync(status: UserStatus.Invisible, idlesince: DateTimeOffset.Now);
}
catch (Exception)
catch (Exception ex)
{
Debug.WriteLine(ex);
this.ExitThread();
}
}
Expand Down Expand Up @@ -150,9 +152,9 @@ private async Task OnDiscordMessage(DiscordClient client, MessageCreateEventArgs
if (_secondaryTileManager != null)
await _secondaryTileManager.HandleMessageAsync(client, e.Message);
}
catch (Exception)
catch (Exception ex)
{
// TODO: log
Debug.WriteLine(ex);
}
}

Expand All @@ -165,9 +167,9 @@ private Task OnMessageUpdated(DiscordClient client, MessageUpdateEventArgs e)
_toastManager?.HandleMessageUpdated(client, e.Message);
}
}
catch (Exception)
catch (Exception ex)
{
// TODO: log
Debug.WriteLine(ex);
}

return Task.CompletedTask;
Expand All @@ -186,9 +188,10 @@ private async Task OnMessageAcknowledged(DiscordClient client, MessageAcknowledg
if (_secondaryTileManager != null)
await _secondaryTileManager.HandleAcknowledgeAsync(e.Channel);
}
catch (Exception)
catch (Exception ex)
{
// TODO: log
Debug.WriteLine(ex);
}
}

Expand Down
30 changes: 16 additions & 14 deletions Unicord.Universal.Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
IgnorableNamespaces="uap mp uap2 uap3 uap4 uap5 rescap">
<Identity Name="24101WamWooWamRD.Unicord" Publisher="CN=0F22111D-EDF0-42F0-B58D-26C4C5C5054B" Version="2.0.27.0" />
<Identity Name="24101WamWooWamRD.Unicord" Publisher="CN=0F22111D-EDF0-42F0-B58D-26C4C5C5054B" Version="2.0.32.0" />
<mp:PhoneIdentity PhoneProductId="5783aabf-3049-421f-ae1d-e88bd89018f2" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>ms-resource:AppDisplayName</DisplayName>
Expand All @@ -24,9 +24,16 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Unicord.Universal.App">
<uap:VisualElements DisplayName="ms-resource:AppDisplayName" Square150x150Logo="Assets\Store\Square150x150Logo.png" Square44x44Logo="Assets\Store\Square44x44Logo.png" Description="ms-resource:AppDisplayDescription" BackgroundColor="transparent">
<uap:VisualElements DisplayName="ms-resource:AppDisplayName"
Square150x150Logo="Assets\Store\Square150x150Logo.png"
Square44x44Logo="Assets\Store\Square44x44Logo.png"
Description="ms-resource:AppDisplayDescription"
BackgroundColor="transparent">
<uap:LockScreen Notification="badge" BadgeLogo="Assets\Store\BadgeLogo.png" />
<uap:DefaultTile Wide310x150Logo="Assets\Store\Wide310x150Logo.png" Square310x310Logo="Assets\Store\LargeTile.png" Square71x71Logo="Assets\Store\SmallTile.png" ShortName="Unicord">
<uap:DefaultTile Wide310x150Logo="Assets\Store\Wide310x150Logo.png"
Square310x310Logo="Assets\Store\LargeTile.png"
Square71x71Logo="Assets\Store\SmallTile.png"
ShortName="Unicord">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo" />
<uap:ShowOn Tile="wide310x150Logo" />
Expand All @@ -42,9 +49,6 @@
</uap:InitialRotationPreference>
</uap:VisualElements>
<Extensions>
<!--<uap5:Extension Category="windows.startupTask" StartPage="EntryPage">
<uap5:StartupTask TaskId="UnicordStartup" DisplayName="Unicord" />
</uap5:Extension>-->
<uap:Extension Category="windows.voipCall">
</uap:Extension>
<uap4:Extension Category="windows.contactPanel">
Expand Down Expand Up @@ -79,6 +83,12 @@
<uap:DisplayName>Unicord</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
<Extension Category="windows.backgroundTasks" EntryPoint="Unicord.Universal.Background.Tasks.PeriodicNotificationsTask">
<BackgroundTasks>
<Task Type="general"/>
<Task Type="timer"/>
</BackgroundTasks>
</Extension>
<uap:Extension Category="windows.appService" EntryPoint="Unicord.Universal.Voice.Background.ServiceBackgroundTask">
<uap:AppService Name="com.wankerr.Unicord.Voice" ServerName="Unicord.Universal.Voice.Background.ServiceBackgroundTask" />
</uap:Extension>
Expand All @@ -87,14 +97,6 @@
<Task Type="systemEvent" />
</BackgroundTasks>
</Extension>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="uni-theme">
<uap:DisplayName>Unicord Theme</uap:DisplayName>
<uap:SupportedFileTypes>
<uap:FileType ContentType="application/x-unicord-theme">.uni-theme</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
<desktop:Extension Category="windows.fullTrustProcess" Executable="Unicord.Universal.Background/Unicord.Universal.Background.exe">
<desktop:FullTrustProcess />
</desktop:Extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundlePlatforms>x86|x64|arm</AppxBundlePlatforms>
<AppxBundlePlatforms>arm</AppxBundlePlatforms>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<AppxBundle>Always</AppxBundle>
<AppInstallerUri>https://wamwoowam.co.uk/unicord/download</AppInstallerUri>
Expand Down
Loading

0 comments on commit d147ec3

Please sign in to comment.