Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复了WebView2的生命周期和透明度问题,进行了跨平台的适配,同时强迫症犯了帮你重构了项目结构 #1

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Hollow.Core.Helpers;
namespace Hollow.Abstractions.JsonConverters;

public class JsonIntToStringConverter: JsonConverter<string>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.IO;
using System.Reflection;
using System.Reflection;

namespace Hollow.Models;
namespace Hollow.Abstractions.Models;

public class AppInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Hollow.Models.Configs;
namespace Hollow.Abstractions.Models.Configs;

public class AppConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Hollow.Core.Gacha.Common;
namespace Hollow.Abstractions.Models.HttpContrasts.Gacha.Common;

public class GachaItem
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using Hollow.Core.Gacha.Common;
using Hollow.Abstractions.Models.HttpContrasts.Gacha.Common;

namespace Hollow.Core.Gacha;
namespace Hollow.Abstractions.Models.HttpContrasts.Gacha;

public class GachaPage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text.Json.Serialization;
using Hollow.Core.Gacha.Common;
using Hollow.Core.Helpers;
using Hollow.Abstractions.JsonConverters;
using Hollow.Abstractions.Models.HttpContrasts.Gacha.Common;

namespace Hollow.Core.Gacha.Uigf;
namespace Hollow.Abstractions.Models.HttpContrasts.Gacha.Uigf;

public class GachaRecords
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Hollow.Core.MiHoYoLauncher.Models.Common;
namespace Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher.Common;

public class ImageModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using Hollow.Core.MiHoYoLauncher.Models.Common;
using Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher.Common;

namespace Hollow.Core.MiHoYoLauncher.Models;
namespace Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher;

public class ZzzAllGameBasicInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Hollow.Core.MiHoYoLauncher.Models;
namespace Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher;

public class ZzzAnnouncement
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Hollow.Core.MiHoYoLauncher.Models;
namespace Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher;

public class ZzzAnnouncementContent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using Hollow.Core.MiHoYoLauncher.Models.Common;
using Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher.Common;

namespace Hollow.Core.MiHoYoLauncher.Models;
namespace Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher;


public class ZzzGameContent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using Hollow.Core.MiHoYoLauncher.Models.Common;
using Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher.Common;

namespace Hollow.Core.MiHoYoLauncher.Models;
namespace Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher;

public class ZzzGameInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Hollow.Models;
namespace Hollow.Abstractions.Models.HttpContrasts;

public struct Response<T>(bool isSuccess, string message="")
public struct Response<T>(bool isSuccess, string message = "")
{
public T Data { get; set; }
public readonly bool IsSuccess = isSuccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Hollow.Core.MiHoYoLauncher;
namespace Hollow.Abstractions.Models.MiHoYoLauncher;

public class GameId
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Hollow.Core.MiHoYoLauncher;
namespace Hollow.Abstractions.Models.MiHoYoLauncher;

public class LauncherId
{
Expand Down
27 changes: 27 additions & 0 deletions Hollow.Windows/Hollow.Windows.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<TieredPGO>true</TieredPGO>
<TieredCompilationQuickJitForLoops>true</TieredCompilationQuickJitForLoops>
<ApplicationIcon>Assets\Icons\small_icon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2646-prerelease"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Hollow\Hollow.csproj"/>
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions Hollow.Windows/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GetModuleHandle
RegisterClassEx
CreateWindowEx
PostQuitMessage
WM_DESTROY
DefWindowProc
DestroyWindow
GetWindowLong
SetLayeredWindowAttributes
25 changes: 10 additions & 15 deletions Hollow/Program.cs → Hollow.Windows/Program.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
using Avalonia;
using System;
using System.IO;
using Hollow.Models;
using Hollow.Abstractions.Models;
using Hollow.Views.Controls.WebView;
using Hollow.Windows.Services;
using Microsoft.Extensions.DependencyInjection;
using Serilog;

namespace Hollow;
namespace Hollow.Windows;

sealed class Program
public static class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Version", AppInfo.AppVersion)
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}")
.WriteTo.File(Path.Combine(AppInfo.LogDir, "log_.txt"), outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}", rollingInterval: RollingInterval.Day, retainedFileCountLimit: null)
.CreateLogger();

Log.Information("Hollow is starting...");

//TODO: Platform specific
Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", AppInfo.CachesDir);

try
{
App.ConfigureServices(x =>
x.AddTransient<IWebViewAdapter, WebView2Adapter>()
);
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
catch (Exception e)
Expand Down
Loading