]> git.lizzy.rs Git - torbrowser-launcher.git/blobdiff - torbrowser-launcher
used wmctrl to finish #17
[torbrowser-launcher.git] / torbrowser-launcher
index a42a9a4e0085c682e40f7fdbde2a98393f9e3d3b..8f57cd50c378e3b3a2da0e54b04943bf20332933 100755 (executable)
@@ -11,7 +11,7 @@ import pygtk
 pygtk.require('2.0')
 import gtk
 
-import os, sys, subprocess, locale, urllib2, gobject, time, pickle, json
+import os, sys, subprocess, locale, urllib2, gobject, time, pickle, json, tarfile, psutil
 
 from twisted.web.client import Agent, ResponseDone
 from twisted.web.http_headers import Headers
@@ -61,6 +61,47 @@ class TorBrowserLauncher:
             if self.load_settings():
                 self.build_paths(self.settings['latest_version'])
 
+                # is tbb already running and we just need to open a new firefox?
+                if self.settings['installed_version']:
+                    vidalia_pid = None
+                    firefox_pid = None
+                    for p in psutil.process_iter():
+                        try:
+                            if p.exe == self.paths['file']['vidalia_bin']:
+                                vidalia_pid = p.pid
+                            if p.exe == self.paths['file']['firefox_bin']:
+                                firefox_pid = p.pid
+                        except:
+                            pass
+
+                    if vidalia_pid and not firefox_pid:
+                        print _('Vidalia is already open, but Firefox is closed. Launching new Firefox.')
+                        subprocess.Popen([self.paths['file']['firefox_bin'], '-no-remote', '-profile', self.paths['file']['firefox_profile']])
+                        return
+                    elif vidalia_pid and firefox_pid:
+                        print _('Vidalia and Firefox are already open, bringing them to focus')
+
+                        # figure out the window ids of vidalia and firefox
+                        vidalia_win_id = None
+                        firefox_win_id = None
+                        p = subprocess.Popen(['wmctrl', '-l', '-p'], stdout=subprocess.PIPE)
+                        for line in p.stdout.readlines():
+                            line_split = line.split()
+                            win_id = line_split[0]
+                            win_pid = int(line_split[2])
+                            if win_pid == vidalia_pid:
+                                vidalia_win_id = win_id
+                            if win_pid == firefox_pid:
+                                firefox_win_id = win_id
+
+                        # bring firefox to front, then vidalia
+                        if firefox_win_id:
+                            subprocess.call(['wmctrl', '-i', '-a', firefox_win_id])
+                        if vidalia_win_id:
+                            subprocess.call(['wmctrl', '-i', '-a', vidalia_win_id])
+
+                        return
+
                 # how long was it since the last update check?
                 # 86400 seconds = 24 hours
                 current_timestamp = int(time.time())
@@ -190,6 +231,9 @@ class TorBrowserLauncher:
                     'settings': tbb_data+'/settings',
                     'version': tbb_data+'/version',
                     'start': tbb_data+'/tbb/'+self.architecture+'/tor-browser_'+self.language+'/start-tor-browser',
+                    'vidalia_bin': tbb_data+'/tbb/'+self.architecture+'/tor-browser_'+self.language+'/App/vidalia',
+                    'firefox_bin': tbb_data+'/tbb/'+self.architecture+'/tor-browser_'+self.language+'/App/Firefox/firefox',
+                    'firefox_profile': tbb_data+'/tbb/'+self.architecture+'/tor-browser_'+self.language+'/Data/profile',
                     'update_check': tbb_data+'/download/RecommendedTBBVersions',
                     'icon': '/usr/share/pixmaps/torbrowser80.xpm',
                     'torproject_pem': '/usr/share/torbrowser-launcher/torproject.pem',
@@ -354,7 +398,7 @@ class TorBrowserLauncher:
             self.download('tarball', self.paths['url']['tarball'], self.paths['file']['tarball'])
 
         elif task == 'download_tarball_sig':
-            print _('Downloading'), +self.paths['url']['tarball_sig']
+            print _('Downloading'), self.paths['url']['tarball_sig']
             self.download('signature', self.paths['url']['tarball_sig'], self.paths['file']['tarball_sig'])
 
         elif task == 'verify':
@@ -492,9 +536,16 @@ class TorBrowserLauncher:
         self.progressbar.set_fraction(0) 
         self.progressbar.set_text(_('Installing'))
         self.progressbar.show()
+        self.refresh_gtk()
 
-        p = subprocess.Popen(['tar', '-xf', self.paths['file']['tarball'], '-C', self.paths['dir']['tbb']], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-        self.pulse_until_process_exits(p)
+        # make sure this file is a tarfile
+        if tarfile.is_tarfile(self.paths['file']['tarball']):
+          tf = tarfile.open(self.paths['file']['tarball'])
+          tf.extractall(self.paths['dir']['tbb'])
+        else:
+            self.set_gui('task', _("Tor Browser Launcher doesn't understand the file format of {0}"), ['start_over'], False)
+            self.clear_ui()
+            self.build_ui()
 
         # installation is finished, so save installed_version
         self.settings['installed_version'] = self.settings['latest_version']