[Ext] Session Manager 0.4 to 0.4.3

Announce and Discuss the Latest Theme and Extension Releases.
Locked
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

zeniko wrote:
Morac wrote:3. The option to reload all windows doesn't work at the moment.

Just replacing <code>CRTabRestored</code> with <code>SSTabRestored</code> in the original code should do the trick (the underlying code is exactly the same).


I think I was thinking along that lines originally but removed it to focus on other stuff and kind of forgot about it. It looks like it should work so I'll try that.

zeniko wrote:
Morac wrote:4. Sometimes the extension's undo closed tab list will get temporary out of sync with the browser's closed tab list


I'd recommend not trying to keep a second list of closed tabs around but to always directly use the one provided by Firefox instead. Should save you some code and bugs...

I don't really keep a second list around, I keep a list of the tab titles around and sync it to Firefox's closed tabs list. The main reason I did this is I kept getting exceptions telling me windows didn't exist otherwise. I'll see if I can work around that somehow.


Right now I'm running into two problems:

1. There is no way to trap the closing of a window to save their state because SessionStore dumps its data before the onunload event fires. This means by the time the extension is called, calling SessionStore results in an exception. This has been documented in Firefox Bug 360408

2. The data returned from a SessionStore's getWindowState(window) function borks when put into the eval function since it isn't formatted correctly for that (it is missing the "[ { ... } ]" around the data. It is easy to work around, but this seems more like a bug in firefox to me. I reported it as such at Bug 365265.
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

Morac wrote:1. There is no way to trap the closing of a window to save their state because SessionStore dumps its data before the onunload event fires.

Until that bug has been fixed, you can easily work around it by patching the <code>closeWindow</code> function to call your code to get the window's state:

Code: Select all

eval("closeWindow = " + closeWindow.toString().replace("if (aClose)", "gSessionManager.onWindowClose(); $&"));

You'll just have to add this line to <code>gSessionManager.onLoad</code> at some point after having made sure that <code>aDialog</code> is <code>false</code> and do the magic in the new <code>onWindowClose</code> function...
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

Okay I got the following things working:
1. Saving closed windows
2. Reloading windows on restore
3. Both persistence options (with caveats, see below).


I have a question though about the "Restore the list of reopenable closed tabs for all windows" feature.
There are 3 options: never (0), startup (1) and always (2).

What exactly is this supposed to do and How is it supposed to work?

At the moment the only thing left is the code that will strip the closed tab data if the option is set to never or startup any time a session or window is manually saved. I'm not sure why it does this is even being done since if the closed tab data is stripped out on the save and the user changes the preference the data is already gone at that point and can't be restored.

There was other code in sessionmanager.js about maintaining the closed tab lists and it frequently checked for this preference, but as all that stuff is now handled by SessionStore I'll have to add code, but I want to know what the feature is supposed to do.
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

Okay I got pretty much everything working although I would like to integrate the extension a bit better with SessionStore since right now SessionStore is solely handling restoring the last session (for crashes or if the user selects to restore last session). The extension handles restoring other sessions. Also there is still an issue with the extension's closed tab list menu occasionally not matching the actually closed tabs though I've only found two conditions that cause this.

Also I'm not sure the "Restore the list of reopenable closed tabs for all windows" feature is working as it was intended, but that's a minor issue.

It seems stable enough so you can grab it from this link
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

Morac wrote:the "Restore the list of reopenable closed tabs for all windows" feature.

This one's supposed to optionally strip out the relevant information whenever a session is manually saved and whenever a session is restored (in case the session was saved with Undo Close Tab information but that information is no longer desired).

Feel free to drop this option (or any other for that matter) if you feel it might mean too much work for you, though.

On a side-note: you don't have to JSON-ify the session objects before passing them to SessionStore. It's sufficient to <code>toSource()</code> them (e.g. <code>mSessionStore.setWindowState(window, state.toSource(), false);</code>).

Morac wrote:I would like to integrate the extension a bit better with SessionStore

Since SessionStore isn't much more than Crash Recovery with added Undo Close Tab bits, there might not be much more to integrate with...

Morac wrote:It seems stable enough so

One question which might be of interest for testers: can previously saved sessions still be loaded? Crash Recovery 0.6 (and thus Session Manager 0.4) used an INI file format while SessionStore uses JSON instead. Do you convert between the two?
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

zeniko wrote:One question which might be of interest for testers: can previously saved sessions still be loaded? Crash Recovery 0.6 (and thus Session Manager 0.4) used an INI file format while SessionStore uses JSON instead. Do you convert between the two?

No I didn't even really consider that. I guess I'll have to add a conversion from INI to JSON format.
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

I updated the version I put out to fix a few issues and make the "Restore ... tabs for all windows" feature work correctly in all cases. I also optimized the event handlers so I don't need as many.

The only issue I've found so far is that when using one of Tab Mix Plus's features that cause the closed tab list to be empty (either the clear the closed tab list menu item or clicking to undo close tab the last closed tab), the Session Manager "undo close" toolbar isn't disabled until it is clicked or another tab is closed. Apparently however TMP works its magic, it bypasses the event handers. This is a minor issue though.

I still need to do the conversion routine mentioned above, but I'm not up to it at the moment (maybe next week). At the moment it just won't list old format sessions.
User avatar
gssq
Posts: 504
Joined: December 7th, 2002, 10:17 am
Location: Singapore
Contact:

Post by gssq »

Thanks!
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

Okay I threw together a semi-decent conversion routine and it now appears capable of reading the old CrashRecovery formatted session saves. It will convert them to the new format, but the old format saved things that the new one doesn't, like cookies and the closed tabs are in a completely different format which I didn't feel like converting at the moment.

My advice is to resave the session after you restore it to get rid of the extra junk and clean it up.

I re-uploaded the file and as usual it is available here.

So at the moment, I can't think of anything else that needs to be done. It should work pretty much just as well as Session Saver 0.4.3 did. The main benefits is there won't be constant errors in the error console and the undo close tab functionality integrates better with other extensions such as tab mix plus. Other than that I can't think of any benefit.

Let me know if you find any bugs.
User avatar
gssq
Posts: 504
Joined: December 7th, 2002, 10:17 am
Location: Singapore
Contact:

Post by gssq »

Hmm doesn't save cookies? Is there a way to get them saved? Anything else in the old format that isn't in the new one?
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

There probably is a way to get it to save cookies manually (using the cookie component) since SessionStore doesn't return this info in it's API calls, but as Firefox already saves them it might be a bit redundant. Also sometimes restoring cookies is not a good thing to do because some sites (some message boards, banks, etc) will match a server side session variable with a browser session cookie. If you restore this cookie it could cause the web site to break.

I can't think of anything else off the top of my head that isn't saved, but I didn't dig much deeper.


I'll mention one other thing. I made the "Restore the list of reopenable closed tabs for all windows" feature very draconic when it is set to none. It will basically never restore the closed tabs list when a session or window is restore for any reason (including crashes). I'm not sure if that's the way it used to work, but it seemed to make sense based on what it is supposed to do.
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

Morac wrote:the old format saved things that the new one doesn't

That means that you're losing information somewhere. SessionStore saves cookies in the same way as Crash Recovery did (except that it's <code>cookies</code> instead of <code>Cookies</code> and thus another case for <code>ini_fixName</code>) and the list of closed tabs is just saved in a different place and encoded a second time in Crash Recovery's format.

