Skip to content

Commit

Permalink
fix: Debug not using node dev server
Browse files Browse the repository at this point in the history
Now when debugging, we will display the interface using the node dev server for debug features such as live code editing. This may introduce some issues (#11) but we shall try anyways and see, since it benefits development.

+ minor perf. improvement when not using the local domain when using SetVirtualHostNameToFolderMapping. See related issue: MicrosoftEdge/WebView2Feedback#2381
  • Loading branch information
lulzsun committed Aug 5, 2022
1 parent ac7c3cc commit 792cd7c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Classes/Recorders/BaseRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public void ProcessCreation_EventArrived(object sender, EventArrivedEventArgs e)
}
AutoDetectGame(processId, executablePath.ToString());
}
else if (processId != 0)
AutoDetectGame(processId);
else if (processId != 0)AutoDetectGame(processId);
}
}
catch (ManagementException) { }
Expand Down
8 changes: 6 additions & 2 deletions Classes/Utils/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static string GenerateShortID() {

public static string GetRePlaysURI() {
#if (DEBUG)
//return "http://localhost:3000/#/";
return "file://" + Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + "/ClientApp/build/index.html";
//return "file://" + Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + "/ClientApp/build/index.html";
return "http://localhost:3000/#/";
#elif (RELEASE)
return "file://" + Application.StartupPath + "/ClientApp/build/index.html";
#endif
Expand Down Expand Up @@ -168,7 +168,11 @@ public static VideoList GetAllVideos(string Game = "All Games", string SortBy =
video.date = new FileInfo(file).CreationTime;
video.fileName = Path.GetFileName(file);
video.game = Path.GetFileName(Path.GetDirectoryName(file));
#if (DEBUG)
video.folder = "https://videos.replays.app/";
#elif (RELEASE)
video.folder = "file://" + Path.GetFullPath(Path.Combine(Path.GetDirectoryName(file), "..")).Replace("\\", "/");
#endif

if (!videoList.games.Contains(video.game)) videoList.games.Add(video.game);

Expand Down
7 changes: 4 additions & 3 deletions Classes/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ private async void CoreWebView2InitializationCompleted(object sender, CoreWebVie
webView2.CoreWebView2.Settings.IsWebMessageEnabled = true;
webView2.CoreWebView2.PermissionRequested += CoreWebView2PermissionRequested;
#if (DEBUG)
webView2.CoreWebView2.SetVirtualHostNameToFolderMapping("replays.local", Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + "/ClientApp/public/", CoreWebView2HostResourceAccessKind.Allow);
webView2.CoreWebView2.SetVirtualHostNameToFolderMapping("videos.replays.app", GetPlaysFolder(), CoreWebView2HostResourceAccessKind.Allow);
webView2.CoreWebView2.SetVirtualHostNameToFolderMapping("replays.app", Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + "/ClientApp/public/", CoreWebView2HostResourceAccessKind.Allow);
#elif (RELEASE)
webView2.CoreWebView2.SetVirtualHostNameToFolderMapping("replays.local", Application.StartupPath + "/ClientApp/build/", CoreWebView2HostResourceAccessKind.Allow);
webView2.CoreWebView2.SetVirtualHostNameToFolderMapping("replays.app", Application.StartupPath + "/ClientApp/build/", CoreWebView2HostResourceAccessKind.Allow);
webView2.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
#endif
webView2.CoreWebView2.Navigate("https://replays.local/preload.html");
webView2.CoreWebView2.Navigate("https://replays.app/preload.html");
}

private void CoreWebView2PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) {
Expand Down
9 changes: 9 additions & 0 deletions ClientApp/src/pages/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ export const Player: React.FC<Props> = ({videos}) => {

return (
<div className="h-full flex flex-col">
{(!process.env.NODE_ENV || process.env.NODE_ENV === 'development') &&
<div className="flex flex-col gap-2 font-medium text-base pb-2">
<span className="font-normal text-sm">DEV ONLY NOTE: Player has issues that only occur when debugging, it works perfectly fine in production</span>
<span className="font-normal text-sm">see this issue for more details:
<a className="cursor-pointer underline pl-2" onClick={(e) => {postMessage("ShowFolder", "https://github.com/lulzsun/RePlays/issues/11")}}>https://github.com/lulzsun/RePlays/issues/11</a>
</span>
</div>
}

<div className="relative flex w-full h-full bg-black justify-center cursor-pointer"
onClick={() => {
(videoElement.current?.paused ? videoElement.current?.play() : videoElement.current?.pause())
Expand Down

0 comments on commit 792cd7c

Please sign in to comment.