Between Linux and Anime

Kind of like Schrodinger's Cat

Associating Firefox Profiles with KDE Activities

As a heavy user of the Activities feature, I’ve always had two major itches. One was addressed when KDE 4.9 finally brought the ability to set activity window rules. The other was how only some applications had the necessary (XSMP) compliance to work properly with activities and its session restoring – in particular, a lack of compliant web browsers.

In fact, to date, the only apparently fully XSMP compliant web browser I know of is Konqueror, full stop. And while Konqueror is a pretty decent browser, its lack of a Firebug-esque DOM inspector made it increasingly inadequate for my purposes now that I do a lot of web development for my day job.

Being reduced to keeping one giant unmanageable lump of tabs in one central Firefox instance gave me plenty of incentive to think hard about the problem. Since it doesn’t look like Firefox or any other browser was gonna go compliant on its own anytime soon, the thought occurred to me if compliance might be hacked in by proxy: if I could manage the browser instance via an external program, I could deal with the session manager from my program and proxy the desired behavior onto the browser instance. So I spent some free time looking up how I might be able to externally control Firefox or Chrome or whatnot. Not surprisingly, the browsers aren’t very open to external controlling, but Firefox’s profiles feature provided just enough command line controls to be exploitable for my purposes. You could run different profiles simultaneously, with each profile being it’s own single process and conveniently remembering it’s own state/session information. So all I needed to do was write an XSMP-compliant program that keeps a Firefox profile name as state information, launches the Firefox instance so it knows its PID, killing the correct Firefox process when the activity closes and the session manager tells it to save state, and reading the profile name and relaunching the Firefox instance for it when the session restores.

So I went ahead and wrote that program, and dubbed it ‘activityfox’. It works quite well :) The proxy program needed to be a GUI application because it seems like the session manager doesn’t save and restore console ones, but with a little Kwin window-rule magic we could completely hide away the proxy program’s GUI window. Here’s a short screencast showing it in action:


OGG here

The way it works is you launch activityfox in an activity, which by proxy launches a Firefox instance with your chosen profile. activityfox will be automatically associated with the current activity, and when you stop the activity, activityfox will be asked to save state and close, and it’ll save the profile name and close it’s child Firefox process too. When you relaunch the activity, the session mechanism automatically calls up activityfox again, which reads the profile name from its saved state information, and uses that to restore the right Firefox profile instance. Since every Firefox profile instance is its own process, you can have as many Firefox profiles running in as many activities as you want, and they’ll all behave. Stopping an activity only closes it’s associated Firefox profile instance, leaving the rest alone, and restoring it restores the instance.

Source code, with build and usage instructions, can be downloaded here (Edit: it’s now on my github here). I’m afraid it’s a C++ program you need to compile: I tried to make it a python script, but for some reason it always crashes after KMainWindow::saveProperties is called, whereas the equivalent C++ program worked fine.

1239
Rate this post
Thanks!
An error occurred!


  • Facebook
  • Twitter
  • Identi.ca
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • RSS
  • Reddit

Previous

Anisong: Vidro Moyou

Next

The Interrogation Game of Reveal-Hikkikomori

