2 using System.Collections.Generic;
3 using System.Text.RegularExpressions;
4 using bytex64.WebThing;
6 public class Session : WebThingPlugin {
8 string CurrentSession = "Default";
10 public override void Init(WebThing wt) {
12 if (Config.Arguments.Length == 0) {
13 if (Config.Options.ContainsKey("Session")) {
14 RestoreSession(Config.Options["Session"]);
15 } else if (Options.ContainsKey("Default")) {
16 RestoreSession("Default");
21 public override void Deinit(WebThing wt) {
22 if (Options.ContainsKey("AutoSave") && Config.ParseBool(Options["AutoSave"])) {
23 SaveSession(CurrentSession);
27 public void RestoreSession(string SessionName) {
28 if (Options.ContainsKey(SessionName)) {
29 while (wt.Tabs.NPages > 0) {
30 WebThingView wtv = wt.Tabs.CurrentPageWidget as WebThingView;
34 string[] pages = Regex.Split(Options[SessionName], @"\s+");
35 foreach (string page in pages) {
38 CurrentSession = SessionName;
40 Console.WriteLine("Could not restore session {0} because it does not exist.", SessionName);
44 public void SaveSession(string SessionName) {
45 List<string> Uris = new List<string>();
46 foreach (WebThingView wtv in wt.Tabs) {
47 Uris.Add(wtv.WebView.MainFrame.Uri);
49 Options[SessionName] = String.Join(" ", Uris.ToArray());
53 public void DeleteSession(string SessionName) {
54 Options.Remove(SessionName);