Replaced check_pid to use psutil as opposed to deal directly with win32 API

This commit is contained in:
Manuel Cortez 2022-12-10 18:29:59 -06:00
parent b57a430dc5
commit ffbb67765d
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
3 changed files with 9 additions and 12 deletions

View File

@ -2,8 +2,9 @@ TWBlue Changelog
## changes in this version
* per popular request, We will generate a 32-bit portable version of TWBlue available for Windows 7 operating systems. This version will not be supported in our automatic updater, so in case using such version, you would need to download it manually every time there is a new update. TWBlue will continue to be available for Windows 7 as long as it is possible to build it using Python 3.7.
* Fixed a couple of bugs that were making TWBlue unable to be opened in some computers.
* per popular request, We will generate a 32-bit portable version of TWBlue available for Windows 7 operating systems. This version will not be supported in our automatic updater, so in case of using such version, you would need to download it manually every time there is a new update. TWBlue will continue to be available for Windows 7 as long as it is possible to build it using Python 3.7.
* Fixed a couple of bugs that were making TWBlue unable to be opened in some computers, related to our translator module and some COM objects handled incorrectly.
* Fixed an issue that was making TWBlue unable to open in certain computers due to errors related to Win32 API'S.
* Twitter:
* Fixed a bug that was making sent direct messages to be placed in received direct messages buffer.
* When quoting a tweet, you can use all 280 characters to send your quoted tweet, as opposed to the 256 characters TWBlue allowed before.

View File

@ -50,6 +50,7 @@ numpy
pillow
charset-normalizer
demoji
psutil
git+https://github.com/accessibleapps/libloader
git+https://github.com/accessibleapps/platform_utils
git+https://github.com/accessibleapps/accessible_output2

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from win32com.client import GetObject
import httpcore
httpcore.SyncHTTPTransport = httpcore.AsyncHTTPProxy
import sys
@ -16,6 +15,7 @@ import paths
# ToDo: Remove this soon as this is done already when importing the paths module.
if os.path.exists(os.path.join(paths.app_path(), "Uninstall.exe")):
paths.mode="installed"
import psutil
import commandline
import config
import output
@ -109,21 +109,16 @@ def donation():
webbrowser.open_new_tab(_("https://twblue.es/donate"))
config.app["app-settings"]["donation_dialog_displayed"] = True
def is_running(pid):
"Check if the process with ID pid is running. Adapted from https://stackoverflow.com/a/568589"
WMI = GetObject('winmgmts:')
processes = WMI.InstancesOf('Win32_Process')
return [process.Properties_('ProcessID').Value for process in processes if process.Properties_('ProcessID').Value == pid]
def check_pid():
"Insures that only one copy of the application is running at a time."
"Ensures that only one copy of the application is running at a time."
pidpath = os.path.join(os.getenv("temp"), "{}.pid".format(application.name))
if os.path.exists(pidpath):
with open(pidpath) as fin:
pid = int(fin.read())
if is_running(pid):
p = psutil.Process(pid=pid)
if p.is_running():
# Display warning dialog
commonMessageDialogs.common_error(_(u"{0} is already running. Close the other instance before starting this one. If you're sure that {0} isn't running, try deleting the file at {1}. If you're unsure of how to do this, contact the {0} developers.").format(application.name, pidpath))
commonMessageDialogs.common_error(_("{0} is already running. Close the other instance before starting this one. If you're sure that {0} isn't running, try deleting the file at {1}. If you're unsure of how to do this, contact the {0} developers.").format(application.name, pidpath))
sys.exit(1)
else:
commonMessageDialogs.dead_pid()