17 Comments

  1. Cool idea.

    I was (am) planning to make a firefox addon that will integrate firefox with activities on two levels:
    – report the open documents to the activity manager (1st step)
    – link tab groups and activities – so the same instance of firefox would be able to handle multiple activities properly.

    This is going to take a lot of time since I don’t really know how to write firefox addons, but I hope it will be done eventually :)

    • Jason "moofang"

      I actually have no idea how to do that: talk to the activitymanager and such. This is a little of a hacky solution, but it works well enough for me until you can get a more complete solution up :)

      Actually now that I’m using this I kinda like how every activity’s Firefox instance can have its own settings and addons.

  2. It doesn’t seem like this will handle opening links from Kmail or Kopete. Have you found a solution to that? Take a look at the -no-remote flag.

    • Jason "moofang"

      I am using that flag, that’s how you get a different process/window for different firefox profiles. In my setup right now I’m using chromium as my default browser with firefoxes opening when I open activities, so all my links open in chromium. If your default browser is firefox I think all links would open in firefox’s default profile? If you want it to open in the current activity’s profile it’ll be tricky. Potentially another proxy program can communicate with activityfox to figure out which firefox profile is associated with the current activity and open links using that profile, then that proxy program can be supplied to KCM as “default browser”. Will take some thought and experimenting.

  3. Oliver Henshaw

    Whayt do you mean when you say that firefox isn’t fully XSMP compliant? Do you see problems with basic login/logout session restores or is there some special XSMP feature that activities require that the normal session restores don’t.

    If the former, this sounds like https://bugzilla.redhat.com/show_bug.cgi?id=831347#c7 – firefox was XSMP aware but needs libgnome for it to work right. The problem is that this isn’t installed anymore or pulled in by firefox, since it would bring in long-deprecated gnome tech (which in turn pulls in long-deprecated freedesktop tech like HAL). There’s some prototype libSM integration in https://bugzilla.mozilla.org/show_bug.cgi?id=694570 but nothing has happened with that in the last few months.

    So firefox may be closer to being xsmp compliant than you think. Even though it isn’t as close as we might like.

    • Jason "moofang"

      Interesting, so does that mean if I pull in libgnome I get full XSMP compliance? I need to try that when I’m free.

      The way I understand it, in order to work well with activities, an application needs to not only be able to save state and restore its state, but do it in an instance-specific fashion, so that you can have multiple sleeping activities and restoring any one will restore that specific instance of the app. Moreover with something like firefox it’ll _still_ be tricky even with such full XSMP compliance because, be default, the entirety of firefox is one single process, ie one single instance, so in order to for it to behave like konqueror does – have a window attached to each activity – you’ll still need to either open a different profile in each activity (but you won’t need a proxy program), or do something like what Ivan said above.

  4. Andrew Potter

    I’d like to have something like this for Libre-Office.

    • Jason "moofang"

      It’ll be pretty hard :( I took a quick look and libreoffice doesn’t really have a comparable invokable profile feature. The darned thing is libreoffice has enough XSMP support to support one session per user, so it restores fine if you log out/log in for example, but not if you have many activities. I guess only in the case of activities do you have many sessions used by one user. If I understand this right though this is nonetheless incomplete compliance with XSMP on libreoffice’s part and so could probably be filed as a bug to libreoffice.

      A possible incomplete hack could be to launch a proxy program with the file you want to open, so the proxy program remembers the file and restores it. However this means that if you file > open another file in libreoffice the proxy program has no way of knowing. Also, you can’t handle the new file case.

      • Jason "moofang"

        Hmmm, actually, I just had an idea that might work to help make non-compliant apps like libreoffice work better with activities. Would not be a complete solution of course, but might be better than the current state of simply doesn’t work. Let me think and try it out, I’ll make a blog post if anything ever comes of it.

  5. By the way, Blip.tv don’t allow you to link straight to the source video (ogv in this case) any more. If anyone tries to look at it, they get redirected to a short video telling them they need to view it in the embedded player or on Blip.tv.

    As far as I know, the only major video host that lets people view the original version is Vimeoh, but they only let people download it if they’re logged in to Vimeoh.

    *sigh*

    • Jason "moofang"

      Thanks for the heads up, but did you try my link? As far as I can tell it seems to work somehow – I got my friends to try it and such. Or could it be a geographical thing where certain places aren’t allowed to view/dl the source ogv (which sounds completely senseless)?

  6. OMG. you are awesome. :) :)

    I was beginning to think I’d have to do this myself ;) and I haven’t had *any* time for non-work code any more :(

  7. Satsuki

    404 – That Blip has sailed.
    I cant download .ogg too :(

    • Jason "moofang"

      Yep Blip has since changed the way it operates and has snipped me off in the process :( I’m afraid the screencast is lost now, but it doesn’t contain any critical info not described in the post. Feel free to ask here if something is unclear all the same.

  8. i made a little script to automatically use the activity ID as the firefox profile name. this saves me some energy setting things up in case i make new activities or rename activities. It’s just a bash script that needs to run from a file in the same directory as activityfox. The profiles it uses would have names like activity ids such as ‘4fc299bf-ea11-4c9d-978f-16c676c6069e’ … the purpose for the id vs a name is to keep a profile linked with an activity even if the activity is renamed

    #!/bin/bash
    activity=$(qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity)
    exec “$(dirname “$0″)/activityfox” “$activity”

Leave a Reply

Powered by WordPress & Theme by Anders Norén