Fix IPCInterface on Windows
This commit is contained in:
parent
80fdc3356c
commit
204f6ee89e
|
@ -111,9 +111,6 @@ DEFAULT_PREFS = {
|
||||||
|
|
||||||
class GtkUI:
|
class GtkUI:
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
# Initialize gdk threading
|
|
||||||
gtk.gdk.threads_init()
|
|
||||||
gobject.threads_init()
|
|
||||||
|
|
||||||
# Initialize gettext
|
# Initialize gettext
|
||||||
try:
|
try:
|
||||||
|
@ -141,7 +138,6 @@ class GtkUI:
|
||||||
from win32api import SetConsoleCtrlHandler
|
from win32api import SetConsoleCtrlHandler
|
||||||
from win32con import CTRL_CLOSE_EVENT
|
from win32con import CTRL_CLOSE_EVENT
|
||||||
from win32con import CTRL_SHUTDOWN_EVENT
|
from win32con import CTRL_SHUTDOWN_EVENT
|
||||||
result = 0
|
|
||||||
def win_handler(ctrl_type):
|
def win_handler(ctrl_type):
|
||||||
log.debug("ctrl_type: %s", ctrl_type)
|
log.debug("ctrl_type: %s", ctrl_type)
|
||||||
if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT:
|
if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT:
|
||||||
|
@ -152,34 +148,19 @@ class GtkUI:
|
||||||
# Make sure gtkui.conf has at least the defaults set
|
# Make sure gtkui.conf has at least the defaults set
|
||||||
self.config = deluge.configmanager.ConfigManager("gtkui.conf", DEFAULT_PREFS)
|
self.config = deluge.configmanager.ConfigManager("gtkui.conf", DEFAULT_PREFS)
|
||||||
|
|
||||||
# We need to check for the existence of 'deluged' in the system path
|
|
||||||
# before allowing to continue in classic mode.
|
|
||||||
if self.config["classic_mode"]:
|
|
||||||
try:
|
|
||||||
if deluge.common.windows_check():
|
|
||||||
import win32api
|
|
||||||
win32api.WinExec("deluged --version")
|
|
||||||
else:
|
|
||||||
import subprocess
|
|
||||||
retcode = subprocess.call("deluged" + " --version", shell=True)
|
|
||||||
log.debug("retcode: %s", retcode)
|
|
||||||
if retcode == 127:
|
|
||||||
log.error("Unable to find deluged!")
|
|
||||||
self.config["classic_mode"] = False
|
|
||||||
except Exception, e:
|
|
||||||
log.error("Unable to find deluged: %s", e)
|
|
||||||
self.config["classic_mode"] = False
|
|
||||||
|
|
||||||
# We need to check on exit if it was started in classic mode to ensure we
|
# We need to check on exit if it was started in classic mode to ensure we
|
||||||
# shutdown the daemon.
|
# shutdown the daemon.
|
||||||
self.started_in_classic = self.config["classic_mode"]
|
self.started_in_classic = self.config["classic_mode"]
|
||||||
|
|
||||||
# Start the Dbus Interface before anything else.. Just in case we are
|
# Start the IPC Interface before anything else.. Just in case we are
|
||||||
# already running.
|
# already running.
|
||||||
self.queuedtorrents = QueuedTorrents()
|
self.queuedtorrents = QueuedTorrents()
|
||||||
|
|
||||||
self.ipcinterface = IPCInterface(args)
|
self.ipcinterface = IPCInterface(args)
|
||||||
|
|
||||||
|
# Initialize gdk threading
|
||||||
|
gtk.gdk.threads_init()
|
||||||
|
gobject.threads_init()
|
||||||
|
|
||||||
# We make sure that the UI components start once we get a core URI
|
# We make sure that the UI components start once we get a core URI
|
||||||
client.set_disconnect_callback(self.__on_disconnect)
|
client.set_disconnect_callback(self.__on_disconnect)
|
||||||
|
|
||||||
|
|
|
@ -56,22 +56,61 @@ class IPCInterface(component.Component):
|
||||||
if not os.path.exists(deluge.configmanager.get_config_dir("ipc")):
|
if not os.path.exists(deluge.configmanager.get_config_dir("ipc")):
|
||||||
os.makedirs(deluge.configmanager.get_config_dir("ipc"))
|
os.makedirs(deluge.configmanager.get_config_dir("ipc"))
|
||||||
|
|
||||||
|
# Make the args absolute paths
|
||||||
|
_args = []
|
||||||
|
for arg in args:
|
||||||
|
_args.append(os.path.abspath(arg))
|
||||||
|
args = _args
|
||||||
|
|
||||||
socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk")
|
socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk")
|
||||||
|
|
||||||
try:
|
if deluge.common.windows_check():
|
||||||
self.factory = Factory()
|
# If we're on windows we need to check the global mutex to see if deluge is
|
||||||
self.factory.protocol = IPCProtocolServer
|
# already running.
|
||||||
reactor.listenUNIX(socket, self.factory, wantPID=True)
|
import win32event
|
||||||
except twisted.internet.error.CannotListenError, e:
|
import win32api
|
||||||
log.info("Deluge is already running! Sending arguments to running instance..")
|
import winerror
|
||||||
self.factory = ClientFactory()
|
self.mutex = win32event.CreateMutex(None, False, "deluge")
|
||||||
self.factory.args = args
|
if win32api.GetLastError() != winerror.ERROR_ALREADY_EXISTS:
|
||||||
self.factory.protocol = IPCProtocolClient
|
# Create listen socket
|
||||||
reactor.connectUNIX(socket, self.factory, checkPID=True)
|
self.factory = Factory()
|
||||||
reactor.run()
|
self.factory.protocol = IPCProtocolServer
|
||||||
sys.exit(0)
|
import random
|
||||||
|
port = random.randrange(20000, 65535)
|
||||||
|
reactor.listenTCP(port, self.factory)
|
||||||
|
# Store the port number in the socket file
|
||||||
|
open(socket, "w").write(str(port))
|
||||||
|
# We need to process any args when starting this process
|
||||||
|
process_args(args)
|
||||||
|
else:
|
||||||
|
# Send to existing deluge process
|
||||||
|
port = int(open(socket, "r").readline())
|
||||||
|
self.factory = ClientFactory()
|
||||||
|
self.factory.args = args
|
||||||
|
self.factory.protocol = IPCProtocolClient
|
||||||
|
reactor.connectTCP("127.0.0.1", port, self.factory)
|
||||||
|
reactor.run()
|
||||||
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
process_args(args)
|
try:
|
||||||
|
self.factory = Factory()
|
||||||
|
self.factory.protocol = IPCProtocolServer
|
||||||
|
reactor.listenUNIX(socket, self.factory, wantPID=True)
|
||||||
|
except twisted.internet.error.CannotListenError, e:
|
||||||
|
log.info("Deluge is already running! Sending arguments to running instance..")
|
||||||
|
self.factory = ClientFactory()
|
||||||
|
self.factory.args = args
|
||||||
|
self.factory.protocol = IPCProtocolClient
|
||||||
|
reactor.connectUNIX(socket, self.factory, checkPID=True)
|
||||||
|
reactor.run()
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
process_args(args)
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
if deluge.common.windows_check():
|
||||||
|
import win32api
|
||||||
|
win32api.CloseHandle(self.mutex)
|
||||||
|
|
||||||
def process_args(args):
|
def process_args(args):
|
||||||
"""Process arguments sent to already running Deluge"""
|
"""Process arguments sent to already running Deluge"""
|
||||||
|
|
Loading…
Reference in New Issue