mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-14 13:41:25 -05:00
If there is an existing onionshare-gui process, open a new tab and quit
This commit is contained in:
parent
92a7dd364e
commit
4d9625514c
@ -21,4 +21,5 @@ requests==2.22.0
|
|||||||
stem==1.7.1
|
stem==1.7.1
|
||||||
urllib3==1.25.3
|
urllib3==1.25.3
|
||||||
Werkzeug==0.15.6
|
Werkzeug==0.15.6
|
||||||
watchdog==0.9.0
|
watchdog==0.9.0
|
||||||
|
psutil==5.6.7
|
@ -23,11 +23,10 @@ import sys
|
|||||||
import platform
|
import platform
|
||||||
import argparse
|
import argparse
|
||||||
import signal
|
import signal
|
||||||
|
import json
|
||||||
|
import psutil
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
if platform.system() == "Linux":
|
|
||||||
import psutil
|
|
||||||
|
|
||||||
from onionshare.common import Common
|
from onionshare.common import Common
|
||||||
|
|
||||||
from .gui_common import GuiCommon
|
from .gui_common import GuiCommon
|
||||||
@ -110,6 +109,9 @@ def main():
|
|||||||
# Verbose mode?
|
# Verbose mode?
|
||||||
common.verbose = verbose
|
common.verbose = verbose
|
||||||
|
|
||||||
|
# Attach the GUI common parts to the common object
|
||||||
|
common.gui = GuiCommon(common, qtapp, local_only)
|
||||||
|
|
||||||
# Validation
|
# Validation
|
||||||
if filenames:
|
if filenames:
|
||||||
valid = True
|
valid = True
|
||||||
@ -124,33 +126,37 @@ def main():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Is there another onionshare-gui running?
|
# Is there another onionshare-gui running?
|
||||||
if common.platform == "Linux":
|
existing_pid = None
|
||||||
existing_pid = None
|
for proc in psutil.process_iter(attrs=["pid", "name", "cmdline"]):
|
||||||
for proc in psutil.process_iter(attrs=["pid", "name", "cmdline"]):
|
if proc.info["pid"] == os.getpid():
|
||||||
if proc.info["pid"] == os.getpid():
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
if proc.info["name"] == "onionshare-gui":
|
if proc.info["name"] == "onionshare-gui":
|
||||||
existing_pid = proc.info["pid"]
|
existing_pid = proc.info["pid"]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Dev mode onionshare?
|
# Dev mode onionshare?
|
||||||
if proc.info["cmdline"] and len(proc.info["cmdline"]) >= 2:
|
if proc.info["cmdline"] and len(proc.info["cmdline"]) >= 2:
|
||||||
if (
|
if (
|
||||||
os.path.basename(proc.info["cmdline"][0]).lower() == "python"
|
os.path.basename(proc.info["cmdline"][0]).lower() == "python"
|
||||||
and os.path.basename(proc.info["cmdline"][1])
|
and os.path.basename(proc.info["cmdline"][1]) == "onionshare-gui"
|
||||||
== "onionshare-gui"
|
):
|
||||||
):
|
existing_pid = proc.info["pid"]
|
||||||
existing_pid = proc.info["pid"]
|
break
|
||||||
break
|
|
||||||
|
|
||||||
if existing_pid:
|
if existing_pid:
|
||||||
print(f"Opening tab in existing OnionShare window (pid {proc.info['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
|
# Make an event for the existing OnionShare window
|
||||||
common.gui = GuiCommon(common, qtapp, local_only)
|
if filenames:
|
||||||
|
obj = {"type": "new_share_tab", "filenames": filenames}
|
||||||
|
else:
|
||||||
|
obj = {"type": "new_tab"}
|
||||||
|
|
||||||
|
# Write that event to disk
|
||||||
|
with open(common.gui.events_filename, "a") as f:
|
||||||
|
f.write(json.dumps(obj) + "\n")
|
||||||
|
return
|
||||||
|
|
||||||
# Launch the gui
|
# Launch the gui
|
||||||
main_window = MainWindow(common, filenames)
|
main_window = MainWindow(common, filenames)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user