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,49 +471,51 @@ namespace UWPHook
} }
} }
if(restartSteam) return true;
{ }
Func<Process> getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault();
Process steam = getSteam(); private async Task<bool> RestartSteam(bool restartSteam)
if (steam != null) {
{ Func<Process> getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault();
string steamExe = steam.MainModule.FileName;
//we always ask politely Process steam = getSteam();
Debug.WriteLine("Requesting Steam shutdown"); if (steam != null)
Process.Start(steamExe, "-exitsteam"); {
string steamExe = steam.MainModule.FileName;
bool restarted = false; //we always ask politely
Stopwatch watch = new Stopwatch(); Debug.WriteLine("Requesting Steam shutdown");
watch.Start(); Process.Start(steamExe, "-exitsteam");
//give it N seconds to sort itself out bool restarted = false;
int waitSeconds = 8; Stopwatch watch = new Stopwatch();
while (watch.Elapsed.TotalSeconds < waitSeconds) watch.Start();
{
Thread.Sleep(TimeSpan.FromSeconds(0.5f));
if (getSteam() == null)
{
Debug.WriteLine("Restarting Steam");
Process.Start(steamExe);
restarted = true;
break;
}
}
if (!restarted) //give it N seconds to sort itself out
int waitSeconds = 8;
while (!restarted || watch.Elapsed.TotalSeconds < waitSeconds)
{
await Task.Delay(TimeSpan.FromSeconds(0.5f));
if (getSteam() == null)
{ {
Debug.WriteLine("Steam instance not restarted"); Debug.WriteLine("Restarting Steam");
MessageBox.Show("Failed to restart Steam, please launch it manually", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); Process.Start(steamExe);
return false; restarted = true;
break;
} }
} }
else
if (!restarted)
{ {
Debug.WriteLine("Steam instance not found to be restarted"); Debug.WriteLine("Steam instance not restarted");
MessageBox.Show("Failed to restart Steam, please launch it manually", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
} }
} }
else
{
Debug.WriteLine("Steam instance not found to be restarted");
}
return true; return true;
} }

Loading…
Cancel
Save