mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-10-08 22:27:02 +02:00
Refactor ScriptLoader for easier script identifier handling
This commit is contained in:
Core
Plugins
Resources
Updates
@@ -122,11 +122,8 @@ namespace TweetDck.Core{
|
||||
|
||||
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||
if (e.Frame.IsMain){
|
||||
foreach(string js in ScriptLoader.LoadResources("code.js").Where(js => js != null)){
|
||||
browser.ExecuteScriptAsync(js);
|
||||
}
|
||||
|
||||
browser.ExecuteScriptAsync(plugins.GenerateScript(PluginEnvironment.Browser));
|
||||
ScriptLoader.ExecuteFile(browser,"code.js","root:code");
|
||||
plugins_Reloaded(plugins,new PluginLoadEventArgs(new string[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +195,7 @@ namespace TweetDck.Core{
|
||||
}
|
||||
|
||||
private void plugins_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
||||
browser.ExecuteScriptAsync(PluginScriptGenerator.GenerateSetPluginState(e.Plugin,e.IsEnabled));
|
||||
ScriptLoader.ExecuteScript(browser,PluginScriptGenerator.GenerateSetPluginState(e.Plugin,e.IsEnabled),"gen:pluginstate:"+e.Plugin);
|
||||
}
|
||||
|
||||
private void updates_UpdateAccepted(object sender, UpdateAcceptedEventArgs e){
|
||||
|
@@ -114,7 +114,7 @@ namespace TweetDck.Core{
|
||||
|
||||
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||
if (e.Frame.IsMain && notificationJS != null && browser.Address != "about:blank"){
|
||||
browser.ExecuteScriptAsync(notificationJS);
|
||||
ScriptLoader.ExecuteScript(e.Frame,notificationJS,"root:notification");
|
||||
browser.ExecuteScriptAsync(plugins.GenerateScript(PluginEnvironment.Notification));
|
||||
}
|
||||
}
|
||||
|
@@ -52,6 +52,10 @@ namespace TweetDck.Plugins{
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString(){
|
||||
return Identifier;
|
||||
}
|
||||
|
||||
public override int GetHashCode(){
|
||||
return identifier.GetHashCode();
|
||||
}
|
||||
|
@@ -4,9 +4,13 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Linq;
|
||||
using CefSharp;
|
||||
using CefSharp.WinForms;
|
||||
|
||||
namespace TweetDck.Resources{
|
||||
static class ScriptLoader{
|
||||
private const string UrlPrefix = "td:";
|
||||
|
||||
public static string LoadResource(string name){
|
||||
try{
|
||||
return File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,name),Encoding.UTF8);
|
||||
@@ -16,8 +20,26 @@ namespace TweetDck.Resources{
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<string> LoadResources(params string[] names){
|
||||
return names.Select(LoadResource);
|
||||
public static void ExecuteFile(ChromiumWebBrowser browser, string file, string identifier){
|
||||
ExecuteScript(browser,LoadResource(file),identifier);
|
||||
}
|
||||
|
||||
public static void ExecuteFile(IFrame frame, string file, string identifier){
|
||||
ExecuteScript(frame,LoadResource(file),identifier);
|
||||
}
|
||||
|
||||
public static void ExecuteScript(ChromiumWebBrowser browser, string script, string identifier){
|
||||
if (script == null)return;
|
||||
|
||||
using(IFrame frame = browser.GetMainFrame()){
|
||||
frame.ExecuteJavaScriptAsync(script,UrlPrefix+identifier);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExecuteScript(IFrame frame, string script, string identifier){
|
||||
if (script == null)return;
|
||||
|
||||
frame.ExecuteJavaScriptAsync(script,UrlPrefix+identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,9 +25,7 @@ namespace TweetDck.Updates{
|
||||
|
||||
private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||
if (e.Frame.IsMain){
|
||||
foreach(string js in ScriptLoader.LoadResources("update.js").Where(js => js != null)){
|
||||
browser.ExecuteScriptAsync(js);
|
||||
}
|
||||
ScriptLoader.ExecuteFile(e.Frame,"update.js","root:update");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user