Skip to content

Commit

Permalink
first working version (a.k.a. alpha version)
Browse files Browse the repository at this point in the history
  • Loading branch information
PsichiX committed Sep 14, 2015
1 parent 300da16 commit d02465b
Show file tree
Hide file tree
Showing 717 changed files with 114,751 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requirements/
5 changes: 5 additions & 0 deletions PlayGate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PlayGate/bin/
PlayGate/obj/
PlayGate/working/xulrunner/
*.suo
*.csproj.user
20 changes: 20 additions & 0 deletions PlayGate/PlayGate.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayGate", "PlayGate\PlayGate.csproj", "{EBA931A0-718A-4292-8565-9FC4A974B685}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EBA931A0-718A-4292-8565-9FC4A974B685}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EBA931A0-718A-4292-8565-9FC4A974B685}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBA931A0-718A-4292-8565-9FC4A974B685}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBA931A0-718A-4292-8565-9FC4A974B685}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions PlayGate/PlayGate/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
185 changes: 185 additions & 0 deletions PlayGate/PlayGate/BrowserControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework.Controls;
using Gecko;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace PlayGate
{
public class BrowserControl : MetroPanel
{
#region Public enumerators.

public enum Status
{
None,
Loading,
Ready
}

#endregion



#region Private data.

private MetroProgressBar m_progressBar;
private MetroLabel m_statusLabel;
private GeckoWebBrowser m_browser;
private Status m_status;
private string m_navigateToWhenActive;

#endregion



#region Public properties.

public Status BrowserStatus { get { return m_status; } }

#endregion



#region Public events.

public event EventHandler Ready;
public event EventHandler Loading;

#endregion



#region Construction and destruction.

public BrowserControl()
{
MetroSkinManager.ApplyMetroStyle(this);
m_status = Status.None;
VisibleChanged += BrowserControl_VisibileChanged;

m_progressBar = new MetroProgressBar();
MetroSkinManager.ApplyMetroStyle(m_progressBar);
m_progressBar.Dock = System.Windows.Forms.DockStyle.Bottom;
m_progressBar.Height = 6;
m_progressBar.ProgressBarStyle = ProgressBarStyle.Continuous;
m_progressBar.Maximum = 1;
m_progressBar.Value = 1;
Controls.Add(m_progressBar);

m_statusLabel = new MetroLabel();
MetroSkinManager.ApplyMetroStyle(m_statusLabel);
m_statusLabel.Text = "";
m_statusLabel.Dock = DockStyle.Bottom;
Controls.Add(m_statusLabel);

m_browser = new GeckoWebBrowser();
MetroSkinManager.ExtendMetroStyle(m_browser, false);
m_browser.NoDefaultContextMenu = true;
m_browser.Dock = DockStyle.Fill;
m_browser.DocumentCompleted += m_browser_DocumentCompleted;
m_browser.ProgressChanged += m_browser_ProgressChanged;
m_browser.Navigating += m_browser_Navigating;
Controls.Add(m_browser);
}

#endregion



#region Public functionalities.

public void Navigate(string url, bool navigateWhenActive = false)
{
if (Visible && Parent != null)
navigateWhenActive = false;
if (navigateWhenActive)
m_navigateToWhenActive = url;
else
{
m_navigateToWhenActive = null;
m_status = Status.Loading;
m_progressBar.Value = 0;
m_browser.Navigate(url);
}
}

public JToken EvaluateScript(string script)
{
return EvaluateScript<JToken>(script);
}

public T EvaluateScript<T>(string script)
{
if (String.IsNullOrEmpty(script))
return default(T);
try
{
using (AutoJSContext context = new AutoJSContext(m_browser.Window.JSContext))
{
var value = context.EvaluateScript(script, m_browser.Window.DomWindow);
return JsonConvert.DeserializeObject<T>(value.ToString());
}
}
catch { return default(T); }
}

public void AddMessageEventListener(string message, Action<string> action, bool useCapture = false)
{
m_browser.AddMessageEventListener(message, action, useCapture);
}

#endregion



#region Private events handlers.

private void BrowserControl_VisibileChanged(object sender, EventArgs e)
{
if (m_navigateToWhenActive != null)
Navigate(m_navigateToWhenActive);
}

private void m_browser_ProgressChanged(object sender, GeckoProgressEventArgs e)
{
if (m_status == Status.Loading)
{
m_progressBar.Maximum = (int)e.MaximumProgress;
m_progressBar.Value = (int)e.CurrentProgress;
m_statusLabel.Text = m_browser.StatusText;
}
}

private void m_browser_Navigating(object sender, Gecko.Events.GeckoNavigatingEventArgs e)
{
m_status = Status.Loading;
m_progressBar.Value = 0;
if (Loading != null)
Loading(this, new EventArgs());
}

private void m_browser_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
{
m_progressBar.Maximum = 1;
m_progressBar.Value = 1;
m_statusLabel.Text = "";
m_status = Status.Ready;
if (Ready != null)
Ready(this, new EventArgs());
}

private void m_browser_CreateWindow2(object sender, GeckoCreateWindow2EventArgs e)
{
e.Cancel = true;
Navigate(e.Uri);
}

#endregion
}
}
Loading

0 comments on commit d02465b

Please sign in to comment.