mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-27 08:19:41 -05:00
Detect if another onionshare-gui process is running
This commit is contained in:
parent
9e434abd9c
commit
30949cf196
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user