4
4
using Files . Filesystem ;
5
5
using Files . Filesystem . FilesystemHistory ;
6
6
using Files . Helpers ;
7
- using Files . Models . Settings ;
8
- using Files . SettingsInterfaces ;
7
+ using Files . Services ;
8
+ using Files . Services . Implementation ;
9
9
using Files . UserControls . MultitaskingControl ;
10
10
using Files . ViewModels ;
11
11
using Files . Views ;
12
+ using Microsoft . AppCenter ;
13
+ using Microsoft . AppCenter . Analytics ;
14
+ using Microsoft . AppCenter . Crashes ;
15
+ using Microsoft . Extensions . DependencyInjection ;
16
+ using Microsoft . Toolkit . Mvvm . DependencyInjection ;
12
17
using Microsoft . Toolkit . Uwp ;
13
18
using Microsoft . Toolkit . Uwp . Helpers ;
14
19
using Microsoft . Toolkit . Uwp . Notifications ;
@@ -41,7 +46,6 @@ sealed partial class App : Application
41
46
42
47
public static SemaphoreSlim SemaphoreSlim = new SemaphoreSlim ( 1 , 1 ) ;
43
48
public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper ( ) ;
44
- public static IBundlesSettings BundlesSettings = new BundlesSettingsModel ( ) ;
45
49
public static SettingsViewModel AppSettings { get ; private set ; }
46
50
public static MainViewModel MainViewModel { get ; private set ; }
47
51
public static JumpListManager JumpList { get ; private set ; }
@@ -61,6 +65,10 @@ sealed partial class App : Application
61
65
public static OngoingTasksViewModel OngoingTasksViewModel { get ; } = new OngoingTasksViewModel ( ) ;
62
66
public static SecondaryTileHelper SecondaryTileHelper { get ; private set ; } = new SecondaryTileHelper ( ) ;
63
67
68
+ public static string AppVersion = $ "{ Package . Current . Id . Version . Major } .{ Package . Current . Id . Version . Minor } .{ Package . Current . Id . Version . Build } .{ Package . Current . Id . Version . Revision } ";
69
+
70
+ public IServiceProvider Services { get ; private set ; }
71
+
64
72
public App ( )
65
73
{
66
74
// Initialize logger
@@ -71,12 +79,52 @@ public App()
71
79
InitializeComponent ( ) ;
72
80
Suspending += OnSuspending ;
73
81
LeavingBackground += OnLeavingBackground ;
82
+
74
83
AppServiceConnectionHelper . Register ( ) ;
84
+
85
+ this . Services = ConfigureServices ( ) ;
86
+ Ioc . Default . ConfigureServices ( Services ) ;
87
+ }
88
+
89
+ private IServiceProvider ConfigureServices ( )
90
+ {
91
+ ServiceCollection services = new ServiceCollection ( ) ;
92
+
93
+ services
94
+ // TODO: Loggers:
95
+
96
+ // Settings:
97
+ // Base IUserSettingsService as parent settings store (to get ISettingsSharingContext from)
98
+ . AddSingleton < IUserSettingsService , UserSettingsService > ( )
99
+ // Children settings (from IUserSettingsService)
100
+ . AddSingleton < IFilesAndFoldersSettingsService , FilesAndFoldersSettingsService > ( ( sp ) => new FilesAndFoldersSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
101
+ . AddSingleton < IStartupSettingsService , StartupSettingsService > ( ( sp ) => new StartupSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
102
+ . AddSingleton < IMultitaskingSettingsService , MultitaskingSettingsService > ( ( sp ) => new MultitaskingSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
103
+ . AddSingleton < IWidgetsSettingsService , WidgetsSettingsService > ( ( sp ) => new WidgetsSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
104
+ . AddSingleton < ISidebarSettingsService , SidebarSettingsService > ( ( sp ) => new SidebarSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
105
+ . AddSingleton < IPreferencesSettingsService , PreferencesSettingsService > ( ( sp ) => new PreferencesSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
106
+ . AddSingleton < IAppearanceSettingsService , AppearanceSettingsService > ( ( sp ) => new AppearanceSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
107
+ . AddSingleton < IPreviewPaneSettingsService , PreviewPaneSettingsService > ( ( sp ) => new PreviewPaneSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
108
+ . AddSingleton < ILayoutSettingsService , LayoutSettingsService > ( ( sp ) => new LayoutSettingsService ( sp . GetService < IUserSettingsService > ( ) . GetSharingContext ( ) ) )
109
+ // Settings not related to IUserSettingsService:
110
+ . AddSingleton < IFileTagsSettingsService , FileTagsSettingsService > ( )
111
+ . AddSingleton < IBundlesSettingsService , BundlesSettingsService > ( )
112
+
113
+ // TODO: Dialogs:
114
+
115
+ // TODO: FileSystem operations:
116
+ // (IFilesystemHelpersService, IFilesystemOperationsService)
117
+
118
+ ; // End of service configuration
119
+
120
+
121
+ return services . BuildServiceProvider ( ) ;
75
122
}
76
123
77
124
private static async Task EnsureSettingsAndConfigurationAreBootstrapped ( )
78
125
{
79
126
AppSettings ??= new SettingsViewModel ( ) ;
127
+ RegistryToJsonSettingsMerger . MergeSettings ( ) ;
80
128
81
129
ExternalResourcesHelper ??= new ExternalResourcesHelper ( ) ;
82
130
await ExternalResourcesHelper . LoadSelectedTheme ( ) ;
@@ -92,6 +140,24 @@ private static async Task EnsureSettingsAndConfigurationAreBootstrapped()
92
140
TerminalController ??= new TerminalController ( ) ;
93
141
}
94
142
143
+ private static async void StartAppCenter ( )
144
+ {
145
+ try
146
+ {
147
+ if ( ! AppCenter . Configured )
148
+ {
149
+ var file = await StorageFile . GetFileFromApplicationUriAsync ( new Uri ( @"ms-appx:///Resources/AppCenterKey.txt" ) ) ;
150
+ var lines = await FileIO . ReadTextAsync ( file ) ;
151
+ var obj = Newtonsoft . Json . Linq . JObject . Parse ( lines ) ;
152
+ AppCenter . Start ( ( string ) obj . SelectToken ( "key" ) , typeof ( Analytics ) , typeof ( Crashes ) ) ;
153
+ }
154
+ }
155
+ catch ( Exception ex )
156
+ {
157
+ Logger . Warn ( ex , "AppCenter could not be started." ) ;
158
+ }
159
+ }
160
+
95
161
public static async Task LoadOtherStuffAsync ( )
96
162
{
97
163
// Start off a list of tasks we need to run before we can continue startup
@@ -437,9 +503,16 @@ await Common.Extensions.IgnoreExceptions(async () =>
437
503
438
504
public static void SaveSessionTabs ( ) // Enumerates through all tabs and gets the Path property and saves it to AppSettings.LastSessionPages
439
505
{
440
- if ( AppSettings != null )
506
+ IUserSettingsService userSettingsService = Ioc . Default . GetService < IUserSettingsService > ( ) ;
507
+ IBundlesSettingsService bundlesSettingsService = Ioc . Default . GetService < IBundlesSettingsService > ( ) ;
508
+
509
+ if ( bundlesSettingsService != null )
510
+ {
511
+ bundlesSettingsService . FlushSettings ( ) ;
512
+ }
513
+ if ( userSettingsService ? . StartupSettingsService != null )
441
514
{
442
- AppSettings . LastSessionPages = MainPageViewModel . AppInstances . DefaultIfEmpty ( ) . Select ( tab =>
515
+ userSettingsService . StartupSettingsService . LastSessionTabList = MainPageViewModel . AppInstances . DefaultIfEmpty ( ) . Select ( tab =>
443
516
{
444
517
if ( tab != null && tab . TabItemArguments != null )
445
518
{
@@ -450,7 +523,7 @@ public static void SaveSessionTabs() // Enumerates through all tabs and gets the
450
523
var defaultArg = new TabItemArguments ( ) { InitialPageType = typeof ( PaneHolderPage ) , NavigationArg = "NewTab" . GetLocalized ( ) } ;
451
524
return defaultArg . Serialize ( ) ;
452
525
}
453
- } ) . ToArray ( ) ;
526
+ } ) . ToList ( ) ;
454
527
}
455
528
}
456
529
0 commit comments