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 CurrentSession = Config.Options["Session"];
16 } else if (Options.ContainsKey("Default")) {
17 RestoreSession("Default");
22 public override void Deinit(WebThing wt) {
23 if (Options.ContainsKey("AutoSave") && Config.ParseBool(Options["AutoSave"])) {
24 SaveSession(CurrentSession);
28 public void RestoreSession(string SessionName) {
29 if (Options.ContainsKey(SessionName)) {
30 while (wt.Tabs.NPages > 0) {
31 WebThingView wtv = wt.Tabs.CurrentPageWidget as WebThingView;
35 string[] pages = Regex.Split(Options[SessionName], @"\s+");
36 foreach (string page in pages) {
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());