Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lettier/webviewhs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.0.0
Choose a base ref
...
head repository: lettier/webviewhs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 33 files changed
  • 1 contributor

Commits on Oct 9, 2018

  1. Updates to version 0.0.1.0

    lettier committed Oct 9, 2018
    Copy the full SHA
    488ca1a View commit details

Commits on Apr 27, 2019

  1. Updates to version 0.0.2.0

    lettier committed Apr 27, 2019
    Copy the full SHA
    3589c97 View commit details

Commits on Jun 16, 2019

  1. Updates to version 0.1.0.0.

    lettier committed Jun 16, 2019
    Copy the full SHA
    21f8ac8 View commit details

Commits on Aug 4, 2019

  1. Copy the full SHA
    21ddd4b View commit details
Showing with 2,170 additions and 1,198 deletions.
  1. +5 −0 .gitignore
  2. +71 −0 CHANGELOG.md
  3. +107 −38 README.md
  4. +0 −1 cabal.config
  5. +575 −196 deps/webview/webview.h
  6. +29 −18 docs/Graphics-UI-Webviewhs.html
  7. +2 −2 docs/doc-index.html
  8. +2 −2 docs/iindex.html
  9. +29 −18 docs/index.html
  10. +1 −1 docs/mini_Graphics-UI-Webviewhs.html
  11. +639 −606 docs/src/Graphics.UI.Webviewhs.html
  12. +19 −0 examples-light/CHANGELOG.md
  13. +29 −0 examples-light/LICENSE
  14. +40 −0 examples-light/README.md
  15. +62 −0 examples-light/how-do-i-communicate-with-haskell-from-javascript.hs
  16. +46 −0 examples-light/how-do-i-inject-some-custom-css-into-the-window.hs
  17. +44 −0 examples-light/how-do-i-log-some-debug-information.hs
  18. +10 −0 examples-light/stack.yaml
  19. +69 −0 examples-light/webviewhs-examples-light.cabal
  20. +27 −1 examples/CHANGELOG.md
  21. +6 −4 examples/README.md
  22. +8 −3 examples/how-do-i-communicate-with-haskell-from-javascript.hs
  23. +7 −2 examples/how-do-i-inject-some-custom-css-into-the-window.hs
  24. +77 −0 examples/how-do-i-inline-an-html-page-on-start-up.hs
  25. +8 −4 examples/how-do-i-log-some-debug-information.hs
  26. +12 −7 examples/how-do-i-run-my-own-function-in-the-window-loop.hs
  27. +12 −7 examples/how-do-i-run-some-function-in-the-main-window-thread-while-in-some-other-thread.hs
  28. +6 −2 examples/how-do-i-run-some-javascript-inside-the-window.hs
  29. +20 −1 examples/webviewhs-examples.cabal
  30. +96 −214 logo/webviewhs-logo-0.svg
  31. +1 −1 makefile
  32. +95 −62 src/Graphics/UI/Webviewhs.hs
  33. +16 −8 webviewhs.cabal
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,8 +4,13 @@
dist/*
haddock/*
hackage-docs-archive/*
*cabal.config*
cabal.sandbox.config
examples/.cabal-sandbox/*
examples/.stack-work/*
examples/dist/*
examples/caba.sandbox.config
examples-light/.cabal-sandbox/*
examples-light/.stack-work/*
examples-light/dist/*
examples-light/caba.sandbox.config
71 changes: 71 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,77 @@

---

## 0.1.0.0

### Added

- Cabal build flag light
- If enabled
- Removes
- clay, jmacro, and text-format-heavy
- runJavaScript, injectCss, and log from the API
- examples-light directory
- WithWindowLoopSetUp
- WithWindowLoopTearDown

### Changed

- withWindowLoop
- It now requires a setup and teardown function
- Documentation

### Removed

-

---

## 0.0.2.0

### Added

-

### Changed

- Updated webview
- Commits
- Fixed bug in Windows 7 where window does not close
- 16c93bcaeaeb6aa7bb5a1432de3bef0b9ecc44f3
- https://github.com/zserge/webview/pull/229
- Add IInternetSecurityManager to override any IE settings.
- f390a2df9ec50d1bce389f0656a215a5504dce04
- https://github.com/zserge/webview/pull/199
- Updated version in documentation

### Removed

-

---

## 0.0.1.0

### Added

-

### Changed

- Updated webview
- Commit
- 24af6cb9b33b3a10dce44188aec0c1646247d830
- Removes objective-c
- https://github.com/zserge/webview/pull/181
- Updated logo

### Removed

- Objective-c requirement for macOS
- Cocoa framework requirement for macOS

---

## 0.0.0.0

### Added
145 changes: 107 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![webviewhs logo](https://i.imgur.com/MOmkahs.png)
![webviewhs logo](https://i.imgur.com/yohrYgX.png)

# What is webviewhs?

@@ -86,7 +86,8 @@ much like stack.

## How do I use webviewhs?

If you want to open up a native desktop window that loads a web page and manages itself, do the following:
If you want to open up a native desktop window that loads a web page and manages itself,
do the following:

```haskell
{-# LANGUAGE
@@ -129,11 +130,13 @@ import qualified Graphics.UI.Webviewhs as WHS
main :: IO ()
main = do
-- Create a channel to communicate between the main thread and another thread we'll create.
-- Create a channel to communicate between the main thread and another thread you'll create.
-- This isn't necessary but it's a great way to communicate between threads.
channel <- newBoundedChan 1
-- withWindowLoop handles the creation, iteration, and deletion of the window.
WHS.withWindowLoop
-- Set the window creation params.
WHS.WindowParams
{ WHS.windowParamsTitle = "Test"
@@ -144,24 +147,38 @@ main = do
, WHS.windowParamsResizable = True
, WHS.windowParamsDebuggable = True -- Enables the Web Inspector if using WebKit.
}
-- webview allows you to specify a callback function that can be
-- called from the JavaScript side.
-- The callback receives a single string parameter.
-- This could be unstructured text or unparsed JSON for example.
-- We'll just print what we received.
-- You can just print what was received for now.
(\ _window stringFromJavaScript -> print stringFromJavaScript)
-- This function runs before the loop.
(WHS.WithWindowLoopSetUp (\ _window -> print "Setting up."))
-- This function runs after the loop.
(WHS.WithWindowLoopTearDown (\ _window -> print "Tearing down."))
-- If you don't need to set up and/or tear down anything, you can do this.
-- (WHS.WithWindowLoopSetUp (void . return . const))
-- (WHS.WithWindowLoopTearDown (void . return . const))
-- This function is called continuously.
-- Return True to continue the window loop or
-- return False to exit the loop and destroy the window.
$ \ window -> do
-- webviewhs provides log and log'.
-- log uses text-format-heavy which provides a "full-featured string
-- formatting function, similar to Python's string.format."
-- log uses text-format-heavy which provides a
-- "full-featured string formatting function, similar to Python's string.format."
-- log' takes a simple Text string.
-- According to webview, logging will print to
-- "stderr, MacOS Console or [Windows] DebugView."
let string = "world" :: Text
WHS.log "Hello {string}!" [("string" :: DTL.Text, Variable string)]
-- webview allows you to run JS inside the window.
-- webviewhs comes with runJavaScript and runJavaScript'.
-- runJavaScript uses JMacro which is a
@@ -170,8 +187,9 @@ main = do
let red = "red" :: Text
_ <- WHS.runJavaScript
window
-- This changes the web page background color to red.
-- Notice that we can use Haskell values inside the JavaScript and
-- Notice that you can use Haskell values inside the JavaScript and
-- even use Haskell like syntax.
[jmacro|
fun setBackgroundColor color { document.body.style.backgroundColor = color; }
@@ -180,53 +198,104 @@ main = do
5000
);
|]

-- webview allows you to inject CSS into the window.
-- webviewhs offers injectCss and injectCss'.
-- injectCss uses Clay "a CSS preprocessor like LESS and Sass,
-- but implemented as an embedded domain specific language (EDSL) in Haskell."
-- injectCss' takes a Text string which may or may not be valid CSS.
_ <- WHS.injectCss
window $
-- This turns all <div> text blue.
Clay.div Clay.?
Clay.color "#0000ff"
-- Inside the window loop, we'll create a thread.
window

-- This turns all <div> text blue.
$ Clay.div Clay.?
Clay.color "#0000ff"

-- Inside the window loop, create a thread.
_ <- forkIO $ do
WHS.log' "Hello from inside a thread."
-- When we're not in the main window UI thread, we need to call
-- dispatchToMain if we want to interact with the window.

-- When you're not in the main window UI thread, you'll need to call
-- dispatchToMain if you want to interact with the window.
-- dispatchToMain will run the given function in the main UI thread.
-- Note that dispatchToMain runs the function asynchronously with no guarantee
-- as to when it will run.
WHS.dispatchToMain window $ \ window' -> do
result <-
WHS.runJavaScript
window'
-- This will randomly scroll the web page up and down.
[jmacro|
if (Math.random() < 0.1) {
setTimeout(
function() {
window.scrollTo(0, Math.random() * window.innerHeight);
},
10000
);
}
|]
-- runJavaScript returns True if it was successful and
-- False if something went wrong.
-- Here we attempt to write the result to our channel.
void $ CCBC.tryWriteChan channel result
-- Exit the loop if we read False from the channel.
WHS.dispatchToMain
window
$ \ window' -> do
result <-
WHS.runJavaScript
window'

-- This will randomly scroll the web page up and down.
[jmacro|
if (Math.random() < 0.1) {
setTimeout(
function() {
window.scrollTo(0, Math.random() * window.innerHeight);
},
10000
);
}
|]

-- runJavaScript returns True if it was successful and
-- False if something went wrong.
-- Here is an attempt to write the result to the channel.
void $ CCBC.tryWriteChan channel result

-- Exit the loop if you read False from the channel.
-- Note that tryReadChan does not block which is
-- important when inside the window loop.
fromMaybe True <$> tryReadChan channel
-- At this point we've exited the window loop,
-- destroyed the window,
-- and will now exit the program.

-- At this point,
-- the loop has been exited,
-- the window has been destroyed,
-- and the program will now exit.
```

For more ways to use webviewhs,
take a look at the [examples](examples) directory.

## What if I don't want clay, jmacro, and text-format-heavy?

webviewhs has a `light` build flag that removes the dependencies clay, jmacro, and text-format-heavy.
In some cases, using the `light` build flag can reduce the final binary size by 77%.

Note that the `light` build flag removes `runJavaScript`, `injectCss`, and `log` from the API.
You can still use `runJavaScript'`, `injectCss'`, and `log'`.

If you're using stack, you can supply the `light` flag in the `stack.yaml` file.

```yaml
flags:
webviewhs:
light: true
```
For more ways to use webviewhs, take a look at the [examples](examples) directory.
You can also supply the `light` flag on the command line like so.

```bash
stack build --flag webviewhs:light
```

If you're using cabal, you'll have to supply a constraint for all configure and install commands.

```bash
# For configure.
cabal configure --constraint="webviewhs +light"
# For install.
cabal install -j --constraint="webviewhs +light"
```

There's currently no way to supply the constraint in the cabal file itself,
however,
there is an [open issue](https://github.com/haskell/cabal/issues/2821) about it.

For more information about using the light version of webviewhs,
take a look at the [examples-light](examples-light) directory.

## What is the license?

1 change: 0 additions & 1 deletion cabal.config

This file was deleted.

Loading