on master help sign in
Initial working version, tested only on Ubuntu
a0be239Michael Snoyman
.gitignorenew file+2
@@ -0,0 +1,2 @@
1+dist
2+*.swp
Hack/Handler/Webkit.hsnew file+11
@@ -0,0 +1,11 @@
1+module Hack.Handler.Webkit (run) where
2+
3+import Webkit (startBrowser)
4+import Hack (Application)
5+import qualified Hack.Handler.SimpleServer as S
6+import Control.Concurrent (forkIO)
7+
8+run :: Application -> IO ()
9+run app = do
10+ forkIO $ S.run 3000 app
11+ startBrowser
LICENSEnew file+25
@@ -0,0 +1,25 @@
1+The following license covers this documentation, and the source code, except
2+where otherwise indicated.
3+
4+Copyright 2008, Michael Snoyman. All rights reserved.
5+
6+Redistribution and use in source and binary forms, with or without
7+modification, are permitted provided that the following conditions are met:
8+
9+* Redistributions of source code must retain the above copyright notice, this
10+ list of conditions and the following disclaimer.
11+
12+* Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+
16+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR
17+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README+1
@@ -0,0 +1 @@
1+Turn Hack applications into standalone GUIs using Webkit.
Setup.lhsnew file+7
@@ -0,0 +1,7 @@
1+#!/usr/bin/env runhaskell
2+
3+> module Main where
4+> import Distribution.Simple
5+
6+> main :: IO ()
7+> main = defaultMain
Webkit.hsnew file+6
@@ -0,0 +1,6 @@
1+{-# LANGUAGE ForeignFunctionInterface #-}
2+{-# CFILES webkit.c #-}
3+module Webkit(startBrowser) where
4+
5+foreign import ccall "webkit.h start_browser"
6+ startBrowser :: IO ()
hack-handler-webkit.cabalnew file+31
@@ -0,0 +1,31 @@
1+name: hack-handler-webkit
2+version: 0.0.0
3+license: BSD3
4+license-file: LICENSE
5+author: Michael Snoyman <michael@snoyman.com>
6+maintainer: Michael Snoyman <michael@snoyman.com>
7+synopsis: Turn Hack applications into standalone GUIs using Webkit.
8+description: Currently using GtkWebkit. Runs any Hack application using
9+ the simpleserver handler and then pops up a Webkit browser
10+ to view it.
11+
12+ Note: only tested on Ubuntu Jaunty. Help appreciated for
13+ other platforms. Ideally, Windows and Mac would use their
14+ own native WebKit ports (and maybe even offer a QtWebKit
15+ option as well for Linux).
16+category: Web
17+stability: unstable
18+cabal-version: >= 1.2
19+build-type: Simple
20+homepage: http://github.com/snoyberg/hack-handler-webkit/tree/master
21+
22+library
23+ build-depends: base >= 4 && < 5,
24+ hack >= 2009.5.19,
25+ hack-handler-simpleserver >= 0.0.1,
26+ bytestring-class
27+ ghc-options: -Wall -threaded
28+ exposed-modules: Hack.Handler.Webkit
29+ other-modules: Webkit
30+ c-sources: webkit.c
31+ pkgconfig-depends: webkit-1.0
webkit.cnew file+127
@@ -0,0 +1,127 @@
1+/*
2+ * Copyright (C) 2006, 2007 Apple Inc.
3+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4+ *
5+ * Copyright (C) 2009 Michael Snoyman <michael@snoyman.com>
6+ *
7+ * Redistribution and use in source and binary forms, with or without
8+ * modification, are permitted provided that the following conditions
9+ * are met:
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#include <gtk/gtk.h>
30+#include <webkit/webkit.h>
31+
32+static GtkWidget* main_window;
33+static WebKitWebView* web_view;
34+static gchar* main_title;
35+
36+static void
37+update_title (GtkWindow* window)
38+{
39+ GString* string = g_string_new (main_title);
40+ gchar* title = g_string_free (string, FALSE);
41+ gtk_window_set_title (window, title);
42+ g_free (title);
43+}
44+
45+static void
46+title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data)
47+{
48+ if (main_title)
49+ g_free (main_title);
50+ main_title = g_strdup (title);
51+ update_title (GTK_WINDOW (main_window));
52+}
53+
54+/*
55+ static void
56+ notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
57+ {
58+ if (webkit_web_view_get_load_status (web_view) == WEBKIT_LOAD_COMMITTED) {
59+ WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view);
60+ const gchar* uri = webkit_web_frame_get_uri (frame);
61+ if (uri)
62+ gtk_entry_set_text (GTK_ENTRY (uri_entry), uri);
63+ }
64+ }
65+ */
66+
67+/*static void
68+ notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
69+ {
70+ load_progress = webkit_web_view_get_progress (web_view) * 100;
71+ update_title (GTK_WINDOW (main_window));
72+ }
73+ */
74+
75+static void
76+destroy_cb (GtkWidget* widget, gpointer data)
77+{
78+ gtk_main_quit ();
79+}
80+
81+static GtkWidget*
82+create_browser ()
83+{
84+ GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
85+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
86+
87+ web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
88+ gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
89+
90+ g_signal_connect (web_view, "title-changed", G_CALLBACK (title_change_cb), web_view);
91+
92+ return scrolled_window;
93+}
94+
95+static GtkWidget*
96+create_window ()
97+{
98+ GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
99+ gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
100+ gtk_widget_set_name (window, "GtkLauncher");
101+ g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
102+
103+ return window;
104+}
105+
106+void start_browser(void)
107+{
108+ int argc = 0;
109+ char *argv0 = "";
110+ char **argv = &argv0;
111+ gtk_init (&argc, &argv);
112+ if (!g_thread_supported ())
113+ g_thread_init (NULL);
114+
115+ GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
116+ gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
117+
118+ main_window = create_window ();
119+ gtk_container_add (GTK_CONTAINER (main_window), vbox);
120+
121+ gchar* uri = (gchar*) ("http://localhost:3000");
122+ webkit_web_view_open (web_view, uri);
123+
124+ gtk_widget_grab_focus (GTK_WIDGET (web_view));
125+ gtk_widget_show_all (main_window);
126+ gtk_main ();
127+}