Skip to content

Commit

Permalink
Fix issues with restarting P2P client (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco authored May 27, 2024
1 parent 392a007 commit 72bf6d2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/KKManager.Updater/Sources/TorrentUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ namespace KKManager.Updater.Sources
public static class TorrentUpdater
{
private static ClientEngine _client;
private static bool _eventsInitialized;
private static async Task<ClientEngine> GetClient()
{
// Only runs once the first time
if (_client == null)
if (!_eventsInitialized)
{
// When waking up from sleep restart all running torrents so they re-announce and such
// If sleep happened for a while then the torrent can be stuck for a long time otherwise
Expand Down Expand Up @@ -53,6 +54,7 @@ private static async Task<ClientEngine> GetClient()
#if DEBUG
MonoTorrent.Logging.LoggerFactory.Register(className => new MonoTorrent.Logging.TextLogger(Console.Out, className));
#endif
_eventsInitialized = true;
}

if (_client == null || _client.Disposed)
Expand Down Expand Up @@ -347,6 +349,7 @@ public void Move(FileInfo targetpath)
public static async Task Stop()
{
await DisposeClient();
_client = null;
}

public static async Task Start()
Expand Down

0 comments on commit 72bf6d2

Please sign in to comment.