1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-18 06:15:49 +02:00

Add 'Configure' button to plugins with a configure() method & close dialog afterwards

This commit is contained in:
chylex 2018-02-12 10:40:00 +01:00
parent bf45c40365
commit 03d50c847b
10 changed files with 79 additions and 28 deletions

View File

@ -76,7 +76,7 @@ private void flowLayoutPlugins_Resize(object sender, EventArgs e){
} }
private void btnOpenFolder_Click(object sender, EventArgs e){ private void btnOpenFolder_Click(object sender, EventArgs e){
using(Process.Start("explorer.exe", "\""+pluginManager.PathCustomPlugins+"\"")){} using(Process.Start("explorer.exe", '"'+pluginManager.PathCustomPlugins+'"')){}
} }
private void btnReload_Click(object sender, EventArgs e){ private void btnReload_Click(object sender, EventArgs e){

View File

@ -71,6 +71,7 @@ public TweetDeckBrowser(FormBrowser owner, PluginManager plugins, TweetDeckBridg
this.plugins = plugins; this.plugins = plugins;
this.plugins.PluginChangedState += plugins_PluginChangedState; this.plugins.PluginChangedState += plugins_PluginChangedState;
this.plugins.PluginConfigureTriggered += plugins_PluginConfigureTriggered;
Program.UserConfig.MuteToggled += UserConfig_MuteToggled; Program.UserConfig.MuteToggled += UserConfig_MuteToggled;
Program.UserConfig.ZoomLevelChanged += UserConfig_ZoomLevelChanged; Program.UserConfig.ZoomLevelChanged += UserConfig_ZoomLevelChanged;
@ -164,6 +165,10 @@ private void plugins_PluginChangedState(object sender, PluginChangedStateEventAr
browser.ExecuteScriptAsync("TDPF_setPluginState", e.Plugin, e.IsEnabled); browser.ExecuteScriptAsync("TDPF_setPluginState", e.Plugin, e.IsEnabled);
} }
private void plugins_PluginConfigureTriggered(object sender, PluginEventArgs e){
browser.ExecuteScriptAsync("TDPF_configurePlugin", e.Plugin);
}
private void UserConfig_MuteToggled(object sender, EventArgs e){ private void UserConfig_MuteToggled(object sender, EventArgs e){
UpdateProperties(); UpdateProperties();
} }

View File

@ -31,7 +31,7 @@ private void InitializeComponent() {
this.flowLayoutInfo = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutInfo = new System.Windows.Forms.FlowLayoutPanel();
this.labelWebsite = new System.Windows.Forms.Label(); this.labelWebsite = new System.Windows.Forms.Label();
this.labelVersion = new System.Windows.Forms.Label(); this.labelVersion = new System.Windows.Forms.Label();
this.btnOpenConfig = new System.Windows.Forms.Button(); this.btnConfigure = new System.Windows.Forms.Button();
this.labelType = new TweetDuck.Core.Controls.LabelVertical(); this.labelType = new TweetDuck.Core.Controls.LabelVertical();
this.panelDescription.SuspendLayout(); this.panelDescription.SuspendLayout();
this.flowLayoutInfo.SuspendLayout(); this.flowLayoutInfo.SuspendLayout();
@ -135,16 +135,16 @@ private void InitializeComponent() {
this.labelVersion.TextAlign = System.Drawing.ContentAlignment.TopRight; this.labelVersion.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.labelVersion.UseMnemonic = false; this.labelVersion.UseMnemonic = false;
// //
// btnOpenConfig // btnConfigure
// //
this.btnOpenConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnConfigure.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOpenConfig.Location = new System.Drawing.Point(382, 80); this.btnConfigure.Location = new System.Drawing.Point(382, 80);
this.btnOpenConfig.Name = "btnOpenConfig"; this.btnConfigure.Name = "btnConfigure";
this.btnOpenConfig.Size = new System.Drawing.Size(68, 23); this.btnConfigure.Size = new System.Drawing.Size(68, 23);
this.btnOpenConfig.TabIndex = 4; this.btnConfigure.TabIndex = 4;
this.btnOpenConfig.Text = "Configure"; this.btnConfigure.Text = "Configure";
this.btnOpenConfig.UseVisualStyleBackColor = true; this.btnConfigure.UseVisualStyleBackColor = true;
this.btnOpenConfig.Click += new System.EventHandler(this.btnOpenConfig_Click); this.btnConfigure.Click += new System.EventHandler(this.btnConfigure_Click);
// //
// labelType // labelType
// //
@ -163,7 +163,7 @@ private void InitializeComponent() {
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.labelType); this.Controls.Add(this.labelType);
this.Controls.Add(this.btnOpenConfig); this.Controls.Add(this.btnConfigure);
this.Controls.Add(this.flowLayoutInfo); this.Controls.Add(this.flowLayoutInfo);
this.Controls.Add(this.panelDescription); this.Controls.Add(this.panelDescription);
this.Controls.Add(this.labelName); this.Controls.Add(this.labelName);
@ -194,7 +194,7 @@ private void InitializeComponent() {
private System.Windows.Forms.FlowLayoutPanel flowLayoutInfo; private System.Windows.Forms.FlowLayoutPanel flowLayoutInfo;
private System.Windows.Forms.Label labelWebsite; private System.Windows.Forms.Label labelWebsite;
private System.Windows.Forms.Label labelVersion; private System.Windows.Forms.Label labelVersion;
private System.Windows.Forms.Button btnOpenConfig; private System.Windows.Forms.Button btnConfigure;
private Core.Controls.LabelVertical labelType; private Core.Controls.LabelVertical labelType;
} }
} }

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils; using TweetDuck.Core.Utils;
@ -57,8 +55,9 @@ private void labelWebsite_Click(object sender, EventArgs e){
} }
} }
private void btnOpenConfig_Click(object sender, EventArgs e){ private void btnConfigure_Click(object sender, EventArgs e){
using(Process.Start("explorer.exe", "/select,\""+plugin.ConfigPath.Replace('/', '\\')+"\"")){} pluginManager.ConfigurePlugin(plugin);
ParentForm?.Close();
} }
private void btnToggleState_Click(object sender, EventArgs e){ private void btnToggleState_Click(object sender, EventArgs e){
@ -87,14 +86,13 @@ private void UpdatePluginState(){
labelName.ForeColor = textColor; labelName.ForeColor = textColor;
labelDescription.ForeColor = textColor; labelDescription.ForeColor = textColor;
btnToggleState.Text = isEnabled ? "Disable" : "Enable"; btnToggleState.Text = isEnabled ? "Disable" : "Enable";
btnOpenConfig.Visible = plugin.HasConfig; btnConfigure.Visible = isEnabled && pluginManager.IsPluginConfigurable(plugin);
btnOpenConfig.Enabled = btnOpenConfig.Visible && File.Exists(plugin.ConfigPath);
} }
else{ else{
labelName.ForeColor = Color.DarkRed; labelName.ForeColor = Color.DarkRed;
labelDescription.ForeColor = Color.DarkRed; labelDescription.ForeColor = Color.DarkRed;
btnToggleState.Visible = false; btnToggleState.Visible = false;
btnOpenConfig.Visible = false; btnConfigure.Visible = false;
} }
} }
} }

