Skip to content

Commit

Permalink
Merge pull request #19 from beyluta/online-resources
Browse files Browse the repository at this point in the history
Feature fetch online HTML resources
  • Loading branch information
beyluta authored Sep 17, 2022
2 parents 5685360 + 9c55ee7 commit bc711d2
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 25 deletions.
16 changes: 5 additions & 11 deletions Abstract/WidgetWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CefSharp.WinForms;
using System;
using System.IO;
using System.Windows.Forms;

namespace Widgets
Expand Down Expand Up @@ -65,16 +64,11 @@ public string GetMetaTagValue(string name, string widgetPath)
{
try
{
string[] html = File.ReadAllLines(widgetPath);
for (int i = 0; i < html.Length; i++)
{
if (html[i].Contains("meta") && html[i].Contains(name) && !html[i].Contains("<!--"))
{
return html[i].Split('"')[3];
}
}
} catch { return null; }
return null;
var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(widgetPath);
return doc.DocumentNode.SelectSingleNode("//meta[@name='" + name + "']").GetAttributeValue("content", null);
}
catch { return null; }
}
}
}
3 changes: 2 additions & 1 deletion Assets/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"version": "1.1.3"
"version": "1.1.3",
"remoteResources": "https://7xdeveloper.com/api/AccessEndpoint.php?endpoint=getappconfigs&id=resources"
}
42 changes: 42 additions & 0 deletions Classes/RemoteResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Widgets.Manager;

namespace Remote
{
public class RemoteResources
{
private Configuration appConfig;

public RemoteResources()
{
string json = File.ReadAllText(WidgetAssets.assetsPath + "/config.json");
appConfig = JsonConvert.DeserializeObject<Configuration>(json);
}

public async void DownloadRemoteResources()
{
using (HttpClient client = new HttpClient())
{
try
{
string response = await client.GetStringAsync(appConfig.remoteResources);
JArray array = JArray.Parse(response);
foreach (JObject resource in array)
{
string name = (string)resource["name"];
string content = (string)resource["html"];
string path = WidgetAssets.widgetsPath + $"\\{name}.html";
WidgetAssets.CreateHTMLFile(path, content);
}
}
catch { }
}
}
}
}
11 changes: 11 additions & 0 deletions Classes/WidgetAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ static public void CreateHTMLFilesDirectory()
{
Directory.CreateDirectory(widgetsPath);
}

static public void CreateHTMLFile(string path, string content)
{
if (!File.Exists(path))
{
using (StreamWriter streamWriter = new StreamWriter(path, true))
{
streamWriter.WriteLine(content);
}
}
}
}
}
38 changes: 25 additions & 13 deletions Classes/WidgetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Remote;
using Snippets;
using System;
using System.Collections;
Expand Down Expand Up @@ -59,6 +60,11 @@ @@ CefSharp configurations.
*/
WidgetAssets.CreateHTMLFilesDirectory();

/*
@@ Fetching online resources such as standard widgets and software version
*/
PrepareRemoteResources();

/*
@@ Loading the configurations of this software into the appConfig class instance.
*/
Expand Down Expand Up @@ -91,6 +97,24 @@ @@ It has some useful settings that can be accessed quickly.
CreateWindow(width, height, "WinWidgets", FormStartPosition.CenterScreen);
}

public async void PrepareRemoteResources()
{
using (HttpClient client = new HttpClient())
{
versionObject = JObject.Parse("{\"version\":\"" + appConfig.version + "\",\"downloadUrl\":\"https://github.com/beyluta/WinWidgets\"}");

try
{
string response = await client.GetStringAsync("https://7xdeveloper.com/api/AccessEndpoint.php?endpoint=getappconfigs&id=version");
versionObject = JObject.Parse(response);
}
catch { }
}

RemoteResources remoteResources = new RemoteResources();
remoteResources.DownloadRemoteResources();
}

public override void CreateWindow(int w, int h, string t, FormStartPosition p)
{
window = new Form();
Expand All @@ -105,20 +129,8 @@ public override void CreateWindow(int w, int h, string t, FormStartPosition p)
window.ShowDialog();
}

public override async void AppendWidget(Form f, string path)
public override void AppendWidget(Form f, string path)
{
using (HttpClient client = new HttpClient())
{
versionObject = JObject.Parse("{\"version\":\"" + appConfig.version + "\",\"downloadUrl\":\"https://github.com/beyluta/WinWidgets\"}");

try
{
string response = await client.GetStringAsync("https://7xdeveloper.com/api/AccessEndpoint.php?endpoint=getappconfigs&id=version");
versionObject = JObject.Parse(response);
}
catch { }
}

browser = new ChromiumWebBrowser(path);
browser.JavascriptMessageReceived += OnBrowserMessageReceived;
browser.IsBrowserInitializedChanged += OnBrowserInitialized;
Expand Down
1 change: 1 addition & 0 deletions Struct/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
struct Configuration
{
public string version;
public string remoteResources;
}

4 changes: 4 additions & 0 deletions WidgetsDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<Reference Include="CefSharp.WinForms, Version=102.0.90.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=MSIL">
<HintPath>packages\CefSharp.WinForms.102.0.90\lib\net462\CefSharp.WinForms.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.11.46.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>packages\HtmlAgilityPack.1.11.46\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand All @@ -85,6 +88,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\RemoteResources.cs" />
<Compile Include="Classes\UserActivityHook.cs" />
<Compile Include="Classes\WidgetAssets.cs" />
<Compile Include="Classes\WidgetManagerMenuHandler.cs" />
Expand Down
1 change: 1 addition & 0 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<package id="cef.redist.x86" version="102.0.9" targetFramework="net472" />
<package id="CefSharp.Common" version="102.0.90" targetFramework="net472" />
<package id="CefSharp.WinForms" version="102.0.90" targetFramework="net472" />
<package id="HtmlAgilityPack" version="1.11.46" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
</packages>

0 comments on commit bc711d2

Please sign in to comment.