As we use web applications more and more on core tasks (email, calendar, office) I have found that I sometimes get frustrated when some annoying piece of Flash on a random web page brings down my entire browser process (including the web applications that I care about).
Some browsers allow you to run multiple instances in their own world. For others you could hack around that by having multiple copies of the browser. I have gone through phases of compartmentalizing my work on various browsers.
Development work on a Firefox instance because I want to use Firebug
Fluffy browsing on WebKit nightly (to try to be a tester too)
Apps in Safari
My main problem with this is that I normally also want Firefox for certain apps because I make heavy use of Greasemonkey. I couldn't do Gmail without at this point (let alone the other sites).
I am used to having my calendar on window 2 of VirtueDesktop (iCal). I am not experimenting with Google Calendar, and I want to do the same. Instead of just having an instance running Google Calendar over there, I decided to try to built a wrapper around a browser component.
I am trying this in both Mac OS X Cocoa, and Adobe Apollo.
Today we will discuss the OS X version.
In theory the hard work is definitely already done for us. The WebKit component is nicely done for us, and the documentation is thorough.
I decided to try to follow the "Multiple Windows" example:
You can implement multiple windows in a Web Kit application easily by beginning with a Cocoa document-based architecture as follows:
Using Xcode, create a document-based Cocoa application. Your new project file will already contain the needed classes and interface files to support multiple windows (namely MyDocument.h, MyDocument.m, and MyDocument.nib).
Add the Web Kit frameworks to your project.
Open MyDocument.nib using Interface Builder and drag a WebView from the Cocoa��GraphicsViews palette to your document window.
Create a webView outlet in MyDocument.h and read the file into Interface Builder. Connect the webView outlet of the File��s Owner to the WebView object you created in the previous step.
Add code to MyDocument.m to load a default page. You can add this code fragment to the windowControllerDidLoadNib: method:
As a newbie to Obj-C and Cocoa, a couple of these instructions were light.
Creating the project was simple. It wasn't hard to see 'document-based'
Adding the Web Kit framework was simple too, although it seems like there are several ways to skin the cat. I did Project - Add to Project - Find System/Library/Frameworks/WebKit.framework. Done.
I found the WebView pane and it was obvious to drag the component that looked like Safari onto the main panel.
I have never created an "outlet" before, so this took some time to play. I added IBOutlet WebView *webView; to MyDocument.h... but then how do you read it into Interface Builder? In some ways Interface Builder is great, but it was also a bit frustrating to work with. I felt like I was constantly looking to click on the right area to then be able to do things. E.g. most of the time "Classes - Read Files" was greyed out, until you click on File's Owner (from the Instances tab). Then, connecting the darn thing drove me nuts. I am not a mouse guy. I don't like to draw my applications. I wanted to select the WebView component that I created, and in connections let me select the webView variable that I just read in. The tool wouldn't let me. It kept saying "You need a component of type WebView". It was! Trying to manually connect was a pain until I worked out that it just needed a darn right click (ironic coming from Apple) to drag the connection from the "File's Owner" to the WebView component in the window. With that, the connection in the inspector showed up nicely. Why wouldn't it just have a drop down to show the ONLY COMPONENT out there that was of that type? Why make me draw?
After adding the code to point to Gmail as a test, I launched the app, and indeed a window showed up with the web page in it. Great! At this point we are pretty unusable though.
First, Gmail was showing me the 'basic' HTML view and telling me that I wasn't supported. At this point I had a couple of options. I could put in the hard coded URL to Gmail that says "do not check the browser, just show me the good ones", or I could change the User-Agent to tell people that this was indeed something decent.
While you are there you probably want to setup nice title bar names and such via:
[webView setGroupName:@"Google Calendar"];
Window resizing and linkage
The app works great until you click on something or try to resize the window :) At this point it doesn't work. At this point we need to go through and set the sizing to allow for happiness, and to let link clicks target the view.
It was at this point that I remembered Michael McCracken had done a wrapper for Gmail back in time: "All it does is load Gmail in a nice big window and duck out of your way. No location bar. And no bookmarks."
I grabbed his code which had dealt with this, and tweaked it to work for my needs.
Downloads
If you fancy taking a look at the source, or just running Gmail or Google Calendar as a normal app that you can put in your dock, and live in its own process, download: