Skip to content
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

It's not possible to call app.on('certificate-error', callback) on electron. #75

Closed
crocket opened this issue Oct 27, 2016 · 2 comments
Closed

Comments

@crocket
Copy link
Contributor

crocket commented Oct 27, 2016

I'm trying to find a good way to wrap https://github.com/electron/electron/blob/master/docs/api/app.md#event-certificate-error

newtype AppBlahCallback = AppBlahCallback JSVal

foreign import javascript interruptible
  "app.on('blah', function (a, b, c, callback) { $c(a, b, c, callback); })"
  waitAppBlah :: IO (JSVal, JSVal, JSVal, AppBlahCallback)

foreign import javascript unsafe "$1($2)"
  appBlahCallback :: AppBlahCallback -> Bool -> IO ()

main :: IO ()
main = do
  forkIO $ do
    (_, _, _, cb) <- waitAppBlah
    appBlahCallback cb True

I cannot retrieve IO (JSVal, JSVal, JSVal, AppBlahCallback) from waitAppBlah more than once, but the event can call the callback multiple times.

If I retrieved

IO (JSVal, JSVal, JSVal, AppBlahCallback)

from waitAppBlah twice,

app.on('blah', function (a, b, c, callback) { $c(a, b, c, callback); })

would just be called twice. This doesn't make sense.

Since no function on GHCJS/Foreign/Callback.hs generates a callback of 4 or more parameters, it's not possible to write the following snippet, either.

newtype AppBlahCallback = AppBlahCallback JSVal

foreign import javascript unsafe
  "app.on('blah', $1)"
  onAppBlah :: Callback (JSVal -> JSVal -> JSVal -> AppBlahCallback -> IO ()) -> IO ()

foreign import javascript unsafe "$1($2)"
  appBlahCallback :: AppBlahCallback -> Bool -> IO ()

main :: IO ()
main = do
  onAppBlah $ asyncCallback4 $ \_ _ _ cb -> appBlahCallback cb True

Does ghcjs-base need modification before I become able to write a wrapper for https://github.com/electron/electron/blob/master/docs/api/app.md#event-certificate-error?

Perhaps, do we need the following functions?

syncCallbackN :: Int -> OnBlocked -> a -> IO (Callback a)

asyncCallbackN :: Int -> a -> IO (Callback a)

Or, how about

asyncCallback ::
  (JSVal -> JSVal -> ... -> JSVal -> IO a) ->
  IO (Callback (JSVal -> JSVal -> ... -> JSVal -> IO a))
@crocket
Copy link
Contributor Author

crocket commented Oct 27, 2016

I believe #76 subsumes this issue.

@crocket crocket closed this as completed Oct 27, 2016
@hamishmack
Copy link
Member

oops sorry did not see this and made #76 based on you gitter chat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants