Skip to content

Commit a54035f

Browse files
committed
Read settings synchronously
The only await left in SettingsHelper.Read was a 2 byte first run write, and it kept a state machine and a Task on the path that runs at every startup. Read and GetSettings are now sync, and the ReSharper suppression on the ReadAllBytes call goes with them - that inspection only fires inside an async method. Write stays async: Swap retries File.Move ten times with a 20ms delay, and blocking the UI thread for 200ms while a backup holds the file is the failure it exists to avoid.
1 parent 762c3e2 commit a54035f

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/DiffEngineTray.Tests/SettingsHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ await SettingsHelper.Write(
6363
AlwaysKillLockingProcesses = true
6464
});
6565

66-
var result = await SettingsHelper.Read();
66+
var result = SettingsHelper.Read();
6767

6868
await Verify(result);
6969
}

src/DiffEngineTray/LockedFilesHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void Persist() =>
2626
{
2727
try
2828
{
29-
var settings = await SettingsHelper.Read();
29+
var settings = SettingsHelper.Read();
3030
settings.AlwaysKillLockingProcesses = true;
3131
await SettingsHelper.Write(settings);
3232
}

src/DiffEngineTray/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static async Task Inner()
5656
void Warn(string message) =>
5757
icon.ShowBalloonTip(10000, "DiffEngineTray", message, ToolTipIcon.Warning);
5858

59-
var settings = await GetSettings();
59+
var settings = GetSettings();
6060
if (settings == null)
6161
{
6262
return;
@@ -181,11 +181,11 @@ internal static IEnumerable<KeyBinding> BuildKeyBindings(Settings settings, Trac
181181

182182
internal record KeyBinding(int Id, HotKey HotKey, Action Action);
183183

184-
static async Task<Settings?> GetSettings()
184+
static Settings? GetSettings()
185185
{
186186
try
187187
{
188-
return await SettingsHelper.Read();
188+
return SettingsHelper.Read();
189189
}
190190
catch (Exception exception)
191191
{

src/DiffEngineTray/Settings/OptionsFormLauncher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static async Task Launch(KeyRegister keyRegister, Tracker tracker)
1010
return;
1111
}
1212

13-
var settings = await SettingsHelper.Read();
13+
var settings = SettingsHelper.Read();
1414
using var form = new OptionsForm(
1515
settings,
1616
newSettings => Save(keyRegister, tracker, settings, newSettings));

src/DiffEngineTray/Settings/SettingsHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static SettingsHelper()
1010
FilePath = Path.Combine(directory, "settings.json");
1111
}
1212

13-
public static async Task<Settings> Read()
13+
public static Settings Read()
1414
{
1515
Settings settings;
1616
if (File.Exists(FilePath))
@@ -25,7 +25,7 @@ public static async Task<Settings> Read()
2525
}
2626
else
2727
{
28-
await File.WriteAllTextAsync(FilePath, "{}");
28+
File.WriteAllText(FilePath, "{}");
2929
settings = new();
3030
}
3131

0 commit comments

Comments
 (0)