Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

Commit a9d1ef1

Browse files
authored
feat: merge pull request #15 from ArvinZJC/dev
feat: release V1.1-beta.1
2 parents f766b2d + f1b61fc commit a9d1ef1

16 files changed

Lines changed: 1046 additions & 112 deletions

PaimonTray/App.xaml.cs

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
using PaimonTray.Views;
55
using PaimonTray.ViewModels;
66
using Serilog;
7+
using System;
8+
using System.Diagnostics;
79
using System.IO;
810
using System.Threading.Tasks;
911
using Windows.ApplicationModel;
1012
using Windows.Storage;
13+
using Windows.System;
14+
using AppInstance = Microsoft.Windows.AppLifecycle.AppInstance;
1115

1216
namespace PaimonTray
1317
{
@@ -25,8 +29,18 @@ public App()
2529
{
2630
ConfigLogger();
2731
GenerateAppVersion();
28-
Log.Information($"{Package.Current.DisplayName} v{AppVersionTag} started.");
32+
Log.Information(
33+
$"{Package.Current.DisplayName} v{AppVersionTag} ({Package.Current.Id.FamilyName}) started.");
2934
InitializeComponent();
35+
UnhandledException += (_, args) =>
36+
{
37+
Log.Error($"Unhandled exception: {args.Message}");
38+
Log.Error($" - Inner exception: {args.Exception.InnerException}");
39+
Log.Error($" - Stack trace: {args.Exception.StackTrace}");
40+
Log.Error($" - HRESULT: {args.Exception.HResult}");
41+
Log.Error($" - Help link: {args.Exception.HelpLink}");
42+
Log.CloseAndFlush();
43+
};
3044
} // end constructor App
3145

3246
#endregion Constructors
@@ -50,6 +64,16 @@ private void ConfigLogger()
5064
rollingInterval: RollingInterval.Day)).CreateLogger();
5165
} // end method ConfigLogger
5266

