Skip to content

Commit

Permalink
[Settings][KBM] Fix re-reading loop on non-existing file (#18374)
Browse files Browse the repository at this point in the history
* [KBM]

* [KBM] Keyboard Manager profile loading should not expect the profile to exist
  • Loading branch information
lncubus committed Jun 2, 2022
1 parent 6f0e2f9 commit 9e4a58e
Showing 1 changed file with 13 additions and 3 deletions.
Expand Up @@ -239,11 +239,12 @@ public void NotifyFileChanged()
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions here (especially mutex errors) should not halt app execution, but they will be logged.")]
public bool LoadProfile()
{
// The KBM process out of runner creates the default.json file if it does not exist.
var success = true;
var readSuccessfully = false;

// The KBM process out of runner doesn't create the default.json file if it does not exist.
string fileName = Settings.Properties.ActiveConfiguration.Value + JsonFileType;
var profileExists = false;

try
{
Expand All @@ -253,7 +254,12 @@ public bool LoadProfile()
{
while (!readSuccessfully && !ts.IsCancellationRequested)
{
if (_settingsUtils.SettingsExists(PowerToyName, fileName))
profileExists = _settingsUtils.SettingsExists(PowerToyName, fileName);
if (!profileExists)
{
break;
}
else
{
try
{
Expand Down Expand Up @@ -298,7 +304,11 @@ public bool LoadProfile()
success = false;
}

if (!success)
if (!profileExists)
{
Logger.LogInfo($"Couldn't load {PowerToyName} profile because it doesn't exist");
}
else if (!success)
{
Logger.LogError($"Couldn't load {PowerToyName} profile");
}
Expand Down

0 comments on commit 9e4a58e

Please sign in to comment.