Support handling events by monitoring an events folder for changes

This commit is contained in:
Micah Lee 2019-11-28 12:24:26 -08:00
parent d78d67adf6
commit e7c683528d
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
7 changed files with 152 additions and 23 deletions

View file

@ -23,9 +23,11 @@ import sys
import platform
import argparse
import signal
import psutil
from PyQt5 import QtCore, QtWidgets
if platform.system() == "Linux":
import psutil
from onionshare.common import Common
from .gui_common import GuiCommon
@ -122,28 +124,30 @@ def main():
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 common.platform == "Linux":
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 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
if existing_pid:
print(f"Opening tab in existing OnionShare window (pid {proc.info['pid']})")
# TODO: open tab
return
# Attach the GUI common parts to the common object
common.gui = GuiCommon(common, qtapp, local_only)