67+
/// <summary>
68+
/// Exit the app with no window.
69+
/// </summary>
70+
private void ExitAppWithNoWindow()
71+
{
72+
Log.CloseAndFlush();
73+
_ = new Window(); // Exiting the app takes no effect if no window instances. (Reference: https://github.com/microsoft/microsoft-ui-xaml/issues/5931)
74+
Exit();
75+
} // end method ExitAppWithNoWindow
76+
5377
/// <summary>
5478
/// Generate the app version from the package version.
5579
/// </summary>
@@ -77,22 +101,53 @@ private void GenerateAppVersion()
77101
/// Other entry points will be used such as when the application is launched to open a specific file.
78102
/// </summary>
79103
/// <param name="e">Details about the launch request and process.</param>
80-
protected override void OnLaunched(LaunchActivatedEventArgs e)
104+
protected override async void OnLaunched(LaunchActivatedEventArgs e)
81105
{
82106
if (DeploymentManager.GetStatus().Status is not DeploymentStatus.Ok)
83107
{
84108
Log.Warning("The Windows App SDK runtime not in a good deployment status.");
85109

86-
var initialiseTask = Task.Run(DeploymentManager.Initialize);
110+
var initialiseTask = Task.Run(() =>
111+
DeploymentManager.Initialize(new DeploymentInitializeOptions { ForceDeployment = true }));
87112

88113
initialiseTask.Wait();
89114

90115
if (initialiseTask.Result.Status is not DeploymentStatus.Ok)
91116
{
92-
Log.Error("Failed to ensure a deployment status of the Windows App SDK runtime.");
93-
Log.CloseAndFlush();
94-
_ = new Window(); // Exiting the app takes no effect if no window instances. (Reference: https://github.com/microsoft/microsoft-ui-xaml/issues/5931)
95-
Exit();
117+
Log.Error(
118+
$"Failed to ensure a good deployment status of the Windows App SDK runtime: {initialiseTask.Result.ExtendedError.Message}");
119+
Log.Error($" - Inner exception: {initialiseTask.Result.ExtendedError.InnerException}");
120+
Log.Error($" - Stack trace: {initialiseTask.Result.ExtendedError.StackTrace}");
121+
Log.Error($" - HRESULT: {initialiseTask.Result.ExtendedError.HResult}");
122+
Log.Error($" - Help link: {initialiseTask.Result.ExtendedError.HelpLink}");
123+
124+
if (initialiseTask.Result.ExtendedError.HResult == AppFieldsHelper.HResultAccessDenied &&
125+
!Environment.CommandLine.Contains(AppFieldsHelper.TaskIdElevatedAppRestart))
126+
{
127+
Log.Information("Restarting the app elevated to try fixing the deployment failure.");
128+
AppInstance.GetCurrent().UnregisterKey();
129+
ExitAppWithNoWindow(); // Need to exit the app before starting a new app instance elevated.
130+
Process.Start(new ProcessStartInfo
131+
{
132+
Arguments = AppFieldsHelper.TaskIdElevatedAppRestart,
133+
FileName = $"shell:appsFolder\\{Package.Current.Id.FamilyName}!App",
134+
UseShellExecute = true,
135+
Verb = "runas"
136+
});
137+
}
138+
else
139+
{
140+
Log.Information(
141+
"The app cannot solve the deployment failure, will open the Windows App SDK runtime download link, and will be exited.");
142+
await Launcher.LaunchUriAsync(new Uri(
143+
$"{AppFieldsHelper.UrlBaseWindowsAppSdkRuntimeDownload}" +
144+
$"{AppFieldsHelper.VersionMajorNuGetWindowsAppSdk}.{AppFieldsHelper.VersionMinorNuGetWindowsAppSdk}/" +
145+
$"{AppFieldsHelper.VersionMajorNuGetWindowsAppSdk}.{AppFieldsHelper.VersionMinorNuGetWindowsAppSdk}.{AppFieldsHelper.VersionBuildNuGetWindowsAppSdk}.{AppFieldsHelper.VersionRevisionNuGetWindowsAppSdk}/" +
146+
$"windowsappruntimeinstall-{Package.Current.Id.Architecture.ToString().ToLower()}.exe"));
147+
ExitAppWithNoWindow();
148+
} // end if...else
149+
150+
return;
96151
} // end if
97152
} // end if
98153

PaimonTray/Helpers/AppFieldsHelper.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ public static class AppFieldsHelper
2727
/// </summary>
2828
public static readonly string GlyphAccept = "\xE8FB";
2929

30+
/// <summary>
31+
/// The code of the glyph AddFriend.
32+
/// </summary>
33+
public static readonly string GlyphAddFriend = "\xE8FA";
34+
35+
/// <summary>
36+
/// The code of the glyph Cancel.
37+
/// </summary>
38+
public static readonly string GlyphCancel = "\xE711";
39+
40+
/// <summary>
41+
/// The code of the glyph Delete.
42+
/// </summary>
43+
public static readonly string GlyphDelete = "\xE74D";
44+
3045
/// <summary>
3146
/// The code of the glyph Diagnostic.
3247
/// </summary>
@@ -42,6 +57,11 @@ public static class AppFieldsHelper
4257
/// </summary>
4358
public static readonly string GlyphHelp = "\xE897";
4459

60+
/// <summary>
61+
/// The code of the glyph Home.
62+
/// </summary>
63+
public static readonly string GlyphHome = "\xE80F";
64+
4565
/// <summary>
4666
/// The code of the glyph Info.
4767
/// </summary>
@@ -52,11 +72,31 @@ public static class AppFieldsHelper
5272
/// </summary>
5373
public static readonly string GlyphKnowledgeArticle = "\xF000";
5474

75+
/// <summary>
76+
/// The code of the glyph More.
77+
/// </summary>
78+
public static readonly string GlyphMore = "\xE712";
79+
80+
/// <summary>
81+
/// The code of the glyph People.
82+
/// </summary>
83+
public static readonly string GlyphPeople = "\xE716";
84+
5585
/// <summary>
5686
/// The code of the glyph Processing.
5787
/// </summary>
5888
public static readonly string GlyphProcessing = "\xE9F5";
5989

90+
/// <summary>
91+
/// The code of the glyph Refresh.
92+
/// </summary>
93+
public static readonly string GlyphRefresh = "\xE72C";
94+
95+
/// <summary>
96+
/// The code of the glyph Settings.
97+
/// </summary>
98+
public static readonly string GlyphSettings = "\xE713";
99+
60100
/// <summary>
61101
/// The code of the glyph SwitchUser.
62102
/// </summary>
@@ -72,11 +112,21 @@ public static class AppFieldsHelper
72112
/// </summary>
73113
public static readonly string GlyphUpdateRestore = "\xE777";
74114

115+
/// <summary>
116+
/// The code of the glyph View.
117+
/// </summary>
118+
public static readonly string GlyphView = "\xE890";
119+
75120
/// <summary>
76121
/// The code of the glyph Website.
77122
/// </summary>
78123
public static readonly string GlyphWebsite = "\xEB41";
79124

125+
/// <summary>
126+
/// General access denied error. (Reference: https://learn.microsoft.com/en-us/windows/win32/seccrypto/common-hresult-values)
127+
/// </summary>
128+
public static readonly int HResultAccessDenied = unchecked((int)0x80070005);
129+
80130
/// <summary>
81131
/// The info bar's bottom margin.
82132
/// </summary>
@@ -87,6 +137,11 @@ public static class AppFieldsHelper
87137
/// </summary>
88138
public static readonly string TagNotificationGreeting = "NotificationGreeting";
89139

140+
/// <summary>
141+
/// The elevated app restart's task ID.
142+
/// </summary>
143+
public static readonly string TaskIdElevatedAppRestart = "PaimonTrayElevatedAppRestart";
144+
90145
/// <summary>
91146
/// The representation of the unknown value.
92147
/// </summary>
@@ -147,6 +202,11 @@ public static class AppFieldsHelper
147202
/// </summary>
148203
public static readonly string UrlAppIconSource = "https://www.pixiv.net/en/artworks/92415888";
149204

205+
/// <summary>
206+
/// The base URL for the Windows App SDK runtime download.
207+
/// </summary>
208+
public static readonly string UrlBaseWindowsAppSdkRuntimeDownload = "https://aka.ms/windowsappsdk/";
209+
150210
/// <summary>
151211
/// The URL of the user manual section instructing how to get your cookies.
152212
/// </summary>
@@ -213,6 +273,26 @@ public static readonly string
213273
/// </summary>
214274
public static readonly int VersionBuildStableMin = 200;
215275

276+
/// <summary>
277+
/// The Windows App SDK NuGet package's build version.
278+
/// </summary>
279+
public static readonly int VersionBuildNuGetWindowsAppSdk = 221109;
280+
281+
/// <summary>
282+
/// The Windows App SDK NuGet package's major version.
283+
/// </summary>
284+
public static readonly int VersionMajorNuGetWindowsAppSdk = 1;
285+
286+
/// <summary>
287+
/// The Windows App SDK NuGet package's minor version.
288+
/// </summary>
289+
public static readonly int VersionMinorNuGetWindowsAppSdk = 2;
290+
291+
/// <summary>
292+
/// The Windows App SDK NuGet package's revision version.
293+
/// </summary>
294+
public static readonly int VersionRevisionNuGetWindowsAppSdk = 1;
295+
216296
#endregion Fields
217297
} // end class AppFieldsHelper
218298
} // end namespace PaimonTray.Helpers

