44using Microsoft . Extensions . Logging ;
55using Serilog ;
66using System . IO ;
7- using System . Net ;
8- using System . Net . Http ;
9- using System . Runtime . InteropServices ;
7+ using Windows . Win32 ;
108using System . Windows . Threading ;
11- using PipManager . Core . Services . PackageSearchService ;
9+ using PipManager . Core . Services ;
10+ using PipManager . Windows . Extensions ;
1211using PipManager . Windows . Services ;
13- using PipManager . Windows . Services . Action ;
14- using PipManager . Windows . Services . Environment ;
15- using PipManager . Windows . Services . Mask ;
16- using PipManager . Windows . Services . Overlay ;
17- using PipManager . Windows . Services . Toast ;
18- using PipManager . Windows . ViewModels . Pages . Action ;
19- using PipManager . Windows . ViewModels . Pages . Environment ;
20- using PipManager . Windows . ViewModels . Pages . Lab ;
21- using PipManager . Windows . ViewModels . Pages . Library ;
22- using PipManager . Windows . ViewModels . Pages . Overlay ;
23- using PipManager . Windows . ViewModels . Pages . Search ;
24- using PipManager . Windows . ViewModels . Pages . Tools ;
2512using PipManager . Windows . ViewModels . Windows ;
26- using PipManager . Windows . Views . Pages . About ;
27- using PipManager . Windows . Views . Pages . Action ;
28- using PipManager . Windows . Views . Pages . Environment ;
29- using PipManager . Windows . Views . Pages . Lab ;
30- using PipManager . Windows . Views . Pages . Library ;
31- using PipManager . Windows . Views . Pages . Overlay ;
32- using PipManager . Windows . Views . Pages . Search ;
33- using PipManager . Windows . Views . Pages . Settings ;
34- using PipManager . Windows . Views . Pages . Tools ;
3513using PipManager . Windows . Views . Windows ;
36- using Wpf . Ui ;
3714
3815namespace PipManager . Windows ;
3916
40- using AboutViewModel = ViewModels . Pages . About . AboutViewModel ;
41- using SettingsViewModel = ViewModels . Pages . Settings . SettingsViewModel ;
42-
43- /// <summary>
44- /// Interaction logic for App.xaml
45- /// </summary>
4617public partial class App
4718{
4819 private static readonly IHost Host = Microsoft . Extensions . Hosting . Host
@@ -57,90 +28,25 @@ public partial class App
5728 {
5829 services . AddHostedService < ApplicationHostService > ( ) ;
5930
60- services . AddTransient ( _ =>
61- {
62- var client = new HttpClient ( new HttpClientHandler { AutomaticDecompression = DecompressionMethods . All } ) { DefaultRequestVersion = HttpVersion . Version20 } ;
63- client . DefaultRequestHeaders . Add ( "User-Agent" , $ "PipManager.Windows/{ AppInfo . AppVersion } ") ;
64- client . Timeout = TimeSpan . FromSeconds ( 6 ) ;
65- return client ;
66- } ) ;
31+ services . AddHttpClient ( AppInfo . AppVersion ) ;
6732
68- // Window
6933 services . AddSingleton < MainWindow > ( ) ;
7034 services . AddSingleton < MainWindowViewModel > ( ) ;
71-
72- // Services
73- services . AddSingleton < INavigationService , NavigationService > ( ) ;
74- services . AddSingleton < ISnackbarService , SnackbarService > ( ) ;
75- services . AddSingleton < IMaskService , MaskService > ( ) ;
76- services . AddSingleton < IToastService , ToastService > ( ) ;
77- services . AddSingleton < IEnvironmentService , EnvironmentService > ( ) ;
78- services . AddSingleton < IActionService , ActionService > ( ) ;
79- services . AddSingleton < IThemeService , ThemeService > ( ) ;
80- services . AddSingleton < IContentDialogService , ContentDialogService > ( ) ;
81- services . AddSingleton < ITaskBarService , TaskBarService > ( ) ;
82- services . AddSingleton < IPackageSearchService , PackageSearchService > ( ) ;
83- services . AddSingleton < IOverlayService , OverlayService > ( ) ;
84-
85- // Pages
86- services . AddSingleton < LibraryPage > ( ) ;
87- services . AddSingleton < LibraryViewModel > ( ) ;
88- services . AddSingleton < LibraryDetailPage > ( ) ;
89- services . AddSingleton < LibraryDetailViewModel > ( ) ;
90- services . AddSingleton < LibraryInstallPage > ( ) ;
91- services . AddSingleton < LibraryInstallViewModel > ( ) ;
92-
93- services . AddSingleton < OverlayPage > ( ) ;
94- services . AddSingleton < OverlayViewModel > ( ) ;
95-
96- services . AddSingleton < ActionPage > ( ) ;
97- services . AddSingleton < ActionViewModel > ( ) ;
98- services . AddSingleton < ActionExceptionPage > ( ) ;
99- services . AddSingleton < ActionExceptionViewModel > ( ) ;
100-
101- services . AddSingleton < SearchPage > ( ) ;
102- services . AddSingleton < SearchViewModel > ( ) ;
103- services . AddSingleton < SearchDetailPage > ( ) ;
104- services . AddSingleton < SearchDetailViewModel > ( ) ;
105-
106- services . AddSingleton < ToolsPage > ( ) ;
107- services . AddSingleton < ToolsViewModel > ( ) ;
10835
109- services . AddSingleton < LabPage > ( ) ;
110- services . AddSingleton < LabViewModel > ( ) ;
111-
112- services . AddSingleton < EnvironmentPage > ( ) ;
113- services . AddSingleton < EnvironmentViewModel > ( ) ;
114- services . AddSingleton < AddEnvironmentPage > ( ) ;
115- services . AddSingleton < AddEnvironmentViewModel > ( ) ;
116-
117- services . AddSingleton < SettingsPage > ( ) ;
118- services . AddSingleton < SettingsViewModel > ( ) ;
119- services . AddSingleton < AboutPage > ( ) ;
120- services . AddSingleton < AboutViewModel > ( ) ;
36+ services . RegisterServices ( ) ;
37+ services . RegisterViews ( ) ;
38+ services . RegisterViewModels ( ) ;
12139 } ) . Build ( ) ;
12240
123- /// <summary>
124- /// Gets registered service.
125- /// </summary>
126- /// <typeparam name="T">Type of the service to get.</typeparam>
127- /// <returns>Instance of the service or <see langword="null"/>.</returns>
12841 public static T GetService < T > ( )
12942 where T : class
13043 {
13144 return Host . Services . GetService ( typeof ( T ) ) as T ?? throw new InvalidOperationException ( "Service not found." ) ;
13245 }
13346
134- [ LibraryImport ( "kernel32.dll" ) ]
135- [ return : MarshalAs ( UnmanagedType . Bool ) ]
136- private static partial void FreeConsole ( ) ;
137-
13847 private bool _showConsoleWindow ;
13948 public static bool IsDebugMode { get ; private set ; }
14049
141- /// <summary>
142- /// Occurs when the application is loading.
143- /// </summary>
14450 private void OnStartup ( object sender , StartupEventArgs e )
14551 {
14652 Environment . SetEnvironmentVariable ( "WEBVIEW2_USER_DATA_FOLDER" , AppInfo . CachesDir ) ;
@@ -154,35 +60,26 @@ private void OnStartup(object sender, StartupEventArgs e)
15460 break ;
15561 }
15662 }
63+ IsDebugMode = _showConsoleWindow ;
15764 var appStarting = new AppStarting
15865 {
15966 ShowConsoleWindow = _showConsoleWindow
16067 } ;
16168 appStarting . StartLogging ( ) ;
162- appStarting . LoadLanguage ( ) ;
163- appStarting . CachesDeletion ( ) ;
69+ AppStarting . LoadLanguage ( ) ;
70+ AppStarting . CachesDeletion ( ) ;
16471 Host . Start ( ) ;
165- IsDebugMode = _showConsoleWindow ;
16672 }
16773
168- /// <summary>
169- /// Occurs when the application is closing.
170- /// </summary>
17174 private async void OnExit ( object sender , ExitEventArgs e )
17275 {
173- if ( _showConsoleWindow )
174- {
175- FreeConsole ( ) ;
176- }
76+ if ( _showConsoleWindow ) PInvoke . FreeConsole ( ) ;
17777 await Host . StopAsync ( ) ;
17878 Host . Dispose ( ) ;
17979 Log . Information ( "Logging ended" ) ;
18080 await Log . CloseAndFlushAsync ( ) ;
18181 }
18282
183- /// <summary>
184- /// Occurs when an exception is thrown by an application but not handled.
185- /// </summary>
18683 private void OnDispatcherUnhandledException ( object sender , DispatcherUnhandledExceptionEventArgs e )
18784 {
18885 Log . Error ( $ "Exception: { e . Exception } ") ;
0 commit comments