From e2583c7d364841b7d8dd707672e057c62d79eb93 Mon Sep 17 00:00:00 2001 From: GRiker Date: Wed, 13 Jun 2012 16:51:34 -0600 Subject: [PATCH] Added code to detect iTunes sandboxing --- src/calibre/devices/apple/driver.py | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 09d0466f40..cf8eee706c 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -101,8 +101,6 @@ class AppleOpenFeedback(OpenFeedback): return Dialog(parent, self) - - class DriverBase(DeviceConfig, DevicePlugin): # Needed for config_widget to work FORMATS = ['epub', 'pdf'] @@ -212,6 +210,15 @@ class ITUNES(DriverBase): "Unsupported direct connect mode. " "See http://www.mobileread.com/forums/showthread.php?t=118559 " "for instructions on using 'Connect to iTunes'") + ITUNES_SANDBOX_LOCKOUT_MESSAGE = _( + '

Unable to communicate with iTunes.

' + "

As of iTunes version 10.6.3, application 'sandboxing' " + 'was implemented by Apple, disabling inter-application communications ' + 'between iTunes and third-party applications.

' + '

Refer to the forum post ' + 'Apple implements sandboxing for iTunes 10.6.3 ' + 'for more information.

' + '

') # Product IDs: # 0x1291 iPod Touch @@ -840,6 +847,9 @@ class ITUNES(DriverBase): we need to talk to iTunes to discover if there's a connected iPod ''' + if self.iTunes is None: + raise OpenFeedback(self.ITUNES_SANDBOX_LOCKOUT_MESSAGE) + if DEBUG: logger().info("ITUNES.open(connected_device: %s)" % repr(connected_device)) @@ -2372,6 +2382,21 @@ class ITUNES(DriverBase): self.iTunes = appscript.app('iTunes') self.initial_status = 'already running' + ''' + Test OSA. If we can't get the app name, we can't talk to iTunes. + As of iTunes 10.6.3 (June 2012), sandboxing was implemented disabling OSA + interapp communications. + If unable to communicate with iTunes, set self.iTunes to None, then + report to user in open() + ''' + try: + foo = self.iTunes.name() + except: + self.iTunes = None + if DEBUG: + logger().info(" unable to communicate with iTunes, raising dialog to user") + return + ''' # Read the current storage path for iTunes media cmd = "defaults read com.apple.itunes NSNavLastRootDirectory" @@ -3319,6 +3344,9 @@ class ITUNES_ASYNC(ITUNES): Note that most of the initialization is necessarily performed in can_handle(), as we need to talk to iTunes to discover if there's a connected iPod ''' + if self.iTunes is None: + raise OpenFeedback(self.ITUNES_SANDBOX_LOCKOUT_MESSAGE) + if DEBUG: logger().info("ITUNES_ASYNC.open(connected_device: %s)" % repr(connected_device))