@@ -122,20 +122,31 @@ private void UnRegisterTriggers(Profile profile)
122
122
/// Initialize the profile manager. Return the list of Profile that it couldn't register hotkeys for.
123
123
/// </summary>
124
124
/// <returns></returns>
125
- public Result < Profile [ ] , VoidSuccess > Init ( )
125
+ public Result < ProfileError [ ] , VoidSuccess > Init ( )
126
126
{
127
- var errors = AppConfigs . Configuration . Profiles . Where ( profile => ! RegisterTriggers ( profile , true ) ) . ToArray ( ) ;
128
-
127
+ var errors = Array . Empty < ProfileError > ( ) ;
129
128
try
130
129
{
131
- RegisterEvents ( ) ;
130
+ errors = AppConfigs . Configuration . Profiles . Select ( profile => ( Profile : profile , Failure : ValidateProfile ( profile , true ) . UnwrapFailure ( ) ) )
131
+ . Select ( tuple =>
132
+ {
133
+ if ( tuple . Failure == null )
134
+ {
135
+ RegisterTriggers ( tuple . Profile , true ) ;
136
+ }
132
137
133
- InitializeProfileExistingProcess ( ) ;
138
+ return tuple ;
139
+ } )
140
+ . Where ( tuple => tuple . Failure != null )
141
+ . Select ( tuple => new ProfileError ( tuple . Profile , tuple . Failure ) )
142
+ . ToArray ( ) ;
134
143
144
+ RegisterEvents ( ) ;
145
+ InitializeProfileExistingProcess ( ) ;
135
146
136
147
if ( errors . Length > 0 )
137
148
{
138
- _logger . Warning ( "Couldn't initiate all profiles: {profiles}" , errors . Select ( profile => profile . Name ) ) ;
149
+ _logger . Warning ( "Couldn't initiate all profiles: {profiles}" , errors ) ;
139
150
return errors ;
140
151
}
141
152
@@ -163,7 +174,6 @@ private void RegisterEvents()
163
174
164
175
WindowsAPIAdapter . WindowDestroyed += ( sender , @event ) => { RestoreState ( @event . Hwnd ) ; } ;
165
176
_logger . Information ( "Windows Destroyed Registered" ) ;
166
-
167
177
}
168
178
169
179
private bool HandleUwpApp ( WindowMonitor . Event @event )
@@ -386,7 +396,7 @@ public Result<string, VoidSuccess> UpdateProfile(Profile oldProfile, Profile new
386
396
} ) ;
387
397
}
388
398
389
- private Result < string , VoidSuccess > ValidateProfile ( Profile profile )
399
+ private Result < string , VoidSuccess > ValidateProfile ( Profile profile , bool init = false )
390
400
{
391
401
if ( string . IsNullOrEmpty ( profile . Name ) )
392
402
{
@@ -403,7 +413,7 @@ private Result<string, VoidSuccess> ValidateProfile(Profile profile)
403
413
return SettingsStrings . profile_error_needPlaybackOrRecording ;
404
414
}
405
415
406
- if ( AppConfigs . Configuration . Profiles . Contains ( profile ) )
416
+ if ( ! init && AppConfigs . Configuration . Profiles . Contains ( profile ) )
407
417
{
408
418
return string . Format ( SettingsStrings . profile_error_name , profile . Name ) ;
409
419
}
0 commit comments