Add WebKit.hs
This commit is contained in:
parent
2904d11e51
commit
a8430bb3b4
1 changed files with 48 additions and 0 deletions
48
WebKit.hs
Normal file
48
WebKit.hs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE OverloadedLabels #-}
|
||||
{-# LANGUAGE ImplicitParams #-}
|
||||
|
||||
import qualified GI.Gtk as Gtk
|
||||
import qualified GI.WebKit.Objects.WebView as WK
|
||||
import Data.GI.Base
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as TIO
|
||||
|
||||
import System.Environment (getArgs)
|
||||
import System.FilePath ((</>))
|
||||
import Control.Monad
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
-- Read HTML content from /tmp/index.html
|
||||
let htmlFilePath = "/tmp/index.html"
|
||||
|
||||
-- TIO ensures proper utf8 support
|
||||
content <- TIO.readFile htmlFilePath
|
||||
|
||||
-- Initialize application
|
||||
app <- new Gtk.Application
|
||||
[ #applicationId := "wazajisho.browser"
|
||||
, On #activate $ do
|
||||
-- Create main window
|
||||
window <- new Gtk.Window
|
||||
[ #application := ?self -- Implicit param
|
||||
, #title := "Wazajisho"
|
||||
, #defaultWidth := 1024
|
||||
, #defaultHeight := 768
|
||||
]
|
||||
|
||||
-- Create WebView with explicit GTK4 compatibility
|
||||
webview <- WK.webViewNew
|
||||
|
||||
-- Load HTML content
|
||||
WK.webViewLoadHtml webview content (Nothing :: Maybe T.Text)
|
||||
|
||||
-- Assemble UI
|
||||
#setChild window (Just webview)
|
||||
#show window
|
||||
]
|
||||
|
||||
-- Start application
|
||||
args <- getArgs
|
||||
void $ #run app (Just args)
|
||||
Loading…
Reference in a new issue