Skip to content

Commit

Permalink
fix: Issue with multiple restart recordings on user tab focus (#65)
Browse files Browse the repository at this point in the history
* Fixes an issue where the user tabs in an out fast that causes multiple RestartRecordings to happen at the same time.
  • Loading branch information
Segergren authored Oct 29, 2022
1 parent 3b20390 commit 41a6923
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion Classes/Recorders/LibObsRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ public override async Task<bool> StopRecording() {
Logger.WriteLine(e.Message);
}

//Adding bookmarks
BookmarkService.ApplyBookmarkToSavedVideo("/" + videoNameTimeStamp + "-ses.mp4");

return true;
Expand Down
15 changes: 11 additions & 4 deletions Classes/Services/BookmarkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ public static void AddBookmark()

public static void ApplyBookmarkToSavedVideo(string videoName)
{
WebMessage.SetBookmarks(videoName, bookmarks, RecordingService.lastVideoDuration);
bookmarks.Clear();
try
{
Logger.WriteLine($"Applying bookmarks");
WebMessage.SetBookmarks(videoName, bookmarks, RecordingService.lastVideoDuration);
bookmarks.Clear();
Logger.WriteLine($"Bookmark status [Successfully]");
}
catch (Exception e)
{
Logger.WriteLine($"Bookmark status [Failed] with exception {e.Message}");
}
}


}
}
7 changes: 5 additions & 2 deletions Classes/Services/RecordingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class RecordingService {
private static Session currentSession = new(0, "Game Unknown");
public static bool IsRecording { get; internal set; }
private static bool IsPreRecording { get; set; }
private static bool IsRestarting { get; set; }
public static bool GameInFocus { get; set; }

public class Session {
Expand Down Expand Up @@ -110,7 +111,8 @@ public static async void StopRecording() {
}
}
public static async void RestartRecording() {
if (!IsRecording) return;
if (!IsRecording || IsRestarting) return;
IsRestarting = true;

bool stopResult = await ActiveRecorder.StopRecording();
bool startResult = await ActiveRecorder.StartRecording();
Expand All @@ -119,9 +121,10 @@ public static async void RestartRecording() {
Logger.WriteLine("Recording restart successful");
}
else {
Logger.WriteLine($"Issue trying to restart recording: {stopResult} {startResult}");
Logger.WriteLine($"Issue trying to restart recording. Could start {stopResult}, could stop {startResult}");
IsRecording = false;
}
IsRestarting = false;
}

public static void LostFocus()
Expand Down

0 comments on commit 41a6923

Please sign in to comment.