View File

@ -1,12 +1,8 @@
using System; namespace TweetDuck.Plugins.Events{
sealed class PluginChangedStateEventArgs : PluginEventArgs{
namespace TweetDuck.Plugins.Events{
sealed class PluginChangedStateEventArgs : EventArgs{
public Plugin Plugin { get; }
public bool IsEnabled { get; } public bool IsEnabled { get; }
public PluginChangedStateEventArgs(Plugin plugin, bool isEnabled){ public PluginChangedStateEventArgs(Plugin plugin, bool isEnabled) : base(plugin){
this.Plugin = plugin;
this.IsEnabled = isEnabled; this.IsEnabled = isEnabled;
} }
} }

View File

@ -0,0 +1,11 @@
using System;
namespace TweetDuck.Plugins.Events{
class PluginEventArgs : EventArgs{
public Plugin Plugin { get; }
public PluginEventArgs(Plugin plugin){
this.Plugin = plugin;
}
}
}

View File

@ -15,9 +15,10 @@ private static string SanitizeCacheKey(string key){
private readonly PluginManager manager; private readonly PluginManager manager;
private readonly TwoKeyDictionary<int, string, string> fileCache = new TwoKeyDictionary<int, string, string>(4, 2); private readonly TwoKeyDictionary<int, string, string> fileCache = new TwoKeyDictionary<int, string, string>(4, 2);
private readonly TwoKeyDictionary<int, string, InjectedHTML> notificationInjections = new TwoKeyDictionary<int,string,InjectedHTML>(4, 1); private readonly TwoKeyDictionary<int, string, InjectedHTML> notificationInjections = new TwoKeyDictionary<int, string, InjectedHTML>(4, 1);
public IEnumerable<InjectedHTML> NotificationInjections => notificationInjections.InnerValues; public IEnumerable<InjectedHTML> NotificationInjections => notificationInjections.InnerValues;
public HashSet<Plugin> WithConfigureFunction { get; } = new HashSet<Plugin>();
public PluginBridge(PluginManager manager){ public PluginBridge(PluginManager manager){
this.manager = manager; this.manager = manager;
@ -114,5 +115,13 @@ public void InjectIntoNotificationsBefore(int token, string key, string search,
public void InjectIntoNotificationsAfter(int token, string key, string search, string html){ public void InjectIntoNotificationsAfter(int token, string key, string search, string html){
notificationInjections[token, key] = new InjectedHTML(InjectedHTML.Position.After, search, html); notificationInjections[token, key] = new InjectedHTML(InjectedHTML.Position.After, search, html);
} }
public void SetConfigurable(int token){
Plugin plugin = manager.GetPluginFromToken(token);
if (plugin != null){
WithConfigureFunction.Add(plugin);
}
}
} }
} }

View File

@ -1,6 +1,7 @@
using CefSharp; using CefSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using TweetDuck.Plugins.Enums; using TweetDuck.Plugins.Enums;
@ -25,6 +26,7 @@ sealed class PluginManager{
public event EventHandler<PluginErrorEventArgs> Reloaded; public event EventHandler<PluginErrorEventArgs> Reloaded;
public event EventHandler<PluginErrorEventArgs> Executed; public event EventHandler<PluginErrorEventArgs> Executed;
public event EventHandler<PluginChangedStateEventArgs> PluginChangedState; public event EventHandler<PluginChangedStateEventArgs> PluginChangedState;
public event EventHandler<PluginEventArgs> PluginConfigureTriggered;
private readonly string rootPath; private readonly string rootPath;
private readonly string configPath; private readonly string configPath;
@ -57,6 +59,24 @@ public bool HasAnyPlugin(PluginEnvironment environment){
return plugins.Any(plugin => plugin.Environments.HasFlag(environment)); return plugins.Any(plugin => plugin.Environments.HasFlag(environment));
} }
public bool IsPluginConfigurable(Plugin plugin){
return plugin.HasConfig || Bridge.WithConfigureFunction.Contains(plugin);
}
public void ConfigurePlugin(Plugin plugin){
if (Bridge.WithConfigureFunction.Contains(plugin)){
PluginConfigureTriggered?.Invoke(this, new PluginEventArgs(plugin));
}
else if (plugin.HasConfig){
if (File.Exists(plugin.ConfigPath)){
using(Process.Start("explorer.exe", "/select,\""+plugin.ConfigPath.Replace('/', '\\')+"\"")){}
}
else{
using(Process.Start("explorer.exe", '"'+plugin.GetPluginFolder(PluginFolder.Data).Replace('/', '\\')+'"')){}
}
}
}
public int GetTokenFromPlugin(Plugin plugin){ public int GetTokenFromPlugin(Plugin plugin){
foreach(KeyValuePair<int, Plugin> kvp in tokens){ foreach(KeyValuePair<int, Plugin> kvp in tokens){
if (kvp.Value.Equals(plugin)){ if (kvp.Value.Equals(plugin)){

View File

@ -35,6 +35,10 @@
install(plugin){ install(plugin){
this.installed.push(plugin); this.installed.push(plugin);
if (typeof plugin.obj.configure === "function"){
$TDP.setConfigurable(plugin.obj.$token);
}
if (!this.isDisabled(plugin)){ if (!this.isDisabled(plugin)){
plugin.obj.enabled(); plugin.obj.enabled();
this.runWhenReady(plugin); this.runWhenReady(plugin);
@ -93,6 +97,13 @@
window.TD_PLUGINS.setState(window.TD_PLUGINS.findObject(identifier), enable); window.TD_PLUGINS.setState(window.TD_PLUGINS.findObject(identifier), enable);
}; };
//
// Block: Setup a function to trigger plugin configuration.
//
window.TDPF_configurePlugin = function(identifier){
window.TD_PLUGINS.findObject(identifier).obj.configure();
};
// //
// Block: Setup a function to reload the page. // Block: Setup a function to reload the page.
// //

View File

@ -274,6 +274,7 @@
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Plugins\Enums\PluginFolder.cs" /> <Compile Include="Plugins\Enums\PluginFolder.cs" />
<Compile Include="Plugins\Events\PluginEventArgs.cs" />
<Compile Include="Plugins\Plugin.cs" /> <Compile Include="Plugins\Plugin.cs" />
<Compile Include="Plugins\Events\PluginChangedStateEventArgs.cs" /> <Compile Include="Plugins\Events\PluginChangedStateEventArgs.cs" />
<Compile Include="Plugins\PluginBridge.cs" /> <Compile Include="Plugins\PluginBridge.cs" />