Skip to content

Commit 1759c8f

Browse files
committed
[plugin] Send 'starting' plugin state sooner; Send 'stopped' state even if client thinks it's disconnected; Don't send simulator disconnect event if it wasn't connected.
1 parent 8661b44 commit 1759c8f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

MSFSTouchPortalPlugin/Services/PluginService.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ public Task StopAsync(CancellationToken cancellationToken) {
151151
// Shut down
152152
_quitting = true;
153153
_logger.LogDebug("Shutting down...");
154-
if (_client.IsConnected)
155-
UpdateTpStateValue("RunningState", "stopped");
154+
UpdateTpStateValue("RunningState", "stopped");
156155
StopPluginEventsTask();
157156
DisconnectSimConnect();
158157
if (_pluginConfig.SaveSettings())
@@ -1022,14 +1021,16 @@ void ConnectSimConnect() {
10221021
}
10231022

10241023
void DisconnectSimConnect() {
1025-
_simAutoConnectDisable.Set();
1024+
bool wasConn = _simConnectService.IsConnected;
10261025
bool wasSet = _simConnectionRequest.IsSet;
1026+
_simAutoConnectDisable.Set();
10271027
_simConnectionRequest.Reset();
1028-
if (_simConnectService.IsConnected)
1028+
if (wasConn)
10291029
_simConnectService.Disconnect();
10301030
else if (wasSet)
10311031
_logger.LogInformation((int)EventIds.PluginInfo, "Connection attempts to Simulator were canceled.");
1032-
UpdateSimConnectState();
1032+
if (wasConn || wasSet)
1033+
UpdateSimConnectState();
10331034
}
10341035

10351036
// Handles some basic actions like sim connection and repeat rate, with optional data value(s).
@@ -1731,13 +1732,13 @@ public void OnInfoEvent(InfoEvent message) {
17311732
"Touch Portal Connected with: TP v{tpV}, SDK v{sdkV}, {pluginId} entry.tp v{plugV}, {plugName} running v{prodV} ({runV})",
17321733
message.TpVersionString, message.SdkVersion, PluginId, message.PluginVersion, VersionInfo.AssemblyName, VersionInfo.GetProductVersionString(), runtimeVer
17331734
);
1735+
UpdateTpStateValue("RunningState", "starting");
17341736

17351737
ProcessPluginSettings(message.Settings);
17361738
// convert the entry.tp version back to the actual decimal value
17371739
if (!uint.TryParse($"{message.PluginVersion}", NumberStyles.HexNumber, null, out uint tpVer))
17381740
tpVer = VersionInfo.GetProductVersionNumber();
1739-
// update status & version states
1740-
UpdateTpStateValue("RunningState", "starting");
1741+
// update version states
17411742
UpdateTpStateValue("RunningVersion", runtimeVer);
17421743
UpdateTpStateValue("EntryVersion", $"{tpVer:X}");
17431744
// set a state for TP config home path (workaround for no env. var access in TP)

0 commit comments

Comments
 (0)