@@ -132,7 +132,7 @@ instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (Widget t m)
132132 newEventWithTrigger = lift . newEventWithTrigger
133133
134134instance ( MonadRef m, Ref m ~ Ref IO, MonadRef h, Ref h ~ Ref IO --TODO: Shouldn't need to be IO
135− , MonadIO m, MonadIO h, Functor m, MonadIORestore m
135+ , MonadIO m, MonadIO h, Functor m
136136 , ReflexHost t, MonadReflexCreateTrigger t m, MonadSample t m, MonadHold t m
137137 , MonadFix m
138138 ) => MonadWidget t (Widget t (Gui t h m)) where
@@ -172,13 +172,13 @@ holdOnStartup a0 ma = do
172172 runFrameWithTriggerRef startupDoneTriggerRef a
173173 hold a0 startupDone
174174
175−mainWidget :: Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> IO ()
175+mainWidget :: Widget Spider (Gui Spider (WithWebView SpiderHost) (HostFrame Spider)) () -> IO ()
176176mainWidget w = runWebGUI $ \webView -> do
177177 Just doc <- liftM (fmap castToHTMLDocument) $ webViewGetDomDocument webView
178178 Just body <- documentGetBody doc
179179 attachWidget body webView w
180180
181−mainWidgetWithHead :: Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> IO ()
181+mainWidgetWithHead :: Widget Spider (Gui Spider (WithWebView SpiderHost) (HostFrame Spider)) () -> Widget Spider (Gui Spider (WithWebView SpiderHost) (HostFrame Spider)) () -> IO ()
182182mainWidgetWithHead h b = runWebGUI $ \webView -> do
183183 Just doc <- liftM (fmap castToHTMLDocument) $ webViewGetDomDocument webView
184184 Just headElement <- liftM (fmap castToHTMLElement) $ documentGetHead doc
@@ -186,7 +186,7 @@ mainWidgetWithHead h b = runWebGUI $ \webView -> do
186186 Just body <- documentGetBody doc
187187 attachWidget body webView b
188188
189−mainWidgetWithCss :: ByteString -> Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> IO ()
189+mainWidgetWithCss :: ByteString -> Widget Spider (Gui Spider (WithWebView SpiderHost) (HostFrame Spider)) () -> IO ()
190190mainWidgetWithCss css w = runWebGUI $ \webView -> do
191191 Just doc <- liftM (fmap castToHTMLDocument) $ webViewGetDomDocument webView
192192 Just headElement <- liftM (fmap castToHTMLElement) $ documentGetHead doc
@@ -194,11 +194,35 @@ mainWidgetWithCss css w = runWebGUI $ \webView -> do
194194 Just body <- documentGetBody doc
195195 attachWidget body webView w
196196
197−attachWidget :: (IsHTMLElement e) => e -> WebView -> Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) a -> IO a
198−attachWidget rootElement wv w = runSpiderHost $ do --TODO: It seems to re-run this handler if the URL changes, even if it's only the fragment
197+newtype WithWebView m a = WithWebView { unWithWebView :: ReaderT WebView m a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix)
198+
199+instance MonadTrans WithWebView where
200+ lift = WithWebView . lift
201+
202+instance MonadRef m => MonadRef (WithWebView m) where
203+ type Ref (WithWebView m) = Ref m
204+ newRef = lift . newRef
205+ readRef = lift . readRef
206+ writeRef r = lift . writeRef r
207+
208+instance MonadAtomicRef m => MonadAtomicRef (WithWebView m) where
209+ atomicModifyRef r = lift . atomicModifyRef r
210+
211+deriving instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (WithWebView m)
212+instance MonadReflexHost t m => MonadReflexHost t (WithWebView m) where
213+ fireEventsAndRead dm a = lift $ fireEventsAndRead dm a
214+ subscribeEvent = lift . subscribeEvent
215+ runFrame = lift . runFrame
216+ runHostFrame = lift . runHostFrame
217+
218+runWithWebView :: WithWebView m a -> WebView -> m a
219+runWithWebView = runReaderT . unWithWebView
220+
221+attachWidget :: (IsHTMLElement e) => e -> WebView -> Widget Spider (Gui Spider (WithWebView SpiderHost) (HostFrame Spider)) a -> IO a
222+attachWidget rootElement wv w = runSpiderHost $ flip runWithWebView wv $ do --TODO: It seems to re-run this handler if the URL changes, even if it's only the fragment
199223 Just doc <- liftM (fmap castToHTMLDocument) $ liftIO $ nodeGetOwnerDocument rootElement
200224 frames <- liftIO newChan
201− rec let guiEnv = GuiEnv doc (writeChan frames . runSpiderHost) runWithActions wv :: GuiEnv Spider SpiderHost
225+ rec let guiEnv = GuiEnv doc (writeChan frames . runSpiderHost . flip runWithWebView wv) runWithActions wv :: GuiEnv Spider (WithWebView SpiderHost)
202226 runWithActions dm = do
203227 voidActionNeeded <- fireEventsAndRead dm $ do
204228 sequence =<< readEvent voidActionHandle