Skip to content

Commit

Permalink
Merge pull request #96 from Mikou27/master
Browse files Browse the repository at this point in the history
Nucleus  v2.3.1
  • Loading branch information
Mikou27 authored Oct 22, 2024
2 parents 6cbe268 + 5a84a14 commit 33cf223
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 187 deletions.
1 change: 1 addition & 0 deletions Master/NucleusCoopTool/Controls/HubWebView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 86 additions & 6 deletions Master/NucleusCoopTool/Controls/HubWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using Nucleus.Gaming.UI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -88,6 +90,8 @@ public HubWebView()

button_Panel.BackColor = BackColor;

ShowThrobber();

string debugUri = Path.Combine(Application.StartupPath, $"webview\\debugUri.txt");

if (File.Exists(debugUri))
Expand Down Expand Up @@ -120,10 +124,55 @@ public HubWebView()
}
}
}

BuildHandlersDatas();
}

private PictureBox throbber;

private void ShowThrobber()
{
if (throbber == null)
{
throbber = new PictureBox
{
Size = new Size(50, 50),
BackColor = BackColor,
Image = ImageCache.GetImage(Globals.ThemeFolder + "loading.gif"),
SizeMode = PictureBoxSizeMode.StretchImage
};

throbber.LocationChanged += ThrobberLocationChanged;
Controls.Add(throbber);

throbber.BringToFront();
}
}

protected void ThrobberLocationChanged(object sender,EventArgs e)
{
PictureBox _throb = (PictureBox)sender;
using (var gp = new GraphicsPath())
{
gp.AddEllipse(new Rectangle(0, 0, _throb.Width , _throb.Height));
_throb.Region = new Region(gp);
}
}

private void ThrobberDispose()
{
if (throbber != null)
Controls.Remove(throbber);
throbber?.Dispose();
throbber = null;
}

private void HubWebView_Resize(object sender, EventArgs e)
{
if(throbber != null)
throbber.Location = RectangleUtil.Center(throbber.ClientRectangle, ClientRectangle).Location;
}

private void BuildHandlersDatas()
{
installedHandlers.Clear();
Expand All @@ -146,14 +195,14 @@ private void BuildHandlersDatas()
}

private async void OnLoad(object sender, EventArgs e)
{
{
await InitializeAsync();
}

private async Task InitializeAsync()
{
try
{
{
CoreWebView2Environment environment;
CoreWebView2EnvironmentOptions environmentOptions = new CoreWebView2EnvironmentOptions();
environmentOptions.AreBrowserExtensionsEnabled = true;
Expand Down Expand Up @@ -215,14 +264,45 @@ private async void WebView_CoreWebView2InitializationCompleted(object sender, Co
webView.CoreWebView2.NewWindowRequested += NewWindowRequested;
webView.CoreWebView2.WebMessageReceived += WebMessageReceived;
webView.CoreWebView2.ProcessFailed += ProcessFailed;
webView.CoreWebView2.NavigationStarting += NavigationStarting;
webView.CoreWebView2.NavigationCompleted += NavigationCompleted;

webView.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Dark;

BringToFront();
}
}
catch { Console.WriteLine("Webview init failed!"); }
}

private bool inUserBrowser;

private void NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
if(e.IsSuccess)
inUserBrowser = false;
}

private void NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
{
CoreWebView2 currentWindow = (CoreWebView2)sender;

if (!e.Uri.StartsWith("https://hub.splitscreen.me/"))
{
if(!inUserBrowser)
{
Process.Start(e.Uri);
inUserBrowser = true;
}
else
{
currentWindow.Reload();
}

e.Cancel = true;
}
}

private void WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
Console.WriteLine(e.WebMessageAsJson);
Expand Down Expand Up @@ -256,6 +336,7 @@ private void DOMContentLoaded(object sender, CoreWebView2DOMContentLoadedEventAr
hasFreshCahe = false;
}

ThrobberDispose();
webView.ZoomFactor = 0.8;
SendDatas();
}
Expand Down Expand Up @@ -596,7 +677,6 @@ private void DisposeContent(object sender, EventArgs e)
}

webView?.Dispose();
}
}
}

}
2 changes: 0 additions & 2 deletions Master/NucleusCoopTool/Forms/DownloadPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public partial class DownloadPrompt : Form
private int entriesDone = 0;
private float fontSize;
private bool overwriteWithoutAsking = false;
private MainForm mainForm;
//public bool gameExeNoUpdate;
public string game;

private void controlscollect()
Expand Down
18 changes: 9 additions & 9 deletions Master/NucleusCoopTool/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 33cf223

Please sign in to comment.