Detect if another onionshare-gui process is running

This commit is contained in:
Micah Lee 2019-10-20 19:18:56 -07:00
parent 9e434abd9c
commit 30949cf196
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -23,13 +23,14 @@ import sys
import platform
import argparse
import signal
from .widgets import Alert
import psutil
from PyQt5 import QtCore, QtWidgets
from onionshare.common import Common
from onionshare.onion import Onion
from onionshare.onionshare import OnionShare
from .widgets import Alert
from .onionshare_gui import OnionShareGui
@ -132,6 +133,30 @@ def main():
if not valid:
sys.exit()
# Is there another onionshare-gui running?
existing_pid = None
for proc in psutil.process_iter(attrs=["pid", "name", "cmdline"]):
if proc.info["pid"] == os.getpid():
continue
if proc.info["name"] == "onionshare-gui":
existing_pid = proc.info["pid"]
break
else:
# Dev mode onionshare?
if proc.info["cmdline"] and len(proc.info["cmdline"]) >= 2:
if (
os.path.basename(proc.info["cmdline"][0]).lower() == "python"
and os.path.basename(proc.info["cmdline"][1]) == "onionshare-gui"
):
existing_pid = proc.info["pid"]
break
if existing_pid:
print(f"Opening tab in existing OnionShare window (pid {proc.info['pid']})")
# TODO: open tab
return
# Start the Onion
onion = Onion(common)