Browse Source

some work toward dynamic linking deps

dhasenan 5 years ago
parent
commit
d6faeb56c3
7 changed files with 194 additions and 132 deletions
  1. 16
    9
      dub.json
  2. 1
    1
      import/about_resin.html
  3. 28
    0
      prebuild.sh
  4. 26
    0
      source/resin/app.d
  5. 20
    0
      source/resin/prefs.d
  6. 102
    121
      source/resin/ui.d
  7. 1
    1
      webkit-d

+ 16
- 9
dub.json View File

@@ -1,22 +1,29 @@
1 1
 {
2
-	"name": "browser",
2
+	"name": "resin",
3 3
 	"authors": [
4 4
 		"dhasenan"
5 5
 	],
6 6
 	"description": "A minimal D application.",
7 7
 	"copyright": "Copyright © 2017, dhasenan",
8
-	"license": "proprietary",
8
+	"license": "MS-PL",
9
+  "targetType": "executable",
9 10
   "dependencies": {
10
-      "gtk-d": "~>3.7.3"
11
-    , "d2sqlite3": "~>0.16.0"
11
+      "d2sqlite3": "~>0.16.0"
12 12
     , "dyaml": "~>0.6.3"
13
-    , "webkit-d": {"path": "webkit-d"}
14 13
     , "urld": "~>2.1.0"
15 14
   },
16
-  "libs-posix": [
17
-      "soup-2.4"
18
-    , "webkit2gtk-4.0"
19
-    , "javascriptcoregtk-4.0"
15
+  "lflags-posix": [
16
+      "-L."
17
+    , "-l:libsoup-2.4.so"
18
+    , "-l:libwebkit2gtk-4.0.so"
19
+    , "-l:libjavascriptcoregtk-4.0.so"
20
+    , "-l:libgtkd-3.so"
21
+    , "-l:libwebkit-d.so"
22
+  ],
23
+  "importPaths": [
24
+    "source",
25
+    "GtkD/generated/gtkd",
26
+    "webkit-d/source"
20 27
   ],
21 28
   "stringImportPaths": [
22 29
     "import"

+ 1
- 1
import/about_resin.html View File

@@ -3,7 +3,7 @@
3 3
         <title>About Resin</title>
4 4
     </head>
5 5
     <body>
6
-        <div style="margin-left: 2em">
6
+        <div style="margin: 2em">
7 7
             <p>I cast my eyes to the hills; where does my help come from?</p>
8 8
             <p>I cast my eyes to the depths; where can I extend my reach?</p>
9 9
             <p>Far and wide I look. All within my sight is within my power to help.</p>

+ 28
- 0
prebuild.sh View File

@@ -0,0 +1,28 @@
1
+#!/usr/bin/env bash
2
+
3
+set -xe
4
+
5
+gtkdub=GtkD/dub.json
6
+if [ ! -f ${gtkdub} ]; then
7
+  git checkout https://github.com/gtkd-developers/GtkD
8
+fi
9
+if grep '"targetType": "library"' ${gtkdub} ; then
10
+  sed -i 's,"targetType": "library","targetType": "dynamicLibrary"' ${gtkdub}
11
+fi
12
+if [ ! -f libgtkd-3.so ]; then
13
+  cd GtkD
14
+  dub build gtk-d:gtkd
15
+  cp libgtkd-3.so ..
16
+  cd ..
17
+fi
18
+
19
+wkdub=webkit-d/dub.json
20
+if [ ! -f ${wkdub} ]; then
21
+  git clone https://git.ikeran.org/dhasenan/webkit-d
22
+fi
23
+if [ ! -f libwebkit-d.so ]; then
24
+  cd webkit-d
25
+  dub build webkit-d:dynamic
26
+  cp libwebkit-d.so ..
27
+  cd ..
28
+fi

+ 26
- 0
source/resin/app.d View File

@@ -0,0 +1,26 @@
1
+module resin.app;
2
+
3
+import etc.linux.memoryerror;
4
+import gio.Application : GApp = Application;
5
+import gtk.Application;
6
+import gtk.Builder;
7
+import gtk.Entry;
8
+import gtk.Notebook;
9
+import gtk.SearchEntry;
10
+import gtk.Window;
11
+import resin.prefs;
12
+import resin.ui;
13
+import std.stdio;
14
+import url;
15
+import webkit2.WebView;
16
+
17
+int main(string[] args)
18
+{
19
+    registerMemoryErrorHandler();
20
+    prefs = new Prefs;
21
+    prefs.load;
22
+    writeln("Edit source/app.d to start your project.");
23
+    auto app = new Application("org.ikeran.browser", GApplicationFlags.FLAGS_NONE);
24
+    app.addOnActivate((a) { new BrowseWindow(app).show(); });
25
+    return app.run(args);
26
+}

+ 20
- 0
source/resin/prefs.d View File

@@ -0,0 +1,20 @@
1
+module resin.prefs;
2
+
3
+/// A size in pixels, as for a window.
4
+struct Size
5
+{
6
+    /// Width and height
7
+    int width, height;
8
+}
9
+
10
+/// User's preferences
11
+class Prefs
12
+{
13
+    /// How big windows should be by default
14
+    Size windowSize = Size(1024, 768);
15
+
16
+    void load() {}
17
+}
18
+
19
+/// Global prefs object
20
+__gshared Prefs prefs;

source/app.d → source/resin/ui.d View File

@@ -1,135 +1,20 @@
1
-import std.stdio;
1
+module resin.ui;
2 2
 
3
-import etc.linux.memoryerror;
4
-
5
-import gtk.Builder;
6 3
 import gtk.Application;
7
-import gio.Application : GApp = Application;
4
+import gtk.Builder;
5
+import gtk.Button;
8 6
 import gtk.Entry;
7
+import gtk.MenuBar;
9 8
 import gtk.Notebook;
10
-import gtk.SearchEntry;
11 9
 import gtk.Window;
10
+import resin.prefs;
12 11
 import url;
13 12
 import webkit2.WebView;
14 13
 
15
-int main(string[] args)
16
-{
17
-    registerMemoryErrorHandler();
18
-    prefs = new Prefs;
19
-    writeln("Edit source/app.d to start your project.");
20
-    auto app = new Application("org.ikeran.browser", GApplicationFlags.FLAGS_NONE);
21
-    app.addOnActivate((a) { new BrowseWindow(app).show(); });
22
-    return app.run(args);
23
-}
24
-
25
-struct Size
26
-{
27
-    int width, height;
28
-}
29
-
30
-class Prefs
31
-{
32
-    Size windowSize = Size(1024, 768);
33
-}
34
-
35
-__gshared Prefs prefs;
36
-
37
-
38
-class Tab
39
-{
40
-    import gtk.Label;
41
-    import gtk.Image;
42
-    import gtk.Spinner;
43
-    import gtk.HBox;
44
-    import webkit2.c.types : WebKitLoadEvent;
45
-    enum DATA_KEY = "resin-tab";
46
-
47
-    BrowseWindow window;
48
-    Notebook notebook;
49
-
50
-    Image favicon;
51
-    Label headerLabel;
52
-    Spinner spinner;
53
-    WebView web;
54
-
55
-    this(BrowseWindow window, string uri = "about:blank")
56
-    {
57
-        this.window = window;
58
-        this.notebook = window.notebook;
59
-
60
-        spinner = new Spinner;
61
-        favicon = new Image;
62
-        favicon.setFromFile("/home/dhasenan/");
63
-        auto labelBox = new HBox(false, 2);
64
-        labelBox.packStart(spinner, false, false, 0);
65
-        labelBox.packStart(favicon, false, false, 0);
66
-        labelBox.packEnd(headerLabel, true, true, 2);
67
-
68
-        web = new WebView;
69
-        web.addOnDecidePolicy(&this.window.decidePolicy);
70
-        web.addOnLoadChanged(&updateNavItems);
71
-        web.setData(Tab.DATA_KEY, cast(void*)this);
72
-        notebook.appendPage(web, "Webby!");
73
-        navigate(uri);
74
-    }
75
-
76
-    void navigate(string uri)
77
-    {
78
-        import std.string : startsWith;
79
-        web.grabFocus();
80
-        switch (uri)
81
-        {
82
-            case "about:mozilla":
83
-                web.loadHtml(import("about_mozilla.html"), uri);
84
-                break;
85
-            case "about:chrome":
86
-                web.loadHtml(import("about_chrome.html"), uri);
87
-                break;
88
-            case "about:resin":
89
-                web.loadHtml(import("about_resin.html"), uri);
90
-                break;
91
-            case "about:version":
92
-                web.loadHtml(import("about_version.html"), uri);
93
-                break;
94
-            case "about:blank":
95
-                web.loadHtml(import("about_blank.html"), uri);
96
-                break;
97
-            default:
98
-                // This does some normalization.
99
-                uri = uri.parseURL.toString;
100
-                web.loadUri(uri);
101
-                break;
102
-        }
103
-    }
104
-
105
-    void updateNavItems(WebKitLoadEvent evt, WebView wv)
106
-    {
107
-        with (WebKitLoadEvent) final switch (evt)
108
-        {
109
-            case STARTED:
110
-                // We're starting an outbound web request.
111
-                favicon.hide;
112
-                spinner.show;
113
-                break;
114
-            case FINISHED:
115
-                favicon.show;
116
-                spinner.hide;
117
-                break;
118
-            case REDIRECTED:
119
-                break;
120
-            case COMMITTED:
121
-                break;
122
-        }
123
-    }
124
-}
125
-
126
-
127 14
 class BrowseWindow
128 15
 {
129 16
     this(Application app, string uri = "about:blank")
130 17
     {
131
-        import gtk.Button;
132
-        import gtk.MenuBar;
133 18
 
134 19
         auto builder = new Builder();
135 20
         if (!builder.addFromString(import("ui.glade")))
@@ -212,4 +97,100 @@ class BrowseWindow
212 97
     Window win;
213 98
     Entry addressBar;
214 99
     Notebook notebook;
215
-}
100
+}
101
+
102
+/**
103
+ * A browser tab.
104
+ */
105
+class Tab
106
+{
107
+    /// We store the Tab as a data value attached to a WebView under this key.
108
+    enum DATA_KEY = "resin-tab";
109
+
110
+    /// Mkae a new tab, child of the given window and pointing at the given tab.
111
+    this(BrowseWindow window, string uri = "about:blank")
112
+    {
113
+        this.window = window;
114
+        this.notebook = window.notebook;
115
+
116
+        spinner = new Spinner;
117
+        favicon = new Image;
118
+        favicon.setFromFile("/home/dhasenan/");
119
+        auto labelBox = new HBox(false, 2);
120
+        labelBox.packStart(spinner, false, false, 0);
121
+        labelBox.packStart(favicon, false, false, 0);
122
+        labelBox.packEnd(headerLabel, true, true, 2);
123
+
124
+        web = new WebView;
125
+        web.addOnDecidePolicy(&this.window.decidePolicy);
126
+        web.addOnLoadChanged(&updateNavItems);
127
+        web.setData(Tab.DATA_KEY, cast(void*)this);
128
+        notebook.appendPage(web, "Webby!");
129
+        navigate(uri);
130
+    }
131
+
132
+    /// Navigate to the given URI.
133
+    final void navigate(string uri)
134
+    {
135
+        import std.string : startsWith;
136
+        web.grabFocus();
137
+        switch (uri)
138
+        {
139
+            case "about:mozilla":
140
+                web.loadHtml(import("about_mozilla.html"), uri);
141
+                break;
142
+            case "about:chrome":
143
+                web.loadHtml(import("about_chrome.html"), uri);
144
+                break;
145
+            case "about:resin":
146
+                web.loadHtml(import("about_resin.html"), uri);
147
+                break;
148
+            case "about:version":
149
+                web.loadHtml(import("about_version.html"), uri);
150
+                break;
151
+            case "about:blank":
152
+                web.loadHtml(import("about_blank.html"), uri);
153
+                break;
154
+            default:
155
+                // This does some normalization.
156
+                uri = uri.parseURL.toString;
157
+                web.loadUri(uri);
158
+                break;
159
+        }
160
+    }
161
+
162
+    private:
163
+    import gtk.Label;
164
+    import gtk.Image;
165
+    import gtk.Spinner;
166
+    import gtk.HBox;
167
+    import webkit2.c.types : WebKitLoadEvent;
168
+
169
+    BrowseWindow window;
170
+    Notebook notebook;
171
+
172
+    Image favicon;
173
+    Label headerLabel;
174
+    Spinner spinner;
175
+    WebView web;
176
+
177
+    void updateNavItems(WebKitLoadEvent evt, WebView wv)
178
+    {
179
+        with (WebKitLoadEvent) final switch (evt)
180
+        {
181
+            case STARTED:
182
+                // We're starting an outbound web request.
183
+                favicon.hide;
184
+                spinner.show;
185
+                break;
186
+            case FINISHED:
187
+                favicon.show;
188
+                spinner.hide;
189
+                break;
190
+            case REDIRECTED:
191
+                break;
192
+            case COMMITTED:
193
+                break;
194
+        }
195
+    }
196
+}

+ 1
- 1
webkit-d

@@ -1 +1 @@
1
-Subproject commit 7c41f0e38f15111cb7c3dabf51598ff408ad1ebd
1
+Subproject commit 4711fd6df52eaf81ce17974466b6e259a2a11918