Skip to content

Commit

Permalink
Fix launcher crashing bug, add more options to the updater
Browse files Browse the repository at this point in the history
  • Loading branch information
NoobNotFound committed Jun 17, 2024
1 parent 4674cd7 commit fdabf68
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 31 deletions.
3 changes: 2 additions & 1 deletion Emerald.App/Emerald.App.Package/Package.WinUI.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<EntryPointProjectUniqueName>..\Emerald.App\Emerald.App.csproj</EntryPointProjectUniqueName>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<PackageCertificateThumbprint>BA30AECD14618A89C2822FC6912530F0B59E436D</PackageCertificateThumbprint>
<PackageCertificateThumbprint>9CBDFA6FDB25BE48AA09759C40DFAB769CF9740A</PackageCertificateThumbprint>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
<AppInstallerUri>D:\Projects\Emerald\Emerald.App\Emerald.App.Package\AppPackages\</AppInstallerUri>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<PackageCertificateKeyFile>Package.WinUI_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SkipOld|x64'">
<AppxBundle>Auto</AppxBundle>
Expand Down
4 changes: 2 additions & 2 deletions Emerald.App/Emerald.App/Helpers/Extentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public static bool IsNullEmptyOrWhiteSpace(this string str) =>

public static Models.Account ToAccount(this CmlLib.Core.Auth.MSession session, bool plusCount = true)
{
bool isOffline = session.UUID == "user_uuid";
bool isOffline = session.AccessToken == "access_token";
return new Models.Account(session.Username, isOffline ? null : session.AccessToken, isOffline ? null : session.UUID, plusCount ? MainWindow.HomePage.AccountsPage.AllCount++ : 0, false, session.ClientToken);
}

