Skip to content

Add more WebContents instance event handlers #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Electron/BrowserWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,45 @@ exports.onWillNavigate = function(webContents) {
};
};
}

exports.onDidNavigate = function(webContents) {
return function(callback) {
return function() {
return webContents.on('did-navigate', function(e, url) {
callback(e)(url)();
});
};
};
}

exports.onDidNavigateInPage = function(webContents) {
return function(callback) {
return function() {
return webContents.on('did-navigate-in-page', function(e, url) {
callback(e)(url)();
});
};
};
}

exports.onDidGetRedirectRequest = function(webContents) {
return function(callback) {
return function() {
return webContents.on('did-get-redirect-request', function(e, oldURL,
newURL, isMainFrame, httpResponseCode, requestMethod,
referrer, headers) {
callback(e)(oldURL)(newURL)(isMainFrame)(httpResponseCode)(requestMethod)(referrer)(headers)();
});
};
};
}

exports.onDomReady = function(webContents) {
return function(callback) {
return function() {
return webContents.on('dom-ready', function(e) {
callback(e)();
});
};
};
}
36 changes: 36 additions & 0 deletions src/Electron/BrowserWindow.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ module Electron.BrowserWindow
, onDidFinishLoad
, onNewWindow
, onWillNavigate
, onDidNavigate
, onDidGetRedirectRequest
, onDomReady
) where

import Prelude (Unit, (>>>))
import Control.Monad.Eff (Eff)
import Data.Argonaut.Core (Json())
import Data.Generic (class Generic)
import Data.StrMap (StrMap)
import Electron (ELECTRON)
import Electron.Options (encodeOptions)
import Electron.Event (Event)
Expand Down Expand Up @@ -110,3 +114,35 @@ foreign import onWillNavigate :: forall eff
. WebContents
-> (Event -> String -> Eff (electron :: ELECTRON | eff) Unit)
-> Eff (electron :: ELECTRON | eff) Unit

-- | Emitted when a navigation is done.
-- |
-- | [Official Electron documentation](http://electron.atom.io/docs/api/web-contents/#event-did-navigate)
foreign import onDidNavigate :: forall eff
. WebContents
-> (Event -> String -> Eff (electron :: ELECTRON | eff) Unit)
-> Eff (electron :: ELECTRON | eff) Unit

-- | Emitted when an in-page navigation happened.
-- |
-- | [Official Electron documentation](http://electron.atom.io/docs/api/web-contents/#event-did-navigate-in-page)
foreign import onDidNavigateInPage :: forall eff
. WebContents
-> (Event -> String -> Eff (electron :: ELECTRON | eff) Unit)
-> Eff (electron :: ELECTRON | eff) Unit

-- | Emitted when a redirect is received while requesting a resource.
-- |
-- | [Official Electron documentation](http://electron.atom.io/docs/api/web-contents/#event-did-get-redirect-request)
foreign import onDidGetRedirectRequest :: forall eff
. WebContents
-> (Event -> String -> String -> Boolean -> Int -> String -> String -> StrMap String -> Eff (electron :: ELECTRON | eff) Unit)
-> Eff (electron :: ELECTRON | eff) Unit

-- | Emitted when the document in the given frame is loaded.
-- |
-- | [Official Electron documentation](http://electron.atom.io/docs/api/web-contents/#event-dom-ready)
foreign import onDomReady :: forall eff
. WebContents
-> (Event -> Eff (electron :: ELECTRON | eff) Unit)
-> Eff (electron :: ELECTRON | eff) Unit