Skip to content

Commit b33ceff

Browse files
authored
Fix issue causing user settings to be repeatedly reloaded from file in some cases (#9669)
* Move semaphore out of App.cs * Update settingsCache on missing value
1 parent e99b055 commit b33ceff

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/Files.Uwp/App.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
using System.Diagnostics;
3131
using System.IO;
3232
using System.Linq;
33-
using System.Threading;
3433
using System.Threading.Tasks;
3534
using Windows.ApplicationModel;
3635
using Windows.ApplicationModel.Activation;
@@ -54,7 +53,6 @@ sealed partial class App : Application
5453
private static bool ShowErrorNotification = false;
5554
private static string OutputPath = null;
5655

57-
public static SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1, 1);
5856
public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper();
5957
public static SettingsViewModel AppSettings { get; private set; }
6058
public static MainViewModel MainViewModel { get; private set; }

src/Files.Uwp/Filesystem/StorageHistory/Helpers/StorageHistoryHelpers.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Files.Shared.Enums;
22
using System;
3+
using System.Threading;
34
using System.Threading.Tasks;
45

56
namespace Files.Uwp.Filesystem.FilesystemHistory
@@ -8,14 +9,16 @@ public class StorageHistoryHelpers : IDisposable
89
{
910
private IStorageHistoryOperations operations;
1011

12+
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
13+
1114
public StorageHistoryHelpers(IStorageHistoryOperations storageHistoryOperations)
1215
=> operations = storageHistoryOperations;
1316

1417
public async Task<ReturnResult> TryUndo()
1518
{
1619
if (App.HistoryWrapper.CanUndo())
1720
{
18-
if (!await App.SemaphoreSlim.WaitAsync(0))
21+
if (!await semaphore.WaitAsync(0))
1922
{
2023
return ReturnResult.InProgress;
2124
}
@@ -26,7 +29,7 @@ public async Task<ReturnResult> TryUndo()
2629
finally
2730
{
2831
App.HistoryWrapper.DecreaseIndex();
29-
App.SemaphoreSlim.Release();
32+
semaphore.Release();
3033
}
3134
}
3235

@@ -37,7 +40,7 @@ public async Task<ReturnResult> TryRedo()
3740
{
3841
if (App.HistoryWrapper.CanRedo())
3942
{
40-
if (!await App.SemaphoreSlim.WaitAsync(0))
43+
if (!await semaphore.WaitAsync(0))
4144
{
4245
return ReturnResult.InProgress;
4346
}
@@ -48,7 +51,7 @@ public async Task<ReturnResult> TryRedo()
4851
}
4952
finally
5053
{
51-
App.SemaphoreSlim.Release();
54+
semaphore.Release();
5255
}
5356
}
5457

src/Files.Uwp/Serialization/Implementation/CachingJsonSettingsDatabase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public CachingJsonSettingsDatabase(ISettingsSerializer settingsSerializer, IJson
2525
}
2626
else
2727
{
28-
base.SetValue(key, defaultValue);
28+
if (base.SetValue(key, defaultValue))
29+
{
30+
_settingsCache.Add(key, defaultValue);
31+
}
2932
return defaultValue;
3033
}
3134
}

0 commit comments

Comments
 (0)