Friday, October 17, 2008

Ubiquity in Thunderbird 0.1 is UP!

Note: 0.1 is the release version only for my zenit wiki page. It is not the official release number.

If you don’t want to read my blog post just go here for the 0.1 release:

http://zenit.senecac.on.ca/wiki/index.php/Make_Ubiquity_Work_In_Thunderbird

Alright, where to begin talking about this goliath. Well, when I first decided to take this thing on, I knew it would be big. I knew there would be tons of code. I knew there would be TONS of things I didn’t understand. What I didn’t expect was such a vast difference between Firefox and Thunderbird.

Simple things like opening a URL completely broke in Thunderbird. Ubiquity runs using an annotation service, sadly that doesn’t exist in Thunderbird. What are you to do when half the code you’re working with is exploding on you? Well, everyone in our group did the most logical thing to start off with. If something is breaking, just comment it out!

Setting up the error console to spit out javascript errors was a process we first learned when we all started on this project. I managed to get the majority of errors to stop popping up, but I still had a few that just wouldn’t go away. A lot of stuff about “services” not wanting to work and certain blocks containing no data (being NULL) simply wouldn’t go away. Thankfully, two other students (Vladamir and Justin) got a past some of the errors I was struggling with, and got Ubiquity to pop up. Hurray!

Unfortunately, when I pulled their build down the previewBlock seemed to crap out on me. Well, there went another solid week of fighting with the code to get preview commands to work properly. I finally got that up and running but it wasn’t doing entirely everything I wanted it to do. For example, the map display from the map command wouldn’t even show up. I got a nice little preview block with text stating what the command did, but no map window.

Well, a few days of asking questions and looking for direction, Vladamir sent his latest build up to the repository. The map window was popping up, but it wasn’t displaying properly. Oh well, I figured I’ll just leave that for later and get commands that need access to new windows creating windows properly first. By this time we had a page to file tickets strictly for Ubiquity Thunderbird. http://labs.toolness.com/trac/ticket/326 I’m considering completing that as part of my 0.2. We’ll see if anyone else claims it by the time I get around to it.

Figuring out how to get windows to pop up in Thunderbird was fairly easy. I spent about an hour playing around with a few functions in the Ubiquity source to see if I could do anything with them. At this point in time, for some strange reason... don’t ask me why, I was thinking that Utils was coming from either Firefox or Thunderbird. I think around this point, I managed to confuse myself (which happens often). There was just so much source to keep track of, I simply made a mistake assuming this wasn’t a built in Ubiquity command. So I ran around throughout the entire source code finding every Utils.openURLInBrowser that I could and replacing it with my 1 liner that popped up the appropriate page the command was trying to generate.

No problems! Command windows were firing up here and there, and I was happy. I figured I did a good job, and I’d just have to start editing some external commands to get them to pop up windows as well. However, instead of going off on that route (thank god I didn’t) I decided to tackle the newly popping up windows and figure out what wasn’t working, and why. Well, I managed to figure out that even though windows were popping up, they still needed Firefox to function properly (which really is a no brainer considering the second I clicked on a tab that needed Firefox it would explode and throw an exception). Almost every tab within the command window requires you to link it to a browser in order for it to work properly. Even then, commands that executed local URLs still exploded, but remote URLs worked fine. Normally I would think it would be the other way around.

Around this time I came to the conclusion that there needed to be some way to tell if Ubiquity was running under Firefox or Ubiquity. I mean, if we’re going to completely alter Ubiquity code to run under Thunderbird, it would suck if someone has to rewrite an entire function just to get it running under Firefox or vice versa. Having one command pop up a window in Firefox but not Thunderbird would be kind of silly. I mentioned this to jono and told him about the whole issue having to replace every Utils command so that a Thunderbird window would load instead of exceptions being thrown. Jono said to me, “Why don’t you just edit Utils and put your code in there?” Well this is one of those... “...” moments. You kind sit there going “I can do that?” First thing I naturally do is ask where I can find Utils, but before anyone can answer, I see a little file called Utils.js. “Nevermind”, I say.

Ok so Utils is a Ubiquity command. Great... thank god I didn’t go altering external commands to get their windows to pop up. That would have been a massive waste of time. So I look at Utils.openUrlinBrowser, comment out EVERYTHING, and put my line of code in to pop up a window. I remove every line that I had replaced Utils.openUrlinBrowser with and put Utils.openUrlinBrowser back in. Ok well... now I have ONE line of code that pops up windows for Thunderbird commands. Great... fantastic... I wasted so much time going through the source finding every command I could and “fixing” it so that a window pops up. I could have just done it here. This is just one of those moments where I feel like a supreme idiot. Not just any kind of supreme idiot mind you... the kind that you’d lock away in a crazy house and your cell mate would say, “Man you’re dumb.” Oh well, I’m over it already.

Despite being able to plop a window pop up command in one spot and have it work for all existing code, chances are we’d still need to know what environment Ubiquity is running over. It’s great that I commented out all that code to get Thunderbird windows to pop up when a command needs one, but if it’s commented out and it’s in Firefox... well... it won’t work. Well it seems that jono felt the same way, and this was created http://labs.toolness.com/trac/ticket/353. Hey, there’s something else for me to do!

Over all I feel the entire experience was worthwhile. Working on this project was completely different than any school assignment I’ve ever done. Usually with those, you’re on your own. If you can’t get something to work, you struggle with it until someone from class or your professor has time to sit down with you and help. Exchanging code through IRC, pastebin, and the repository is a breeze, and there’s no plagiarism to boot. Throughout the entire process, I’ve felt like a child that’s first learning to walk. Or rather... a child that grew up a little bit but didn’t pay attention to anything anyone said. Totally should have paid more attention to Javascript when we were learning it. Relearning it was definitely a pain.

Of course, things breaking without knowing why was pretty frustrating. However, I find that a good, healthy nerd rage usually relieves all stress and makes me ready to go at it once again. Nerd raging usually consists of saying, “Screw it!”, getting up, watching some TV and eating some food.

Oh on another note, I spent a lot of time trying to make a XPI file out of this Ubiquity build (about a days worth of time) only to have it keep crapping out on me. Well, it appears that I needed to use python to create the XPI build, and couldn’t do it manually. Should have asked about why my XPI was failing earlier.

Stupid things I did while working on this project:

- Installed the wrong version of Thunderbird on my XP machine. I installed the right version on my Vista box! That gave me errors for a long time.
- COMPLETELY wasted the repository. I was using an editor that used Windows end lines. If you want to merge with Linux end lines you need to use a text editor that will use Linux end lines in files. I’ve been using EditPad Lite. Just a couple of clicks and you can start using Linux end lines. On that note, doing a hg merge, seeing a ton of errors, going “Meh whatever” and doing a hg push isn’t exactly the brightest thing to do. It trashes the entire repository.
- Didn’t ask enough questions. I thought I was being a pain and asked a lot of questions, but at this point I think I actually didn’t ask enough questions. If I had asked more questions, chances are I would have found out about Utils much sooner and wouldn’t have wasted a day trying to make a XPI file from my current Ubiquity build.

No comments: