Formalized plugin interface
main.exe: main.cs WebThing.dll SoupSettings.so
gmcs $(CSFLAGS) -r:WebThing.dll main.cs
-WebThing.dll: WebThing.cs
- gmcs $(CSFLAGS) $(references) -target:library -out:$@ $<
+WebThing.dll: WebThing.cs WebThingPlugin.cs
+ gmcs $(CSFLAGS) $(references) -target:library -out:$@ $^
SoupSettings.so: SoupSettings.c
$(CC) $(CFLAGS) -shared $(LDFLAGS) $< -o $@
private Gtk.Table WidgetGrid;
private Gtk.Alignment InteriorOverlay;
- public Dictionary<string,object> Plugins;
+ public Dictionary<string,WebThingPlugin> Plugins;
public Dictionary<string,string> Options;
public string[] Arguments;
_Window.ShowAll();
- Plugins = new Dictionary<string, object>();
+ Plugins = new Dictionary<string,WebThingPlugin>();
// TODO: Conf.Get("plugins") instead of hard-coded path?
using (TextReader f = new StreamReader("plugins.conf")) {
string line;
public void LoadPlugin(string assemblyname) {
Assembly a = Assembly.LoadFile("plugins/" + assemblyname + ".dll");
- object obj = a.CreateInstance("Plugin", false, BindingFlags.ExactBinding, null, new object[] { this }, null, null);
- Plugins[assemblyname] = obj;
+ Type[] types = a.GetTypes();
+ foreach (Type t in types) {
+ if (t.GetInterface("WebThingPlugin") != null) {
+ WebThingPlugin p = (WebThingPlugin) a.CreateInstance(t.FullName, false, BindingFlags.ExactBinding, null, null, null, null);
+ p.Init(this);
+ Plugins[t.FullName] = p;
+ Console.WriteLine("Successfully loaded {0}", t.FullName);
+ }
+ }
}
public void AttachWidget(Gtk.Widget widget, CompassDirection direction, AttachOptions xoptions, AttachOptions yoptions) {
using System;
using bytex64.WebThing;
-public class Plugin {
- public Plugin(WebThing wt) {
+public class DefaultPage : WebThingPlugin {
+ public void Init(WebThing wt) {
if (wt.Arguments.Length > 0) {
wt.OpenUri(wt.Arguments[0]);
} else {
using Gtk;
using bytex64.WebThing;
-public class Plugin {
+public class FFNav : WebThingPlugin {
WebThing wt;
- public Plugin(WebThing wt) {
+ public void Init(WebThing wt) {
this.wt = wt;
wt.WebView.KeyPressEvent += WebView_KeyPress;
}
}
}
-public class Plugin {
- public Plugin(WebThing wt) {
+public class LoadThrobberPlugin : WebThingPlugin {
+ public void Init(WebThing wt) {
LoadThrobber lt = new LoadThrobber(wt);
wt.AttachWidget(lt, CompassDirection.Interior);
}
using Gtk;
using bytex64.WebThing;
-public class Plugin {
+public class Vimish : WebThingPlugin {
WebThing wt;
Gtk.Entry commandline;
- public Plugin(WebThing wt) {
+ public void Init(WebThing wt) {
this.wt = wt;
wt.WebView.KeyPressEvent += WebView_KeyPress;