Skip to content

Commit

Permalink
refactor: 优化代码版本号获取方式
Browse files Browse the repository at this point in the history
  • Loading branch information
K12f committed Sep 24, 2024
1 parent 9520d35 commit 9508387
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
33 changes: 25 additions & 8 deletions src/BlueCatKoKo.Ui/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using System.Text;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Threading;

using BlueCatKoKo.Ui.Models;
using BlueCatKoKo.Ui.Services;
using BlueCatKoKo.Ui.ViewModels;
using BlueCatKoKo.Ui.ViewModels.Pages;
using BlueCatKoKo.Ui.Views;
using BlueCatKoKo.Ui.Views.Pages;

using CommunityToolkit.Mvvm.Messaging;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Serilog;

using Wpf.Ui;

namespace BlueCatKoKo.Ui
Expand All @@ -37,7 +34,7 @@ public partial class App : Application
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(
"log.txt", rollingInterval: RollingInterval.Day,encoding:Encoding.UTF8
"log.txt", rollingInterval: RollingInterval.Day, encoding: Encoding.UTF8
)
.CreateLogger();
logging.Services.AddSingleton(Log.Logger);
Expand All @@ -46,7 +43,27 @@ public partial class App : Application
{
container.AddHostedService<ApplicationHostService>();
// configuration
container.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
// 绑定 AppConfig 配置段
var appConfig = new AppConfig();
context.Configuration.GetSection(nameof(AppConfig)).Bind(appConfig);

// 获取程序集版本
var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString();

appConfig.Version = version; // 将版本赋值给 AppConfig

// container.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));

container.AddSingleton(appConfig);
container.Configure<AppConfig>(config =>
{
config.Name = appConfig.Name;
config.TrayTitle = appConfig.TrayTitle;
config.Description = appConfig.Description;
config.DownloadPath = appConfig.DownloadPath;
config.RepositoryUrl = appConfig.RepositoryUrl;
config.Version = appConfig.Version;
});
container.AddSingleton<AppConfigService>();

// Service containing
Expand Down
2 changes: 1 addition & 1 deletion src/BlueCatKoKo.Ui/BlueCatKoKo.Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ApplicationIcon>applicationIcon.ico</ApplicationIcon>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyName>BlueCatKoKo</AssemblyName>
<AssemblyVersion>1.2.5</AssemblyVersion>
<AssemblyVersion>1.2.6.0</AssemblyVersion>
<UseWPF>true</UseWPF>
<MvvmToolkitEnableINotifyPropertyChangingSupport>false</MvvmToolkitEnableINotifyPropertyChangingSupport>

Expand Down
1 change: 0 additions & 1 deletion src/BlueCatKoKo.Ui/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"AppConfig": {
"Name": "BlueCatKoKo",
"TrayTitle": "BlueCatKoKo-DY-Downloader",
"Version": "v1.2.5",
"Description": "BlueCatKoKo is a Douyin Downloader",
"DownloadPath": "./",
"RepositoryUrl": "https://github.com/K12f/BlueCatKoKo",
Expand Down

0 comments on commit 9508387

Please sign in to comment.