public static CmlLib.Core.Auth.MSession ToMSession(this Models.Account account)
{
bool isOffline = account.UUID == null;
return new CmlLib.Core.Auth.MSession(account.UserName, isOffline ? "access_token" : account.AccessToken, isOffline ? Guid.NewGuid().ToString() : account.UUID ?? "2749420bc7a54b05ab622b34e61b8a79", account.ClientToken);
return new CmlLib.Core.Auth.MSession(account.UserName, isOffline ? "access_token" : account.AccessToken, isOffline ? Guid.NewGuid().ToString().Replace("-", "") : account.UUID) { ClientToken = account.ClientToken };
}
}
}
8 changes: 8 additions & 0 deletions Emerald.App/Emerald.App/Helpers/Settings/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,19 @@ public class App : JSON
public Discord Discord { get; set; } = new();
public NewsFilter NewsFilter { get; set; } = new();
public Store Store { get; set; } = new();
public Updates Updates { get; set; } = new();
public bool AutoClose { get; set; }
public bool HideOnLaunch { get; set; }
public bool WindowsHello { get; set; }

}
public class Updates : JSON
{

public bool CheckAtStartup { get; set; } = true;
public bool AutoDownload { get; set; }
public bool IncludePreReleases { get; set; }
}
public partial class StoreFilter : JSON
{
[ObservableProperty]
Expand Down
5 changes: 3 additions & 2 deletions Emerald.App/Emerald.App/Helpers/Updater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Windows.Management.Deployment;
using Windows.Storage;
using static PInvoke.Kernel32;
using SS = Emerald.WinUI.Helpers.Settings.SettingsSystem;

namespace Emerald.WinUI.Helpers.Updater
{
Expand All @@ -31,14 +32,14 @@ public class Updater
public Architecture Architecture => RuntimeInformation.ProcessArchitecture;

private GitHubClient Client;
public bool IsPrereleaseEnabled { get; set; } = false;
public bool IsPrereleaseEnabled => SS.Settings.App.Updates.IncludePreReleases;
public Updater()
{
}
bool IsInitialized = false;
public async System.Threading.Tasks.Task Initialize()
{
var cId = await FileIO.ReadTextAsync(await StorageFile.GetFileFromPathAsync($"{Windows.ApplicationModel.Package.Current.InstalledPath}\\MsalClientID.txt"));
var cId = await FileIO.ReadTextAsync(await StorageFile.GetFileFromPathAsync($"{Windows.ApplicationModel.Package.Current.InstalledPath}\\GithubClientID.txt"));

Client = new GitHubClient(new Octokit.ProductHeaderValue(cId));
IsInitialized = true;
Expand Down
5 changes: 4 additions & 1 deletion Emerald.App/Emerald.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Emerald.Core;
using Emerald.Core.Tasks;
using Emerald.WinUI.Helpers;
using Emerald.WinUI.Helpers.Settings.JSON;
using Emerald.WinUI.Helpers.Updater;
using Emerald.WinUI.Models;
using Emerald.WinUI.UserControls;
Expand Down Expand Up @@ -207,7 +208,9 @@ void TintColor()
{
UpdateUI();
};
App.Current.Updater.CheckForUpdates();

if (SS.Settings.App.Updates.CheckAtStartup)
App.Current.Updater.CheckForUpdates();
(Content as FrameworkElement).Loaded -= Initialize;
}
private static void UpdateUI()
Expand Down
15 changes: 7 additions & 8 deletions Emerald.App/Emerald.App/Models/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,27 @@ public partial class Account : Model
public bool Last { get; set; }

// For app UI
public string TypeIconGlyph { get => Type == AccountType.Offline ? "\xF384" : "\xEC05"; }
public string TypeIconGlyph { get => IsOffline ? "\xF384" : "\xEC05"; }

public string ProfilePicture { get => Type != AccountType.Offline ? "https://minotar.net/avatar/" + UUID : "https://minotar.net/avatar/MHF_Steve"; }
public string ProfilePicture { get => !IsOffline ? "https://minotar.net/avatar/" + UUID : "https://minotar.net/avatar/MHF_Steve"; }

public string BodyPicture { get => Type != AccountType.Offline ? "https://minotar.net/body/" + UUID : "https://minotar.net/body/MHF_Steve"; }
public string BodyPicture { get => !IsOffline ? "https://minotar.net/body/" + UUID : "https://minotar.net/body/MHF_Steve"; }

public string Skin { get => Type != AccountType.Offline ? "https://minotar.net/skin/" + UUID : "https://minotar.net/skin/MHF_Steve"; }
public string Skin { get => !IsOffline ? "https://minotar.net/skin/" + UUID : "https://minotar.net/skin/MHF_Steve"; }

public AccountType Type { get => UUID == null ? AccountType.Offline : AccountType.Microsoft; }
public AccountType Type { get => IsOffline ? AccountType.Offline : AccountType.Microsoft; }

[ObservableProperty]
private bool _CheckBoxLoaded;

public string TypeString
=> IsFake ? Localized.MicrosoftOrOffline.Localize() : (IsOffline ? Localized.OfflineAccount.Localize() : Localized.MicrosoftAccount.Localize());
=> IsOffline ? Localized.OfflineAccount.Localize() : Localized.MicrosoftAccount.Localize();

[ObservableProperty]
private bool _IsChecked;

public bool IsOffline => UUID == null;
public bool IsOffline => string.IsNullOrWhiteSpace(AccessToken);

public bool IsFake => UUID == "fake" || AccessToken == "fake";

public Account(string username, string accesstoken, string uuid, int count, bool last, string clientToken = null)
{
Expand Down
18 changes: 18 additions & 0 deletions Emerald.App/Emerald.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,22 @@
<data name="UpdateNow" xml:space="preserve">
<value>Update now</value>
</data>
<data name="AutoDownloadUpdates" xml:space="preserve">
<value>Automatically download updates if available</value>
</data>
<data name="CheckForUpdatesAtStartup" xml:space="preserve">
<value>Check for updates when app starts</value>
</data>
<data name="CheckNow" xml:space="preserve">
<value>Check Now</value>
</data>
<data name="IncludePreReleases" xml:space="preserve">
<value>Include pre-releases</value>
</data>
<data name="Updates" xml:space="preserve">
<value>Updates</value>
</data>
<data name="UpdatesDescription" xml:space="preserve">
<value>Automatically update, include prerelease etc..</value>
</data>
</root>
4 changes: 3 additions & 1 deletion Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Emerald.WinUI.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
mc:Ignorable="d"
Spacing="6">
<Rectangle
Height="2"
Margin="-16,0,-16,0"
Expand All @@ -17,6 +18,7 @@
Visibility="{x:Bind BorderVisibility}" />
<local:Expander
Title="{x:Bind Title, Mode=OneWay}"
Description="{x:Bind Description,Mode=OneWay}"
ExpanderStyle="Transparent"
HeaderControls="{x:Bind Content, Mode=OneWay}" />
</StackPanel>
12 changes: 12 additions & 0 deletions Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public ExpanderItem()



public string Description
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}

// Using a DependencyProperty as the backing store for Description. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(ExpanderItem), new PropertyMetadata(null));



public string Title
{
get { return (string)GetValue(TitleProperty); }
Expand Down
22 changes: 22 additions & 0 deletions Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@
<HyperlinkButton Content="Website" NavigateUri="https://theriversi.de/" />
</StackPanel>
</uc:Expander>
<uc:Expander
Title="{helpers:Localize Name=Updates}"
Description="{helpers:Localize Name=UpdatesDescription}"
ExpanderStyle="Default"
Icon="&#xE12B;">
<uc:Expander.Controls>
<StackPanel Spacing="6">
<uc:ExpanderItem BorderVisibility="Collapsed" Title="{helpers:Localize Name=CheckForUpdates}" Margin="0,-12,0,0">
<Button Click="btnCheckU_Click" Content="{helpers:Localize Name=CheckNow}"/>
</uc:ExpanderItem>
<uc:ExpanderItem Title="{helpers:Localize Name=IncludePreReleases}">
<ToggleSwitch IsOn="{x:Bind SS:SettingsSystem.Settings.App.Updates.IncludePreReleases}"/>
</uc:ExpanderItem>
<uc:ExpanderItem Title="{helpers:Localize Name=CheckForUpdatesAtStartup}">
<ToggleSwitch IsOn="{x:Bind SS:SettingsSystem.Settings.App.Updates.CheckAtStartup}"/>
</uc:ExpanderItem>
<uc:ExpanderItem Title="{helpers:Localize Name=AutoDownloadUpdates}" Margin="0,0,0,-10">
<ToggleSwitch IsOn="{x:Bind SS:SettingsSystem.Settings.App.Updates.AutoDownload}"/>
</uc:ExpanderItem>
</StackPanel>
</uc:Expander.Controls>
</uc:Expander>
<uc:Expander
IsExpanded="True"
Title="{helpers:Localize Name=SettingsBackups}"
Expand Down
28 changes: 17 additions & 11 deletions Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,23 @@ private async Task<bool> WindowsHelloResult() =>
!SS.Settings.App.WindowsHello || (SS.Settings.App.WindowsHello && (!await WindowsHello.IsAvailable() || WindowsHello.IsRecentlyAuthenticated(5) || await WindowsHello.Authenticate()));
private async void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (SS.Settings.App.WindowsHello && !tglWinHello.IsOn)
{
if (!await WindowsHello.Authenticate())
if (SS.Settings.App.WindowsHello && !tglWinHello.IsOn)
{
tglWinHello.IsOn = true;
_ = MessageBox.Show("Error".Localize(), "WinHelloChangeFailed".Localize(), MessageBoxButtons.Ok);
if (!await WindowsHello.Authenticate())
{
tglWinHello.IsOn = true;
_ = MessageBox.Show("Error".Localize(), "WinHelloChangeFailed".Localize(), MessageBoxButtons.Ok);
}
else
{
SS.Settings.App.WindowsHello = false;
}
}
else
{
SS.Settings.App.WindowsHello = false;
SS.Settings.App.WindowsHello = true;
}
}
else
{
SS.Settings.App.WindowsHello = true;
}

}

private async void DeleteBackup_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -173,4 +174,9 @@ private void BackupName_GotFocus(object sender, RoutedEventArgs e)
lvBackups.SelectedIndex = (lvBackups.ItemsSource as List<SettingsBackup>).IndexOf((sender as TextBox).DataContext as SettingsBackup);
LoadBackupCMDBar = lvBackups.SelectedItems.Any();
}

private void btnCheckU_Click(object sender, RoutedEventArgs e)
{
App.Current.Updater.CheckForUpdates();
}
}
2 changes: 1 addition & 1 deletion Emerald.App/Emerald.App/Views/Settings/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
Description="{helpers:Localize Name=DownloadSettingsDescription}"
Icon="&#xE896;"
IsEnabled="{x:Bind Main:App.Current.Launcher.UIState, Mode=OneWay}">
<StackPanel Spacing="5">
<StackPanel Spacing="6">
<uc:ExpanderItem
Title="{helpers:Localize Name=AssetsCheck}"
Margin="0,-10,0,0"
Expand Down
5 changes: 1 addition & 4 deletions Emerald.Core/Emerald.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CmlLib.Core" Version="3.3.10" />
<PackageReference Include="CmlLib.Core.Auth.Microsoft" Version="3.0.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
<PackageReference Include="ProjBobcat" Version="1.16.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CMLLib\CmlLib\CmlLib.csproj" />
</ItemGroup>

</Project>

0 comments on commit fdabf68

Please sign in to comment.