mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-04 05:11:50 +01:00
Tell the tapes the simulator runs only while the starter watches it
The tapes looked for any process named as the chosen exe, every two seconds off the UI thread. Under Wine the process is eu07.exe and never matched, so a run never showed as running and the tape window did not follow the driven vehicle, while a simulator started some other way was taken for the last launch. The starter's own watch of the process it started now says it.
This commit is contained in:
@@ -401,8 +401,6 @@ public class StartSimulationTests
|
||||
public bool OpenInShell(string pathOrUrl) => false;
|
||||
|
||||
public IProcessHandle? FindRunning(string processName) => null;
|
||||
|
||||
public bool IsRunning(string processName) => false;
|
||||
}
|
||||
|
||||
private sealed class RunningProcess : IProcessHandle
|
||||
|
||||
@@ -31,6 +31,4 @@ public interface IProcessLauncher
|
||||
bool OpenInShell(string pathOrUrl);
|
||||
|
||||
IProcessHandle? FindRunning(string processName);
|
||||
|
||||
bool IsRunning(string processName);
|
||||
}
|
||||
|
||||
@@ -65,8 +65,7 @@ public sealed class AppServices
|
||||
SettingsStore = new SettingsStore(files, clock, log, settingsPaths, new SettingsSerializer(dlssPlatform: !environment.IsMacOS), Executables);
|
||||
MissingVehicleLog = new MissingVehicleLog(SettingsStore.Settings, missingAssets, Library, log);
|
||||
Favorites = new FavoriteSceneries(files, log, settingsPaths.FavoritesPath());
|
||||
Tapes = new HaslerTapes(files, paths, log, clock, Timetables,
|
||||
() => Processes.IsRunning(Path.GetFileNameWithoutExtension(SettingsStore.ResolveExecutable())));
|
||||
Tapes = new HaslerTapes(files, paths, log, clock, Timetables, () => State.SimulatorRunning);
|
||||
Gpus = new LinuxGpus(files, environment);
|
||||
GraphicsCards = new GraphicsCards(files, environment, Gpus);
|
||||
Displays = new Displays(files, environment);
|
||||
|
||||
@@ -46,5 +46,17 @@ public sealed class AppState
|
||||
}
|
||||
}
|
||||
|
||||
private volatile bool _simulatorRunning;
|
||||
|
||||
/// <summary>
|
||||
/// The simulator the starter watches is still running: the one it started, not
|
||||
/// any of the same name. Read off the UI thread too.
|
||||
/// </summary>
|
||||
public bool SimulatorRunning
|
||||
{
|
||||
get => _simulatorRunning;
|
||||
set => _simulatorRunning = value;
|
||||
}
|
||||
|
||||
public void NotifyChanged() => Changed?.Invoke();
|
||||
}
|
||||
|
||||
@@ -90,22 +90,6 @@ public sealed class SystemProcessLauncher : IProcessLauncher
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRunning(string processName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var found = Process.GetProcessesByName(processName);
|
||||
foreach (var process in found)
|
||||
process.Dispose();
|
||||
return found.Length > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log($"lookup {processName}", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ProcessHandle : IProcessHandle
|
||||
{
|
||||
private const int KeptErrorLines = 20;
|
||||
|
||||
@@ -39,7 +39,6 @@ public partial class MainWindow : Window
|
||||
private DateTime _openedUtc = DateTime.UtcNow;
|
||||
private DateTime _startedUtc = DateTime.MinValue;
|
||||
private bool _starting;
|
||||
private bool _simulatorRunning;
|
||||
private bool _lookingAtSceneryFiles;
|
||||
private readonly DispatcherTimer _sceneryFilesTimer = new() { Interval = TimeSpan.FromSeconds(2) };
|
||||
|
||||
@@ -116,7 +115,7 @@ public partial class MainWindow : Window
|
||||
/// </summary>
|
||||
private async Task LookAtSceneryFilesAsync()
|
||||
{
|
||||
if (_lookingAtSceneryFiles || _simulatorRunning || !IsVisible || WindowState == WindowState.Minimized)
|
||||
if (_lookingAtSceneryFiles || AppServices.Current.State.SimulatorRunning || !IsVisible || WindowState == WindowState.Minimized)
|
||||
return;
|
||||
|
||||
_lookingAtSceneryFiles = true;
|
||||
@@ -690,10 +689,10 @@ public partial class MainWindow : Window
|
||||
return;
|
||||
}
|
||||
|
||||
_simulatorRunning = true;
|
||||
AppServices.Current.State.SimulatorRunning = true;
|
||||
_ = simulator.WaitForExitAsync().ContinueWith(_ => Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
_simulatorRunning = false;
|
||||
AppServices.Current.State.SimulatorRunning = false;
|
||||
RestoreFromSimulator();
|
||||
ReportIfCrashed(simulator, executable, started);
|
||||
}), TaskScheduler.Default);
|
||||
|
||||
Reference in New Issue
Block a user