webviewhs-0.1.0.0: Create native dialogs and windows that run web pages.

Copyright(C) 2018 David Lettier
LicenseBSD3
MaintainerDavid Lettier
Safe HaskellNone
LanguageHaskell2010

Graphics.UI.Webviewhs

Description

webviewhs is a Haskell binding to the webview library created by Serge Zaitsev.

According to webview:

[webview is] a tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs.
It uses Cocoa/WebKit on macOS, gtk-webkit2 on Linux and MSHTML (IE10/11) on Windows.

For more information, see the webview README.

Be sure to explore the provided examples.

To exclude clay, jmacro, and text-format-heavy, use the cabal build flag light. Be sure to explore the provided light examples for more information.

Synopsis

Documentation

data WindowParams Source #

Specifies the window creation parameters.

Constructors

WindowParams 

Fields

type Window = Ptr Source #

Pointer to a webview struct.

newtype WithWindowLoopSetUp a Source #

Constructors

WithWindowLoopSetUp (Window a -> IO ()) 

createWindowAndBlock :: WindowParams -> IO () Source #

Creates a window and runs the main loop unless the window is destroyed. Useful for loading a web page and not having to manage the loop.

createWindow Source #

Arguments

:: WindowParams 
-> (Window a -> Text -> IO ())

A callback that JavaScript can use to communicate with the Haskell side.

-> IO (Either Text (Window a)) 

Creates a window giving you the chance to changes its properties, run its loop, etc. Returns Left on failure and Right Window on success.

setWindowTitle :: Window a -> Text -> IO () Source #

Changes the window title.

setWindowFullscreen :: Window a -> Bool -> IO () Source #

Sets the window's fullscreen state. Pass True to put the window into fullscreen mode. Pass False to take the window out of fullscreen mode.

setWindowBackgroundColor :: Window a -> WindowBackgroundColor -> IO () Source #

If the loaded web page does not specify a background color, this sets the window's background color.

withWindowLoop Source #

Arguments

:: WindowParams 
-> (Window a -> Text -> IO ())

A callback function that can be invoked from the JavaScript side. The callback must accept a Window and the JavaScript sent Text. The JavaScript sent Text could be unstructured or structured like JSON.

-> WithWindowLoopSetUp a

A function that is called before iterating. It must accept a Window and return IO (). Use it to set up before entering the main loop. You can pass void . return . const if you don't have a setup function.

-> WithWindowLoopTearDown a

A function that is called after iterating. It must accept a Window and return IO (). Use it to tear down after leaving the main loop. You can pass void . return . const if you don't have a teardown function. Note, do not terminate the window loop and/or destroy the window as this is done for you.

-> (Window a -> IO Bool)

A function that is called each iteration. Return True to continue or False to stop iterating.

-> IO () 

Manages the window and main loop for you. It accepts a JavaScript callback, setup, teardown, and iteration function.

iterateWindowLoop Source #

Arguments

:: Window a 
-> Bool

Pass True to iterate until the window exits. Pass False to run one iteration.

-> IO Bool 

Iterates the window loop. If True, runs the window loop continuously—blocking until the window exits. If False, runs one iteration of the window loop and releases control back to the caller.

runJavaScript' Source #

Arguments

:: Window a 
-> Text 
-> IO Bool

Returns True on success and False on failure.

Runs the given JavaScript inside the window. The given JavaScript is not checked for validity.

runJavaScript Source #

Arguments

:: (JsToDoc js, JMacro js) 
=> Window a 
-> js 
-> IO Bool

Returns True on success and False on failure.

Runs the given JavaScript inside the window. Uses Language.Javascript.JMacro. Note, this function is not available when using the light cabal build flag.

injectCss Source #

Arguments

:: Window a 
-> Css 
-> IO Bool

Returns True on success and False on failure.

Injects CSS into the window. Uses Clay. Note, this function is not available when using the light cabal build flag.

log :: VarContainer vars => Format -> vars -> IO () Source #

Logs the given formatted input to stderr, macOS console, or Windows DebugView depending on the build platform. Uses Data.Text.Format.Heavy. Note, this function is not available when using the light cabal build flag.

injectCss' Source #

Arguments

:: Window a 
-> Text 
-> IO Bool

Returns True on success and False on failure.

Injects CSS into the window. The given CSS is not checked for validity.

openWindowAlertDialog Source #

Arguments

:: Window a 
-> WindowAlertDialogType 
-> Text

This is the primary message.

-> Text

This is the secondary message.

-> IO () 

Opens a window alert dialog.

withWindowOpenDialog Source #

Arguments

:: Window a 
-> Text

The open dialog window title.

-> Bool

Pass True to disable selecting files. Pass False to allow selecting both files and directories.

-> (Text -> IO ())

A callback that accepts the result of the dialog.

-> IO () 

Opens a native file chooser dialog. Accepts a callback that receives the selection.

withWindowSaveDialog Source #

Arguments

:: Window a 
-> Text

The save dialog window title.

-> (Text -> IO ())

A callback that accepts the result of the dialog.

-> IO () 

Opens a native file saving dialog. Accepts a callback that receives the selection. Does not actually save the file. Save the file inside the provided callback.

dispatchToMain :: Window a -> (Window a -> IO ()) -> IO () Source #

Runs the given function in the main window UI thread. Use this function whenever you wish to interact with the window but you're not running in the main window UI thread.

log' :: Text -> IO () Source #

Logs the given input to stderr, macOS console, or Windows DebugView depending on the build platform.

terminateWindowLoop :: Window a -> IO () Source #

Terminates the window's loop.

destroyWindow :: Window a -> IO () Source #

Destroys the window.