mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
move InitializeCulture
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Snap.Hutao.Service;
|
||||
using System.Globalization;
|
||||
using Windows.Globalization;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
@@ -36,6 +39,23 @@ internal static class DependencyInjection
|
||||
.BuildServiceProvider(true);
|
||||
|
||||
Ioc.Default.ConfigureServices(serviceProvider);
|
||||
|
||||
serviceProvider.InitializeCulture();
|
||||
|
||||
return serviceProvider;
|
||||
}
|
||||
|
||||
private static IServiceProvider InitializeCulture(this IServiceProvider serviceProvider)
|
||||
{
|
||||
AppOptions appOptions = serviceProvider.GetRequiredService<AppOptions>();
|
||||
appOptions.PreviousCulture = CultureInfo.CurrentCulture;
|
||||
|
||||
CultureInfo cultureInfo = appOptions.CurrentCulture;
|
||||
|
||||
CultureInfo.CurrentCulture = cultureInfo;
|
||||
CultureInfo.CurrentUICulture = cultureInfo;
|
||||
ApplicationLanguages.PrimaryLanguageOverride = cultureInfo.Name;
|
||||
|
||||
return serviceProvider;
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Snap.Hutao.Core.Json;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using Snap.Hutao.Service;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Windows.Globalization;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
@@ -39,26 +36,6 @@ internal static class IocConfiguration
|
||||
.AddDbContext<AppDbContext>(AddDbContextCore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化语言
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">服务提供器</param>
|
||||
/// <returns>服务提供器,用于链式调用</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public static IServiceProvider InitializeCulture(this IServiceProvider serviceProvider)
|
||||
{
|
||||
AppOptions appOptions = serviceProvider.GetRequiredService<AppOptions>();
|
||||
appOptions.PreviousCulture = CultureInfo.CurrentCulture;
|
||||
|
||||
CultureInfo cultureInfo = appOptions.CurrentCulture;
|
||||
|
||||
CultureInfo.CurrentCulture = cultureInfo;
|
||||
CultureInfo.CurrentUICulture = cultureInfo;
|
||||
ApplicationLanguages.PrimaryLanguageOverride = cultureInfo.Name;
|
||||
|
||||
return serviceProvider;
|
||||
}
|
||||
|
||||
private static void AddDbContextCore(IServiceProvider provider, DbContextOptionsBuilder builder)
|
||||
{
|
||||
HutaoOptions hutaoOptions = provider.GetRequiredService<HutaoOptions>();
|
||||
|
||||
@@ -20,6 +20,8 @@ internal sealed class ExceptionFormat
|
||||
/// <returns>格式化后的异常</returns>
|
||||
public static string Format(Exception exception)
|
||||
{
|
||||
// TODO: handle WinRT.ExceptionHelpers+__RestrictedErrorObject
|
||||
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine("Exception Data:");
|
||||
|
||||
|
||||
@@ -29,8 +29,10 @@ internal sealed class ScheduleTaskInterop : IScheduleTaskInterop
|
||||
TaskDefinition task = TaskService.Instance.NewTask();
|
||||
task.RegistrationInfo.Description = SH.CoreScheduleTaskHelperDailyNoteRefreshTaskDescription;
|
||||
task.Triggers.Add(new TimeTrigger() { Repetition = new(TimeSpan.FromSeconds(interval), TimeSpan.Zero), });
|
||||
|
||||
string scriptPath = EnsureWScriptCreated("DailyNoteRefresh", "hutao://DailyNote/Refresh");
|
||||
task.Actions.Add("wscript", $@"/b ""{scriptPath}""");
|
||||
|
||||
TaskService.Instance.RootFolder.RegisterTaskDefinition(DailyNoteRefreshTaskName, task);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ public static partial class Program
|
||||
// By adding the using statement, we can dispose the injected services when we closing
|
||||
using (ServiceProvider serviceProvider = DependencyInjection.Initialize())
|
||||
{
|
||||
serviceProvider.InitializeCulture();
|
||||
|
||||
// In a Desktop app this runs a message pump internally,
|
||||
// and does not return until the application shuts down.
|
||||
Application.Start(AppInitializationCallback);
|
||||
|
||||
Reference in New Issue
Block a user