import xbmc
import urllib2
import threading
from pulsar.config import PULSARD_HOST


class PulsarMonitor(xbmc.Monitor):
    def __init__(self):
        self._closing = threading.Event()

    @property
    def closing(self):
        return self._closing

    def onAbortRequested(self):
        # Only when closing Kodi
        if xbmc.abortRequested:
            self._closing.set()
            self._closing.clear()

    def onSettingsChanged(self):
        try:
            urllib2.urlopen("%s/reload" % PULSARD_HOST)
        except:
            pass
