mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-13 08:34:08 +02:00
Fix browser reload causing JS to not load, and add exception handling to code.js reading
This commit is contained in:
parent
0c60e4ebfd
commit
377f9602d0
@ -32,6 +32,7 @@ public FormBrowser(){
|
||||
|
||||
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){ MenuHandler = new ContextMenuHandler(this) };
|
||||
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
||||
browser.RegisterJsObject("$TD",bridge);
|
||||
|
||||
Controls.Add(browser);
|
||||
@ -76,9 +77,22 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent
|
||||
if (!e.IsLoading){
|
||||
Invoke(new Action(SetupWindow));
|
||||
browser.LoadingStateChanged -= Browser_LoadingStateChanged;
|
||||
}
|
||||
}
|
||||
|
||||
string js = File.ReadAllText("code.js",Encoding.UTF8);
|
||||
browser.ExecuteScriptAsync(js);
|
||||
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||
if (e.Frame.IsMain){
|
||||
string js = null;
|
||||
|
||||
try{
|
||||
js = File.ReadAllText("code.js",Encoding.UTF8);
|
||||
}catch(Exception ex){
|
||||
MessageBox.Show("Unfortunately, TweetDick could not load the code.js file. The program will continue running with limited functionality.\r\n\r\n"+ex.Message,"TweetDick Has Failed :(",MessageBoxButtons.OK,MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
if (js != null){
|
||||
browser.ExecuteScriptAsync(js);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user