diff options
author | Joey Hess <joey@kitenet.net> | 2012-10-27 00:42:14 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-10-27 00:42:14 -0400 |
commit | ce5b38aa1dbd1e320c5247d95344e373bf03e7cf (patch) | |
tree | 99e55c492457520f016188e00ba553c23f8bc187 /Assistant/Threads | |
parent | 5b7d00b6e9f79f4e0a2093feea58ad164a766ab2 (diff) |
reconnect XMPP when NetWatcher notices a change
Diffstat (limited to 'Assistant/Threads')
-rw-r--r-- | Assistant/Threads/NetWatcher.hs | 1 | ||||
-rw-r--r-- | Assistant/Threads/PushNotifier.hs | 18 |
2 files changed, 13 insertions, 6 deletions
diff --git a/Assistant/Threads/NetWatcher.hs b/Assistant/Threads/NetWatcher.hs index 883a7bef5..ed64541c3 100644 --- a/Assistant/Threads/NetWatcher.hs +++ b/Assistant/Threads/NetWatcher.hs @@ -70,6 +70,7 @@ dbusThread st dstatus scanremotes pushnotifier = ) handleconn = do debug thisThread ["detected network connection"] + notifyRestart pushnotifier handleConnection st dstatus scanremotes pushnotifier onerr e _ = do runThreadState st $ diff --git a/Assistant/Threads/PushNotifier.hs b/Assistant/Threads/PushNotifier.hs index 46a1d3ebf..f6058b465 100644 --- a/Assistant/Threads/PushNotifier.hs +++ b/Assistant/Threads/PushNotifier.hs @@ -28,12 +28,19 @@ import Data.Time.Clock thisThread :: ThreadName thisThread = "PushNotifier" +controllerThread :: PushNotifier -> IO () -> IO () +controllerThread pushnotifier a = forever $ do + tid <- forkIO a + waitRestart pushnotifier + killThread tid + pushNotifierThread :: ThreadState -> DaemonStatusHandle -> PushNotifier -> NamedThread -pushNotifierThread st dstatus pushnotifier = NamedThread thisThread $ do - v <- runThreadState st $ getXMPPCreds - case v of - Nothing -> return () -- no creds? exit thread - Just c -> loop c =<< getCurrentTime +pushNotifierThread st dstatus pushnotifier = NamedThread thisThread $ + controllerThread pushnotifier $ do + v <- runThreadState st $ getXMPPCreds + case v of + Nothing -> noop + Just c -> loop c =<< getCurrentTime where loop c starttime = do void $ connectXMPP c $ \jid -> do @@ -53,7 +60,6 @@ pushNotifierThread st dstatus pushnotifier = NamedThread thisThread $ do threadDelaySeconds (Seconds 300) loop c =<< getCurrentTime - sendnotifications = forever $ do us <- liftIO $ waitPush pushnotifier let payload = [extendedAway, encodePushNotification us] |