From b39eefb4f570b0e0ec16942b7341689cc01d57ae Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sun, 30 Sep 2018 21:29:04 -0700 Subject: [PATCH] cross-platform Popen with hidden window --- WakaTime.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/WakaTime.py b/WakaTime.py index 0fa319f..7818a2a 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -18,6 +18,7 @@ import json import os import platform import re +import subprocess import sys import time import threading @@ -25,7 +26,7 @@ import traceback import urllib import webbrowser from datetime import datetime -from subprocess import Popen, STDOUT, PIPE +from subprocess import STDOUT, PIPE from zipfile import ZipFile try: import _winreg as winreg # py2 @@ -42,6 +43,8 @@ except ImportError: is_py2 = (sys.version_info[0] == 2) is_py3 = (sys.version_info[0] == 3) +is_win = platform.system() == 'Windows' + if is_py2: def u(text): @@ -91,6 +94,21 @@ else: )) +class Popen(subprocess.Popen): + """Patched Popen to prevent opening cmd window on Windows platform.""" + + def __init__(self, *args, **kwargs): + startupinfo = kwargs.get('startupinfo') + if is_win or True: + try: + startupinfo = startupinfo or subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + except AttributeError: + pass + kwargs['startupinfo'] = startupinfo + super(Popen, self).__init__(*args, **kwargs) + + # globals HEARTBEAT_FREQUENCY = 2 ST_VERSION = int(sublime.version())