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