@@ -126,7 +126,7 @@ private void Initialize()
126
126
CheckForNewVersion ( ) ;
127
127
InitializeDisplayManager ( ) ;
128
128
InitializeAudioManager ( ) ;
129
- Globals . Instance . SaveSettings ( ) ;
129
+ Globals . Instance . SaveSettings ( ) ;
130
130
InitializeTrayMenuHelper ( ) ;
131
131
CreateRelayCommands ( ) ;
132
132
ShowView = ! Settings . StartMinimizedToTray ;
@@ -169,8 +169,8 @@ private void UpdateCurrentProfile(ApplicationItem application, ApplicationChange
169
169
170
170
if ( profile == null )
171
171
return ;
172
- bool profileChanged = Equals ( profile , CurrentProfile ) ;
173
-
172
+ bool profileChanged = Equals ( profile , CurrentProfile ) ;
173
+
174
174
CurrentProfile = profile ;
175
175
if ( profileChanged )
176
176
Globals . Logs . Add ( $ "Profile changed to { profile . Name } ", false ) ;
@@ -206,7 +206,7 @@ private void UpdateCurrentProfile(ApplicationItem application, ApplicationChange
206
206
CurrentProfile = null ;
207
207
}
208
208
}
209
-
209
+
210
210
private void ActionLog ( object sender , LogEntry entry )
211
211
{
212
212
Globals . Logs . AppendLogEntry ( entry ) ;
@@ -262,7 +262,7 @@ private void CreateRelayCommands()
262
262
ActivateHDRCommand = new RelayCommand ( DisplayManager . Instance . ActivateHDR ) ;
263
263
DeactivateHDRCommand = new RelayCommand ( DisplayManager . Instance . DeactivateHDR ) ;
264
264
AddAssignmentCommand = new RelayCommand ( AddAssignment ) ;
265
- EditApplicationCommand = new RelayCommand < ApplicationProfileAssignment > ( EditApplication ) ;
265
+ EditApplicationCommand = new RelayCommand < ApplicationProfileAssignment > ( EditApplication ) ;
266
266
RemoveAssignmentCommand = new RelayCommand < ApplicationProfileAssignment > ( RemoveAssignment ) ;
267
267
268
268
MoveAssignmentUpCommand = new RelayCommand < ApplicationProfileAssignment > ( MoveAssignmentUp ) ;
@@ -307,6 +307,7 @@ private void LoadSettings()
307
307
{
308
308
Globals . Instance . LoadSettings ( ) ;
309
309
FixAssignments ( ) ;
310
+ Globals . Instance . SaveSettings ( ) ;
310
311
Settings . ApplicationProfileAssignments . Sort ( a => a . Position , ListSortDirection . Ascending ) ;
311
312
Settings . ApplicationProfileAssignments . CollectionChanged += ApplicationProfileAssigments_CollectionChanged ;
312
313
Settings . ApplicationProfiles . CollectionChanged += ApplicationProfiles_CollectionChanged ;
@@ -317,9 +318,9 @@ private void LoadSettings()
317
318
ApplicationProfileAssigments_CollectionChanged (
318
319
Settings . ApplicationProfileAssignments , new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , Settings . ApplicationProfileAssignments . ToList ( ) ) ) ;
319
320
320
- ApplicationProfiles_CollectionChanged ( Settings . ApplicationProfiles , new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , Settings . ApplicationProfiles . ToList ( ) ) ) ;
321
+ ApplicationProfiles_CollectionChanged ( Settings . ApplicationProfiles , new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , Settings . ApplicationProfiles . ToList ( ) ) ) ;
321
322
322
- Monitors_CollectionChanged ( Settings . Monitors , new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , Settings . Monitors . ToList ( ) ) ) ;
323
+ Monitors_CollectionChanged ( Settings . Monitors , new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , Settings . Monitors . ToList ( ) ) ) ;
323
324
324
325
325
326
Globals . Logs . LogFileEnabled = Settings . CreateLogFile ;
@@ -353,7 +354,7 @@ private void FixAssignments()
353
354
do
354
355
{
355
356
assignment . Position = assignment . Position - 1 ;
356
- } while ( Settings . ApplicationProfileAssignments . Count ( a => a . Position == assignment . Position ) > 1 ) ;
357
+ } while ( Settings . ApplicationProfileAssignments . Count ( a => a . Position == assignment . Position ) > 1 ) ;
357
358
}
358
359
}
359
360
@@ -374,7 +375,7 @@ private void StartApplication(ApplicationItem application)
374
375
DisplayManager . Instance . ActivateHDR ( ) ;
375
376
System . Threading . Thread . Sleep ( 2500 ) ;
376
377
application . StartApplication ( ) ;
377
-
378
+
378
379
}
379
380
catch ( Exception ex )
380
381
{
@@ -419,7 +420,7 @@ public void Start()
419
420
DisplayManager . Instance . StartMonitoring ( ) ;
420
421
Globals . Logs . Add ( $ "HDR Monitoring started", false ) ;
421
422
Started = true ;
422
- // UpdateHDRModeBasedOnCurrentApplication();
423
+ // UpdateHDRModeBasedOnCurrentApplication();
423
424
}
424
425
}
425
426
@@ -451,7 +452,9 @@ private void AddAssignment()
451
452
{
452
453
if ( ! Settings . ApplicationProfileAssignments . Any ( pi => pi . Application . ApplicationFilePath == adder . ApplicationItem . ApplicationFilePath ) )
453
454
{
454
- ApplicationProfileAssignment . NewAssigment ( adder . ApplicationItem ) ;
455
+ var assignment = ApplicationProfileAssignment . NewAssigment ( adder . ApplicationItem ) ;
456
+ if ( Settings . DefaultProfile != null )
457
+ assignment . Profile = Settings . DefaultProfile ;
455
458
}
456
459
Settings . ApplicationProfileAssignments . Sort ( x => x . Position , System . ComponentModel . ListSortDirection . Ascending ) ;
457
460
@@ -615,76 +618,86 @@ private void ProfileActions_CollectionChanged(object sender, NotifyCollectionCha
615
618
Globals . Instance . SaveSettings ( ) ;
616
619
}
617
620
621
+ readonly object _lockAssignments = new object ( ) ;
622
+
618
623
private void ApplicationProfileAssigments_CollectionChanged ( object sender , NotifyCollectionChangedEventArgs e )
619
624
{
620
- SortableObservableCollection < ApplicationProfileAssignment > collection = ( SortableObservableCollection < ApplicationProfileAssignment > ) sender ;
621
- switch ( e . Action )
625
+ bool taken = Monitor . TryEnter ( _lockAssignments ) ;
626
+ if ( ! taken )
627
+ return ;
628
+ try
622
629
{
623
- case NotifyCollectionChangedAction . Add :
624
-
625
- foreach ( ApplicationProfileAssignment assignment in e . NewItems )
626
- {
630
+ SortableObservableCollection < ApplicationProfileAssignment > collection = ( SortableObservableCollection < ApplicationProfileAssignment > ) sender ;
631
+ switch ( e . Action )
632
+ {
633
+ case NotifyCollectionChangedAction . Add :
627
634
635
+ foreach ( ApplicationProfileAssignment assignment in e . NewItems )
636
+ {
628
637
629
- Globals . Logs . Add ( $ "Application added: { assignment . Application . ApplicationName } ", false ) ;
630
- assignment . PropertyChanged += SaveSettingsOnPropertyChanged ;
631
- ApplicationWatcher . AddProcess ( assignment . Application ) ;
632
- assignment . Application . PropertyChanged += SaveSettingsOnPropertyChanged ;
633
- }
634
-
635
- break ;
636
- case NotifyCollectionChangedAction . Remove :
637
- foreach ( ApplicationProfileAssignment assignment in e . OldItems )
638
- {
639
- Globals . Logs . Add ( $ "Application removed: { assignment . Application . ApplicationName } ", false ) ;
640
- assignment . PropertyChanged -= SaveSettingsOnPropertyChanged ;
641
638
639
+ Globals . Logs . Add ( $ "Application added: { assignment . Application . ApplicationName } ", false ) ;
640
+ assignment . PropertyChanged += SaveSettingsOnPropertyChanged ;
641
+ ApplicationWatcher . AddProcess ( assignment . Application ) ;
642
+ assignment . Application . PropertyChanged += SaveSettingsOnPropertyChanged ;
643
+ }
642
644
643
- int removedPosition = assignment . Position ;
644
- foreach ( ApplicationProfileAssignment a in collection )
645
+ break ;
646
+ case NotifyCollectionChangedAction . Remove :
647
+ foreach ( ApplicationProfileAssignment assignment in e . OldItems )
645
648
{
646
- if ( a . Position >= removedPosition )
647
- a . Position = a . Position - 1 ;
649
+ Globals . Logs . Add ( $ "Application removed: { assignment . Application . ApplicationName } ", false ) ;
650
+ assignment . PropertyChanged -= SaveSettingsOnPropertyChanged ;
651
+
652
+
653
+ int removedPosition = assignment . Position ;
654
+ foreach ( ApplicationProfileAssignment a in collection )
655
+ {
656
+ if ( a . Position >= removedPosition )
657
+ a . Position = a . Position - 1 ;
658
+ }
659
+ ApplicationWatcher . RemoveProcess ( assignment . Application ) ;
660
+ assignment . Application . PropertyChanged -= SaveSettingsOnPropertyChanged ;
648
661
}
649
- ApplicationWatcher . RemoveProcess ( assignment . Application ) ;
650
- assignment . Application . PropertyChanged -= SaveSettingsOnPropertyChanged ;
651
- }
652
662
653
- break ;
654
- case NotifyCollectionChangedAction . Move :
663
+ break ;
664
+ case NotifyCollectionChangedAction . Move :
665
+ int downFrom = e . NewStartingIndex ;
666
+ int upFrom = e . OldStartingIndex ;
655
667
656
- int up , down , delta ;
668
+ if ( e . OldStartingIndex == e . NewStartingIndex )
669
+ break ;
657
670
658
- if ( e . OldStartingIndex < e . NewStartingIndex )
659
- {
660
- up = e . OldStartingIndex + 1 ;
661
- down = e . NewStartingIndex ;
662
- delta = - 1 ;
663
- }
664
- else
665
- {
666
- up = e . NewStartingIndex ;
667
- down = e . OldStartingIndex - 1 ;
668
- delta = 1 ;
669
- }
670
671
671
- foreach ( ApplicationProfileAssignment assingment in collection )
672
- {
673
- int position = assingment . Position ;
674
- if ( position == e . OldStartingIndex )
675
- {
676
- assingment . Position = e . NewStartingIndex ;
677
- }
678
- else if ( down <= position && position <= up )
672
+
673
+ foreach ( ApplicationProfileAssignment assingment in collection )
679
674
{
680
- assingment . Position = position + delta ;
675
+ int position = assingment . Position ;
676
+ if ( position == e . OldStartingIndex )
677
+ {
678
+ assingment . Position = e . NewStartingIndex ;
679
+ }
680
+ else if ( e . OldStartingIndex > e . NewStartingIndex && position < e . OldStartingIndex && position >= e . NewStartingIndex )
681
+ {
682
+ assingment . Position = position + 1 ;
683
+ }
684
+ else if ( e . OldStartingIndex < e . NewStartingIndex && position > e . OldStartingIndex && position <= e . NewStartingIndex )
685
+ {
686
+ assingment . Position = position - 1 ;
687
+ }
681
688
}
682
- }
683
- break ;
689
+
690
+ break ;
691
+ }
692
+ Globals . Instance . SaveSettings ( ) ;
693
+ }
694
+ finally
695
+ {
696
+ if ( taken )
697
+ Monitor . Exit ( _lockAssignments ) ;
684
698
}
685
- Globals . Instance . SaveSettings ( ) ;
686
699
}
687
-
700
+
688
701
689
702
690
703
private void SaveSettingsOnPropertyChanged ( object sender , PropertyChangedEventArgs e )
0 commit comments