Morac wrote:So at the moment, I can't think of anything else that needs to be done.

Sweet. Now let's have some people test it and then we can discuss whether you want to take over http://sessionmanager.mozdev.org/ or if I should just link to your site/version...
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

zeniko wrote:
Morac wrote:the old format saved things that the new one doesn't

That means that you're losing information somewhere. SessionStore saves cookies in the same way as Crash Recovery did (except that it's <code>cookies</code> instead of <code>Cookies</code> and thus another case for <code>ini_fixName</code>) and the list of closed tabs is just saved in a different place and encoded a second time in Crash Recovery's format.

Oops it looks like it does save cookies though apparently not all the time. I tried a test by going to Google, setting preferences and saving the session and noticed there was no cookie data in the session file so I assumed no cookie data was stored. I found cookie data in a different session save. I'm not sure why cookie data isn't saved for Google though.

Here's what I did:
1. Go to www.google.com
2. Set preferences to show 50 results
3. type javascript:alert(document.cookie) to show that the preference was saved
4. Save the session
5. Clear cookies and restore session.
6. Preferences are back to default. Checking the session file shows no cookies.

I'm assuming this is a bug or something?


Any way, I probably should also figure out a way to convert the closed tab data from the old format, but since it isn't as simple as changing one word I'll have to see. It looks like it should be simple enough to convert since the closed tab data is just an escaped mini-version of the the regular window restore data.

In the meantime I added the Cookies to the conversion and re-uploaded the file.
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

Morac wrote:I'm not sure why cookie data isn't saved for Google though.

That's because SessionStore only saves session cookies whereas Google sets permanent cookies. Since I have never cared much about permanent cookies (I have configured Firefox to automatically convert all cookies to session cookies), Crash Recovery and Session Manager (and now SessionStore) only really handled the former. If you want permanent cookies to be saved for manually saved sessions as well, you'll have to yourself extend the cookies list at the point of saving...
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Post by Morac »

I've run into a bunch of issues trying to convert from the old closed tab data into the new format. The two main issues are that Crash Recovery stores different data (it uses window, tabs, entries while SessionStore uses state) and that the old data can't be easily decoded by the decode function since it reuses the same Window1.Tab1 entries over and over again causing the data to get overwritten.

I think I found a way past the second issue, but trying to convert from "windows : [ { tabs : { ... } ] " format to the current one is frustrating me at the moment. I keep coming close but things just aren't right. I think I might just leave that out as it really is a minor issue.
Locked