about summary refs log tree commit diff
path: root/kcc.py
diff options
context:
space:
mode:
Diffstat (limited to 'kcc.py')
-rwxr-xr-xkcc.py41
1 files changed, 25 insertions, 16 deletions
diff --git a/kcc.py b/kcc.py
index dd245cb..0029ad7 100755
--- a/kcc.py
+++ b/kcc.py
@@ -23,29 +23,38 @@ if sys.version_info[0] != 3:
     print('ERROR: This is Python 3 script!')
     exit(1)
 
-# OS specific PATH variable workarounds
+# OS specific workarounds
 import os
 if sys.platform.startswith('darwin'):
-    if 'RESOURCEPATH' not in os.environ:
-        os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/:' + os.environ['PATH']
-    else:
-        os.environ['PATH'] = './../Resources:/usr/local/bin:/usr/bin:/bin'
+    if getattr(sys, 'frozen', False):
+        os.environ['PATH'] = os.path.dirname(os.path.abspath(sys.executable)) + \
+            '/../Resources:/usr/local/bin:/usr/bin:/bin'
         os.system('defaults write com.kindlecomicconverter.KindleComicConverter ApplePersistenceIgnoreState YES')
+        os.system('defaults write com.kindlecomicconverter.KindleComicConverter NSInitialToolTipDelay -int 1000')
+    else:
+        os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/osx/:' + os.environ['PATH']
 elif sys.platform.startswith('win'):
-    if getattr(sys, 'frozen', False):
-        os.chdir(os.path.dirname(os.path.abspath(sys.executable)))
+    import multiprocessing.popen_spawn_win32 as forking
 
-        # Implementing dummy stdout and stderr for frozen Windows release
-        class FakeSTD(object):
-            def write(self, string):
-                pass
+    class _Popen(forking.Popen):
+        def __init__(self, *args, **kw):
+            if hasattr(sys, 'frozen'):
+                # noinspection PyProtectedMember
+                os.putenv('_MEIPASS2', sys._MEIPASS)
+            try:
+                super(_Popen, self).__init__(*args, **kw)
+            finally:
+                if hasattr(sys, 'frozen'):
+                    if hasattr(os, 'unsetenv'):
+                        os.unsetenv('_MEIPASS2')
+                    else:
+                        os.putenv('_MEIPASS2', '')
+    forking.Popen = _Popen
 
-            def flush(self):
-                pass
-        sys.stdout = FakeSTD()
-        sys.stderr = FakeSTD()
+    if getattr(sys, 'frozen', False):
+        os.chdir(os.path.dirname(os.path.abspath(sys.executable)))
     else:
-        os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/;' + os.environ['PATH']
+        os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/windows/;' + os.environ['PATH']
         os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
 from kcc.shared import dependencyCheck