diff --git a/CRSim.Core/Abstractions/ISettingsService.cs b/CRSim.Core/Abstractions/ISettingsService.cs index 4da8723..173c1ef 100644 --- a/CRSim.Core/Abstractions/ISettingsService.cs +++ b/CRSim.Core/Abstractions/ISettingsService.cs @@ -9,6 +9,7 @@ namespace CRSim.Core.Abstractions { public interface ISettingsService { + void LoadSettings(); void SaveSettings(); Settings GetSettings(); } diff --git a/CRSim.Core/Services/DatabaseService.cs b/CRSim.Core/Services/DatabaseService.cs index c4719ac..979945b 100644 --- a/CRSim.Core/Services/DatabaseService.cs +++ b/CRSim.Core/Services/DatabaseService.cs @@ -11,11 +11,6 @@ namespace CRSim.Core.Services private List _stations; private List _trainNumbers; - public DatabaseService() - { - ImportData(AppPaths.ConfigFilePath); - } - public List GetAllStations() { return _stations; diff --git a/CRSim.Core/Services/SettingsService.cs b/CRSim.Core/Services/SettingsService.cs index 7bc6022..385ff77 100644 --- a/CRSim.Core/Services/SettingsService.cs +++ b/CRSim.Core/Services/SettingsService.cs @@ -9,10 +9,6 @@ namespace CRSim.Core.Services { private Settings _settings; private RegistryKey _key = Registry.CurrentUser.OpenSubKey(@"Software\CRSim\Settings",true); - public SettingsService() - { - LoadSettings(); - } public void SaveSettings() { _key.SetValue("SwitchPageSeconds", _settings.SwitchPageSeconds); @@ -27,7 +23,7 @@ namespace CRSim.Core.Services _key.SetValue("LoadTodayOnly", _settings.LoadTodayOnly); _key.SetValue("ReopenUnclosedScreensOnLoad", _settings.ReopenUnclosedScreensOnLoad); } - private void LoadSettings() + public void LoadSettings() { if (_key==null) { diff --git a/CRSim/App.xaml.cs b/CRSim/App.xaml.cs index 64403ac..4123f7d 100644 --- a/CRSim/App.xaml.cs +++ b/CRSim/App.xaml.cs @@ -5,11 +5,13 @@ public static IHost AppHost { get; private set; } public static MainWindow MainWindow; public string[] commandLineArgs; + public CommandLineOptions parsedOptions; + public static string AppVersion { get; set; } = Assembly.GetAssembly(typeof(App)).GetName().Version.ToString(); public App() { var args = Environment.GetCommandLineArgs(); - var parsedOptions = CommandLineParser.Parse(args); + parsedOptions = CommandLineParser.Parse(args); if (parsedOptions.Debug) { LaunchDebugConsole(); @@ -27,25 +29,64 @@ services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddTransient(); services.AddSingleton(); services.AddSingleton(); - services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); PluginService.InitializePlugins(context, services, parsedOptions.ExternalPluginPath); }) - .Build(); + .Build(); InitializeComponent(); } protected override void OnLaunched(LaunchActivatedEventArgs args) { - MainWindow = AppHost.Services.GetService(); - MainWindow?.Activate(); - AppHost.Services.GetService();//init + ShowSplashScreen(); + } + + private void ShowSplashScreen() + { + var splashScreenWindow = AppHost.Services.GetService(); + splashScreenWindow.SplashScreenClosed += OnSplashScreenClosed; + splashScreenWindow.Activate(); + _ = PerformInitializationAsync(splashScreenWindow); + } + + private static async Task PerformInitializationAsync(StartWindow splashScreen) + { + try + { + var startWindow = AppHost.Services.GetService(); + await Task.Delay(2000); + startWindow.Status = "正在加载设置..."; + AppHost.Services.GetService().LoadSettings(); + await Task.Delay(500); + startWindow.Status = "正在加载数据库..."; + AppHost.Services.GetService().ImportData(AppPaths.ConfigFilePath); + await Task.Delay(500); + startWindow.Status = new[] { "正在控票…", "正在关闭垃圾桶盖…", "正在刷绿车底…", "正在准备降弓用刑…" }[new Random().Next(4)]; + await Task.Delay(500); + } + catch (Exception ex) + { + Console.WriteLine($"初始化错误: {ex.Message}"); + } + finally + { + splashScreen.CompleteInitialization(); + } + } + + private void OnSplashScreenClosed(object sender, EventArgs e) + { + var mainWindow = AppHost.Services.GetService(); + mainWindow.Activate(); + MainWindow = mainWindow; } [System.Runtime.InteropServices.DllImport("kernel32.dll")] @@ -61,7 +102,7 @@ ( __|_|_[___[___[___[__] =-(_)--(_)--' (O) (O) "); Console.ForegroundColor = ConsoleColor.Gray; - Console.WriteLine(" CRSim - 国铁信息显示模拟"); + Console.WriteLine(" CRSim - 国铁信息显示模拟 v" + AppVersion); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Debug console started.\n"); Console.ForegroundColor = ConsoleColor.White; diff --git a/CRSim/Assets/Background/CRSim.wmv b/CRSim/Assets/Background/CRSim.wmv new file mode 100644 index 0000000..34dc185 Binary files /dev/null and b/CRSim/Assets/Background/CRSim.wmv differ diff --git a/CRSim/Assets/Background/SplashScreenBackground.png b/CRSim/Assets/Background/SplashScreenBackground.png new file mode 100644 index 0000000..c40ac54 Binary files /dev/null and b/CRSim/Assets/Background/SplashScreenBackground.png differ diff --git a/CRSim/CRSim.csproj b/CRSim/CRSim.csproj index 9e70328..cf1d521 100644 --- a/CRSim/CRSim.csproj +++ b/CRSim/CRSim.csproj @@ -24,6 +24,7 @@ + @@ -56,6 +57,7 @@ + @@ -104,6 +106,9 @@ True \ + + MSBuild:Compile + MSBuild:Compile diff --git a/CRSim/Properties/GlobalUsing.cs b/CRSim/Properties/GlobalUsing.cs index 1493cd7..71cc718 100644 --- a/CRSim/Properties/GlobalUsing.cs +++ b/CRSim/Properties/GlobalUsing.cs @@ -6,9 +6,12 @@ global using System.Text.Json; global using System.Threading.Tasks; global using System.Collections.Generic; global using System.Collections.ObjectModel; +global using System.Reflection; +global using System.Timers; global using Microsoft.UI.Xaml; global using Microsoft.UI.Xaml.Controls; +global using Microsoft.UI.Dispatching; global using Microsoft.UI.Windowing; global using Microsoft.Extensions.Hosting; global using Microsoft.Extensions.DependencyInjection; @@ -26,4 +29,8 @@ global using CRSim.Core.Models; global using CRSim.Core.Services; global using CRSim.Core.Abstractions; -global using OfficeOpenXml; \ No newline at end of file +global using OfficeOpenXml; + +global using CommunityToolkit.WinUI; + +global using Windows.Graphics; \ No newline at end of file diff --git a/CRSim/Views/StartWindow.xaml b/CRSim/Views/StartWindow.xaml new file mode 100644 index 0000000..383dc19 --- /dev/null +++ b/CRSim/Views/StartWindow.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/CRSim/Views/StartWindow.xaml.cs b/CRSim/Views/StartWindow.xaml.cs new file mode 100644 index 0000000..7a27a3f --- /dev/null +++ b/CRSim/Views/StartWindow.xaml.cs @@ -0,0 +1,71 @@ +using System.ComponentModel; + +namespace CRSim.Views +{ + // ¼ί + public delegate void SplashScreenClosedEventHandler(object sender, EventArgs e); + + public sealed partial class StartWindow : Window, INotifyPropertyChanged + { + // ¼ + public event SplashScreenClosedEventHandler SplashScreenClosed; + public string AppVersion { get; set; } = App.AppVersion; + + private string _status = "..."; + public string Status + { + get => _status; + set + { + if (_status != value) + { + _status = value; + OnPropertyChanged(nameof(Status)); + } + } + } + + public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged; + + private void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); + } + + public StartWindow() + { + this.InitializeComponent(); + + AppWindow.Resize(new Windows.Graphics.SizeInt32(750, 270)); + var area = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest)?.WorkArea; + if (area != null) + { + AppWindow.Move(new PointInt32((area.Value.Width - AppWindow.Size.Width) / 2, (area.Value.Height - AppWindow.Size.Height) / 2)); + } + + + OverlappedPresenter presenter = OverlappedPresenter.Create(); + + presenter.IsAlwaysOnTop = true; + presenter.IsMaximizable = false; + presenter.IsMinimizable = false; + presenter.IsResizable = false; + presenter.SetBorderAndTitleBar(true, false); + + AppWindow.SetPresenter(presenter); + + AppWindow.MoveInZOrderAtTop(); + + Logo.MediaPlayer.Play(); + + + } + + // ɳʼر + public void CompleteInitialization() + { + SplashScreenClosed?.Invoke(this, EventArgs.Empty); + this.Close(); + } + } +}