mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-02 20:34:07 +02:00
Fix a hidden crash that prevented desktop notifications from showing
This commit is contained in:
parent
dd4edc4249
commit
59fba7fba0
Core
Plugins
@ -12,6 +12,7 @@
|
|||||||
using TweetDuck.Core.Other.Analytics;
|
using TweetDuck.Core.Other.Analytics;
|
||||||
using TweetDuck.Core.Utils;
|
using TweetDuck.Core.Utils;
|
||||||
using TweetDuck.Plugins;
|
using TweetDuck.Plugins;
|
||||||
|
using TweetDuck.Plugins.Enums;
|
||||||
using TweetDuck.Plugins.Events;
|
using TweetDuck.Plugins.Events;
|
||||||
using TweetDuck.Updates;
|
using TweetDuck.Updates;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ public bool IsWaiting{
|
|||||||
|
|
||||||
public string UpdateInstallerPath { get; private set; }
|
public string UpdateInstallerPath { get; private set; }
|
||||||
|
|
||||||
|
public PluginManager PluginManager => plugins;
|
||||||
public AnalyticsFile AnalyticsFile => analytics?.File ?? AnalyticsFile.Dummy;
|
public AnalyticsFile AnalyticsFile => analytics?.File ?? AnalyticsFile.Dummy;
|
||||||
|
|
||||||
private readonly TweetDeckBrowser browser;
|
private readonly TweetDeckBrowser browser;
|
||||||
@ -57,17 +59,19 @@ public FormBrowser(UpdaterSettings updaterSettings){
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Text = Program.BrandName;
|
Text = Program.BrandName;
|
||||||
|
|
||||||
this.browser = new TweetDeckBrowser(this, new TweetDeckBridge.Browser(this, notification));
|
|
||||||
this.contextMenu = ContextMenuBrowser.CreateMenu(this);
|
|
||||||
|
|
||||||
this.plugins = new PluginManager(browser, Program.PluginPath, Program.PluginConfigFilePath);
|
this.plugins = new PluginManager(Program.PluginPath, Program.PluginConfigFilePath);
|
||||||
this.plugins.Reloaded += plugins_Reloaded;
|
this.plugins.Reloaded += plugins_Reloaded;
|
||||||
this.plugins.Executed += plugins_Executed;
|
this.plugins.Executed += plugins_Executed;
|
||||||
this.plugins.Reload();
|
this.plugins.Reload();
|
||||||
|
|
||||||
this.notification = new FormNotificationTweet(this, plugins);
|
this.notification = new FormNotificationTweet(this, plugins);
|
||||||
this.notification.Show();
|
this.notification.Show();
|
||||||
|
|
||||||
|
this.browser = new TweetDeckBrowser(this, new TweetDeckBridge.Browser(this, notification));
|
||||||
|
this.contextMenu = ContextMenuBrowser.CreateMenu(this);
|
||||||
|
|
||||||
|
this.plugins.Register(browser, PluginEnvironment.Browser, true);
|
||||||
|
|
||||||
Controls.Add(new MenuStrip{ Visible = false }); // fixes Alt freezing the program in Win 10 Anniversary Update
|
Controls.Add(new MenuStrip{ Visible = false }); // fixes Alt freezing the program in Win 10 Anniversary Update
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
using TweetDuck.Resources;
|
using TweetDuck.Resources;
|
||||||
|
|
||||||
namespace TweetDuck.Core.Notification{
|
namespace TweetDuck.Core.Notification{
|
||||||
abstract partial class FormNotificationMain : FormNotificationBase{
|
abstract partial class FormNotificationMain : FormNotificationBase, ITweetDeckBrowser{
|
||||||
private const string NotificationScriptFile = "notification.js";
|
private const string NotificationScriptFile = "notification.js";
|
||||||
|
|
||||||
private static readonly string NotificationScriptIdentifier = ScriptLoader.GetRootIdentifier(NotificationScriptFile);
|
private static readonly string NotificationScriptIdentifier = ScriptLoader.GetRootIdentifier(NotificationScriptFile);
|
||||||
@ -81,17 +81,35 @@ protected FormNotificationMain(FormBrowser owner, PluginManager pluginManager, b
|
|||||||
this.timerBarHeight = BrowserUtils.Scale(4, DpiScale);
|
this.timerBarHeight = BrowserUtils.Scale(4, DpiScale);
|
||||||
|
|
||||||
browser.KeyboardHandler = new KeyboardHandlerNotification(this);
|
browser.KeyboardHandler = new KeyboardHandlerNotification(this);
|
||||||
|
|
||||||
browser.RegisterAsyncJsObject("$TD", new TweetDeckBridge.Notification(owner, this));
|
browser.RegisterAsyncJsObject("$TD", new TweetDeckBridge.Notification(owner, this));
|
||||||
browser.RegisterAsyncJsObject("$TDP", plugins.Bridge);
|
|
||||||
|
|
||||||
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||||
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
||||||
|
|
||||||
|
plugins.Register(this, PluginEnvironment.Notification);
|
||||||
|
|
||||||
mouseHookDelegate = MouseHookProc;
|
mouseHookDelegate = MouseHookProc;
|
||||||
Disposed += (sender, args) => StopMouseHook(true);
|
Disposed += (sender, args) => StopMouseHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ITweetDeckBrowser.RegisterBridge(string name, object obj){
|
||||||
|
browser.RegisterAsyncJsObject(name, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITweetDeckBrowser.OnFrameLoaded(Action<IFrame> callback){
|
||||||
|
browser.FrameLoadEnd += (sender, args) => {
|
||||||
|
IFrame frame = args.Frame;
|
||||||
|
|
||||||
|
if (frame.IsMain && NotificationJS != null && browser.Address != "about:blank"){
|
||||||
|
callback(frame);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITweetDeckBrowser.ExecuteFunction(string name, params object[] args){
|
||||||
|
browser.ExecuteScriptAsync(name, args);
|
||||||
|
}
|
||||||
|
|
||||||
// mouse wheel hook
|
// mouse wheel hook
|
||||||
|
|
||||||
private void StartMouseHook(){
|
private void StartMouseHook(){
|
||||||
@ -166,7 +184,6 @@ private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
|||||||
if (e.Frame.IsMain && NotificationJS != null && browser.Address != "about:blank"){
|
if (e.Frame.IsMain && NotificationJS != null && browser.Address != "about:blank"){
|
||||||
e.Frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Notification));
|
e.Frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Notification));
|
||||||
ScriptLoader.ExecuteScript(e.Frame, NotificationJS, NotificationScriptIdentifier);
|
ScriptLoader.ExecuteScript(e.Frame, NotificationJS, NotificationScriptIdentifier);
|
||||||
plugins.ExecutePlugins(e.Frame, PluginEnvironment.Notification);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +249,7 @@ public override void ResumeNotification(){
|
|||||||
protected override string GetTweetHTML(TweetNotification tweet){
|
protected override string GetTweetHTML(TweetNotification tweet){
|
||||||
string html = base.GetTweetHTML(tweet);
|
string html = base.GetTweetHTML(tweet);
|
||||||
|
|
||||||
foreach(InjectedHTML injection in plugins.Bridge.NotificationInjections){
|
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
||||||
html = injection.Inject(html);
|
html = injection.Inject(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin
|
|||||||
protected override string GetTweetHTML(TweetNotification tweet){
|
protected override string GetTweetHTML(TweetNotification tweet){
|
||||||
string html = tweet.GenerateHtml("td-screenshot", false);
|
string html = tweet.GenerateHtml("td-screenshot", false);
|
||||||
|
|
||||||
foreach(InjectedHTML injection in plugins.Bridge.NotificationInjections){
|
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
||||||
html = injection.Inject(html);
|
html = injection.Inject(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using TweetDuck.Core;
|
using TweetDuck.Core;
|
||||||
|
using TweetDuck.Data;
|
||||||
using TweetDuck.Plugins.Enums;
|
using TweetDuck.Plugins.Enums;
|
||||||
using TweetDuck.Plugins.Events;
|
using TweetDuck.Plugins.Events;
|
||||||
using TweetDuck.Resources;
|
using TweetDuck.Resources;
|
||||||
@ -21,42 +22,46 @@ sealed class PluginManager{
|
|||||||
public string PathCustomPlugins => Path.Combine(rootPath, "user");
|
public string PathCustomPlugins => Path.Combine(rootPath, "user");
|
||||||
|
|
||||||
public IEnumerable<Plugin> Plugins => plugins;
|
public IEnumerable<Plugin> Plugins => plugins;
|
||||||
|
public IEnumerable<InjectedHTML> NotificationInjections => bridge.NotificationInjections;
|
||||||
|
|
||||||
public PluginConfig Config { get; }
|
public PluginConfig Config { get; }
|
||||||
public PluginBridge Bridge { get; }
|
|
||||||
|
|
||||||
public event EventHandler<PluginErrorEventArgs> Reloaded;
|
public event EventHandler<PluginErrorEventArgs> Reloaded;
|
||||||
public event EventHandler<PluginErrorEventArgs> Executed;
|
public event EventHandler<PluginErrorEventArgs> Executed;
|
||||||
|
|
||||||
private readonly ITweetDeckBrowser browser;
|
|
||||||
private readonly string rootPath;
|
private readonly string rootPath;
|
||||||
private readonly string configPath;
|
private readonly string configPath;
|
||||||
|
private readonly PluginBridge bridge;
|
||||||
|
|
||||||
private readonly HashSet<Plugin> plugins = new HashSet<Plugin>();
|
private readonly HashSet<Plugin> plugins = new HashSet<Plugin>();
|
||||||
private readonly Dictionary<int, Plugin> tokens = new Dictionary<int, Plugin>();
|
private readonly Dictionary<int, Plugin> tokens = new Dictionary<int, Plugin>();
|
||||||
private readonly Random rand = new Random();
|
private readonly Random rand = new Random();
|
||||||
|
|
||||||
public PluginManager(ITweetDeckBrowser browser, string rootPath, string configPath){
|
private ITweetDeckBrowser mainBrowser;
|
||||||
this.browser = browser;
|
|
||||||
|
public PluginManager(string rootPath, string configPath){
|
||||||
this.rootPath = rootPath;
|
this.rootPath = rootPath;
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
|
|
||||||
this.Config = new PluginConfig();
|
this.Config = new PluginConfig();
|
||||||
this.Bridge = new PluginBridge(this);
|
this.bridge = new PluginBridge(this);
|
||||||
|
|
||||||
this.browser.OnFrameLoaded(OnFrameLoaded);
|
|
||||||
this.browser.RegisterBridge("$TDP", Bridge);
|
|
||||||
|
|
||||||
Config.Load(configPath);
|
Config.Load(configPath);
|
||||||
Config.PluginChangedState += Config_PluginChangedState;
|
Config.PluginChangedState += Config_PluginChangedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Config_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
public void Register(ITweetDeckBrowser browser, PluginEnvironment environment, bool asMainBrowser = false){
|
||||||
browser.ExecuteFunction("TDPF_setPluginState", e.Plugin, e.IsEnabled);
|
browser.OnFrameLoaded(frame => ExecutePlugins(frame, environment));
|
||||||
Config.Save(configPath);
|
browser.RegisterBridge("$TDP", bridge);
|
||||||
|
|
||||||
|
if (asMainBrowser){
|
||||||
|
mainBrowser = browser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFrameLoaded(IFrame frame){
|
private void Config_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
||||||
ExecutePlugins(frame, PluginEnvironment.Browser);
|
mainBrowser?.ExecuteFunction("TDPF_setPluginState", e.Plugin, e.IsEnabled);
|
||||||
|
Config.Save(configPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPluginInstalled(string identifier){
|
public bool IsPluginInstalled(string identifier){
|
||||||
@ -68,12 +73,12 @@ public bool HasAnyPlugin(PluginEnvironment environment){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPluginConfigurable(Plugin plugin){
|
public bool IsPluginConfigurable(Plugin plugin){
|
||||||
return plugin.HasConfig || Bridge.WithConfigureFunction.Contains(plugin);
|
return plugin.HasConfig || bridge.WithConfigureFunction.Contains(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConfigurePlugin(Plugin plugin){
|
public void ConfigurePlugin(Plugin plugin){
|
||||||
if (Bridge.WithConfigureFunction.Contains(plugin)){
|
if (bridge.WithConfigureFunction.Contains(plugin)){
|
||||||
browser.ExecuteFunction("TDPF_configurePlugin", plugin);
|
mainBrowser?.ExecuteFunction("TDPF_configurePlugin", plugin);
|
||||||
}
|
}
|
||||||
else if (plugin.HasConfig){
|
else if (plugin.HasConfig){
|
||||||
if (File.Exists(plugin.ConfigPath)){
|
if (File.Exists(plugin.ConfigPath)){
|
||||||
@ -143,7 +148,7 @@ IEnumerable<Plugin> LoadPluginsFrom(string path, PluginGroup group){
|
|||||||
Reloaded?.Invoke(this, new PluginErrorEventArgs(loadErrors));
|
Reloaded?.Invoke(this, new PluginErrorEventArgs(loadErrors));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecutePlugins(IFrame frame, PluginEnvironment environment){
|
private void ExecutePlugins(IFrame frame, PluginEnvironment environment){
|
||||||
if (!HasAnyPlugin(environment)){
|
if (!HasAnyPlugin(environment)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user