Do not block UI when restarting Steam

pull/98/head
Brian Lima 2 years ago
parent c278c6389b
commit 0f5de2088a

@ -155,7 +155,8 @@ namespace UWPHook
try try
{ {
await ExportGames(restartSteam); await ExportGames();
await RestartSteam(restartSteam);
msg = "Your apps were successfuly exported!"; msg = "Your apps were successfuly exported!";
if(!restartSteam) if(!restartSteam)
@ -339,7 +340,7 @@ namespace UWPHook
/// </summary> /// </summary>
/// <param name="restartSteam"></param> /// <param name="restartSteam"></param>
/// <returns></returns> /// <returns></returns>
private async Task<bool> ExportGames(bool restartSteam) private async Task<bool> ExportGames()
{ {
string[] tags = Settings.Default.Tags.Split(','); string[] tags = Settings.Default.Tags.Split(',');
string steam_folder = SteamManager.GetSteamFolder(); string steam_folder = SteamManager.GetSteamFolder();
@ -470,7 +471,10 @@ namespace UWPHook
} }
} }
if(restartSteam) return true;
}
private async Task<bool> RestartSteam(bool restartSteam)
{ {
Func<Process> getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault(); Func<Process> getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault();
@ -489,9 +493,9 @@ namespace UWPHook
//give it N seconds to sort itself out //give it N seconds to sort itself out
int waitSeconds = 8; int waitSeconds = 8;
while (watch.Elapsed.TotalSeconds < waitSeconds) while (!restarted || watch.Elapsed.TotalSeconds < waitSeconds)
{ {
Thread.Sleep(TimeSpan.FromSeconds(0.5f)); await Task.Delay(TimeSpan.FromSeconds(0.5f));
if (getSteam() == null) if (getSteam() == null)
{ {
Debug.WriteLine("Restarting Steam"); Debug.WriteLine("Restarting Steam");
@ -512,7 +516,6 @@ namespace UWPHook
{ {
Debug.WriteLine("Steam instance not found to be restarted"); Debug.WriteLine("Steam instance not found to be restarted");
} }
}
return true; return true;
} }

Loading…
Cancel
Save