PaimonTray/Helpers/HttpClientHelper.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,20 @@ public class HttpClientHelper
4444
/// </summary>
4545
private const string HeaderNameDynamicSecret = "DS";
4646

47+
/// <summary>
48+
/// The referer header name.
49+
/// </summary>
50+
private const string HeaderNameReferer = "Referer";
51+
4752
/// <summary>
4853
/// The app version header value for the CN server.
4954
/// </summary>
50-
private const string HeaderValueAppVersionServerCn = "2.38.1";
55+
private const string HeaderValueAppVersionServerCn = "2.40.1";
5156

5257
/// <summary>
5358
/// The app version header value for the global server.
5459
/// </summary>
55-
private const string HeaderValueAppVersionServerGlobal = "2.21.1";
60+
private const string HeaderValueAppVersionServerGlobal = "2.22.0";
5661

5762
/// <summary>
5863
/// The client type header value for the CN server.
@@ -64,6 +69,16 @@ public class HttpClientHelper
6469
/// </summary>
6570
private const string HeaderValueClientTypeServerGlobal = "2";
6671

72+
/// <summary>
73+
/// The referer header value for the CN server.
74+
/// </summary>
75+
private const string HeaderValueRefererServerCn = "https://webstatic.mihoyo.com/";
76+
77+
/// <summary>
78+
/// The referer header value for the global server.
79+
/// </summary>
80+
private const string HeaderValueRefererServerGlobal = "https://webstatic-sea.hoyolab.com";
81+
6782
#endregion Constants
6883

