mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-17 21:15:47 +02:00
Fix ScriptLoader crash when showing error message from another thread
This commit is contained in:
parent
ffd0f5e986
commit
ebe3868720
@ -131,7 +131,7 @@ private void browser_FrameLoadStart(object sender, FrameLoadStartEventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TwitterUtils.IsTwitterWebsite(frame)){
|
if (TwitterUtils.IsTwitterWebsite(frame)){
|
||||||
ScriptLoader.ExecuteFile(frame, "twitter.js");
|
ScriptLoader.ExecuteFile(frame, "twitter.js", browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.ExecuteJavaScriptAsync(TwitterUtils.BackgroundColorOverride);
|
frame.ExecuteJavaScriptAsync(TwitterUtils.BackgroundColorOverride);
|
||||||
@ -144,7 +144,7 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
|||||||
if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(frame)){
|
if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(frame)){
|
||||||
UpdateProperties();
|
UpdateProperties();
|
||||||
TweetDeckBridge.RestoreSessionData(frame);
|
TweetDeckBridge.RestoreSessionData(frame);
|
||||||
ScriptLoader.ExecuteFile(frame, "code.js");
|
ScriptLoader.ExecuteFile(frame, "code.js", browser);
|
||||||
InjectBrowserCSS();
|
InjectBrowserCSS();
|
||||||
ReinjectCustomCSS(Program.UserConfig.CustomBrowserCSS);
|
ReinjectCustomCSS(Program.UserConfig.CustomBrowserCSS);
|
||||||
UserConfig_SoundNotificationInfoChanged(null, EventArgs.Empty);
|
UserConfig_SoundNotificationInfoChanged(null, EventArgs.Empty);
|
||||||
@ -152,7 +152,7 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
|||||||
TweetDeckBridge.ResetStaticProperties();
|
TweetDeckBridge.ResetStaticProperties();
|
||||||
|
|
||||||
if (Program.UserConfig.FirstRun){
|
if (Program.UserConfig.FirstRun){
|
||||||
ScriptLoader.ExecuteFile(frame, "introduction.js");
|
ScriptLoader.ExecuteFile(frame, "introduction.js", browser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ public void UpdateProperties(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void InjectBrowserCSS(){
|
public void InjectBrowserCSS(){
|
||||||
browser.ExecuteScriptAsync("TDGF_injectBrowserCSS", ScriptLoader.LoadResource("styles/browser.css")?.TrimEnd() ?? string.Empty);
|
browser.ExecuteScriptAsync("TDGF_injectBrowserCSS", ScriptLoader.LoadResource("styles/browser.css", false, browser)?.TrimEnd() ?? string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReinjectCustomCSS(string css){
|
public void ReinjectCustomCSS(string css){
|
||||||
|
@ -2,26 +2,30 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using TweetDuck.Core.Controls;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
|
|
||||||
namespace TweetDuck.Resources{
|
namespace TweetDuck.Resources{
|
||||||
static class ScriptLoader{
|
static class ScriptLoader{
|
||||||
private const string UrlPrefix = "td:";
|
private const string UrlPrefix = "td:";
|
||||||
|
|
||||||
public static string LoadResource(string name, bool silent = false){
|
public static string LoadResource(string name, bool silent = false, Control sync = null){
|
||||||
try{
|
try{
|
||||||
return File.ReadAllText(Path.Combine(Program.ScriptPath, name), Encoding.UTF8);
|
return File.ReadAllText(Path.Combine(Program.ScriptPath, name), Encoding.UTF8);
|
||||||
}catch(Exception ex){
|
}catch(Exception ex){
|
||||||
if (!silent){
|
if (!silent){
|
||||||
FormMessage.Error("TweetDuck Has Failed :(", "Unfortunately, TweetDuck could not load the "+name+" file. The program will continue running with limited functionality.\n\n"+ex.Message, FormMessage.OK);
|
ShowLoadError(sync, "Unfortunately, TweetDuck could not load the "+name+" file. The program will continue running with limited functionality.\n\n"+ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExecuteFile(IFrame frame, string file){
|
public static bool ExecuteFile(IFrame frame, string file, Control sync = null){
|
||||||
ExecuteScript(frame, LoadResource(file), GetRootIdentifier(file));
|
string script = LoadResource(file, sync == null, sync);
|
||||||
|
ExecuteScript(frame, script, GetRootIdentifier(file));
|
||||||
|
return script != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExecuteScript(IFrame frame, string script, string identifier){
|
public static void ExecuteScript(IFrame frame, string script, string identifier){
|
||||||
@ -33,5 +37,14 @@ public static void ExecuteScript(IFrame frame, string script, string identifier)
|
|||||||
public static string GetRootIdentifier(string file){
|
public static string GetRootIdentifier(string file){
|
||||||
return "root:"+Path.GetFileNameWithoutExtension(file);
|
return "root:"+Path.GetFileNameWithoutExtension(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ShowLoadError(Control sync, string message){
|
||||||
|
if (sync == null){
|
||||||
|
FormMessage.Error("TweetDuck Has Failed :(", message, FormMessage.OK);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
sync.InvokeAsyncSafe(() => FormMessage.Error("TweetDuck Has Failed :(", message, FormMessage.OK));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public UpdateHandler(ITweetDeckBrowser browser, UpdaterSettings settings){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void OnFrameLoaded(IFrame frame){
|
private void OnFrameLoaded(IFrame frame){
|
||||||
ScriptLoader.ExecuteFile(frame, "update.js");
|
ScriptLoader.ExecuteFile(frame, "update.js"); // TODO can't show error on failure
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Check(bool force){
|
public int Check(bool force){
|
||||||
|
Loading…
Reference in New Issue
Block a user