Skip to content

Commit

Permalink
Bring back delayed start logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Vin-meido committed Dec 25, 2021
1 parent 36455bd commit 731aa30
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions SugoiOfflineTranslatorEndpoint/SugoiOfflineTranslatorEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace SugoiOfflineTranslator
{
public class SugoiOfflineTranslatorEndpoint : HttpEndpoint, ITranslateEndpoint, IDisposable, IMonoBehaviour_Update
public class SugoiOfflineTranslatorEndpoint : HttpEndpoint, ITranslateEndpoint, IDisposable
{
public override string Id => "SugoiOfflineTranslator";

Expand Down Expand Up @@ -146,18 +146,6 @@ private void StartProcess()
}
}

public void Update()
{
if (this.isStarted && !this.isDisposing)
{
if(this.process.HasExited)
{
XuaLogger.AutoTranslator.Warn($"Translator server process exited unexpectedly [status {process.ExitCode}]");
this.isStarted = false;
}
}
}

void ServerDataReceivedEventHandler(object sender, DataReceivedEventArgs args)
{
if (this.LogServerMessages)
Expand Down Expand Up @@ -187,6 +175,20 @@ IEnumerator ITranslateEndpoint.Translate(ITranslationContext context)

public override IEnumerator OnBeforeTranslate(IHttpTranslationContext context)
{
if (this.isStarted && this.process.HasExited)
{
this.isStarted = false;
this.isReady = false;

XuaLogger.AutoTranslator.Warn($"Translator server process exited unexpectedly [status {process.ExitCode}]");
}

if (!this.isStarted && !this.isDisposing)
{
XuaLogger.AutoTranslator.Warn($"Translator server process not running. Starting...");
this.StartProcess();
}

while (!isReady) yield return null;
}

Expand Down

0 comments on commit 731aa30

Please sign in to comment.