6984
#region Constructors
@@ -171,6 +186,14 @@ public async Task<string> SendGetRequestAsync(string cookies, bool isServerCn, b
171186
return null;
172187
} // end if
173188

189+
var headerValueReferer = isServerCn ? HeaderValueRefererServerCn : HeaderValueRefererServerGlobal;
190+
191+
if (!httpClientHeaders.TryAddWithoutValidation(HeaderNameReferer, headerValueReferer))
192+
{
193+
Log.Warning($"Failed to add the referer header (referer: {headerValueReferer}).");
194+
return null;
195+
} // end if
196+
174197
if (needDynamicSecret)
175198
{
176199
var headerValueAppVersion =

PaimonTray/Helpers/WindowsHelper.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,22 @@ public ExistingWindow GetExistingSettingsWindow()
164164
/// Get the main window's page's max size.
165165
/// </summary>
166166
/// <returns>The max size.</returns>
167-
public SizeInt32 GetMainWindowPageMaxSize()
167+
public SizeInt32 GetMainWindowPageMaxSize(double rasterisationScale)
168168
{
169169
var isMainWindowTopNavigationPane =
170170
_app.SettingsH.DecideMainWindowNavigationViewPaneDisplayMode() is NavigationViewPaneDisplayMode.Top;
171171
var mainExistingWindow = GetExistingMainWindow();
172172
var workArea =
173173
GetWorkArea(mainExistingWindow is null ? new WindowId() : GetWindowId(mainExistingWindow.Win));
174-
var workAreaOffset = 2 * MainWindowPositionOffset;
175-
var workAreaAdditionalOffset = 4 * MainWindowPositionOffset; // Reserved for the navigation pane.
174+
var workAreaOffset = 2 * MainWindowPositionOffset * rasterisationScale;
175+
var workAreaAdditionalOffset =
176+
4 * MainWindowPositionOffset * rasterisationScale; // Reserved for the navigation pane.
176177

177178
return new SizeInt32(
178-
workArea.Width - workAreaOffset - (isMainWindowTopNavigationPane ? 0 : workAreaAdditionalOffset),
179-
workArea.Height - workAreaOffset - (isMainWindowTopNavigationPane ? workAreaAdditionalOffset : 0));
179+
(int)Math.Floor((workArea.Width - workAreaOffset -
180+
(isMainWindowTopNavigationPane ? 0 : workAreaAdditionalOffset)) / rasterisationScale),
181+
(int)Math.Floor((workArea.Height - workAreaOffset -
182+
(isMainWindowTopNavigationPane ? workAreaAdditionalOffset : 0)) / rasterisationScale));
180183
} // end method GetMainWindowPageMaxSize
181184

182185
/// <summary>

PaimonTray/Package.appxmanifest

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22

33
<Package
44
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
6+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
57
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
68
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
7-
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
8-
IgnorableNamespaces="uap uap5">
9+
IgnorableNamespaces="desktop rescap uap uap5">
910
<Identity
1011
Name="12436ArvinZJC.40085CBC45AEE"
1112
Publisher="CN=E90C2C37-436F-4061-9936-3EA91C959CF6"
12-
Version="1.1.0.0" />
13+
Version="1.1.100.0" />
1314
<Properties>
1415
<DisplayName>PaimonTray</DisplayName>
1516
<PublisherDisplayName>ArvinZJC</PublisherDisplayName>
1617
<Logo>Assets\AppIcon\StoreLogo.png</Logo>
1718
</Properties>
1819
<Dependencies>
19-
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
20+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22621.0" />
2021
</Dependencies>
2122
<Resources>
2223
<Resource Language="en-GB"/>
2324
<Resource Language="en-US"/>
2425
<Resource Language="zh-Hans-CN"/>
2526
</Resources>
2627
<Applications>
27-
<Application Id="App"
28+
<Application
29+
Id="App"
2830
Executable="$targetnametoken$.exe"
2931
EntryPoint="$targetentrypoint$">
3032
<uap:VisualElements

0 commit comments

Comments
 (0)