focus on your browsing
browser web-browser

add slight support for discerning search queries from urls

start work on in house url validator
add proper support for changing the current tab's url
run formatter

+152 -63
+1 -1
OuchBrowser/Actions.cs
··· 11 11 win = window; 12 12 } 13 13 14 - public void AddAction(string name, GObject.SignalHandler<SimpleAction, SimpleAction.ActivateSignalArgs>action) 14 + public void AddAction(string name, GObject.SignalHandler<SimpleAction, SimpleAction.ActivateSignalArgs> action) 15 15 { 16 16 var simpleaction = SimpleAction.New(name, null); 17 17 simpleaction.OnActivate += action;
+1 -4
OuchBrowser/OuchBrowser.csproj
··· 20 20 </ItemGroup> 21 21 22 22 <ItemGroup> 23 - <EmbeddedResource 24 - Include="OuchBrowser.app.gresource" 25 - LogicalName="OuchBrowser.app.gresource" 26 - /> 23 + <EmbeddedResource Include="OuchBrowser.app.gresource" LogicalName="OuchBrowser.app.gresource" /> 27 24 28 25 <!-- CSS --> 29 26 <EmbeddedResource Include="Styles.css" />
+1 -2
OuchBrowser/Program.cs
··· 21 21 RegisterResources(); 22 22 RegisterCss(); 23 23 24 - app.OnStartup += Window.OnStartup; 25 - app.OnActivate += Window.OnActivate; 24 + app.OnActivate += window.OnActivate; 26 25 27 26 return app.RunWithSynchronizationContext(null); 28 27 }
+64 -54
OuchBrowser/UI/Window.blp
··· 148 148 margin-end: 0; 149 149 } 150 150 151 - Button { 152 - margin-start: 10; 153 - margin-end: 0; 154 - action-name: "win.palette-new"; 151 + ScrolledWindow { 152 + vscrollbar-policy: external; 155 153 156 154 Box { 157 - spacing: 10; 155 + orientation: vertical; 158 156 159 - Image { 160 - icon-name: "list-add-symbolic"; 157 + Button { 158 + margin-start: 10; 159 + margin-end: 0; 160 + action-name: "win.palette-new"; 161 161 162 - styles [ 163 - "dimmed", 164 - ] 165 - } 162 + Box { 163 + spacing: 10; 164 + 165 + Image { 166 + icon-name: "list-add-symbolic"; 167 + 168 + styles [ 169 + "dimmed", 170 + ] 171 + } 172 + 173 + Label { 174 + label: _("New tab"); 166 175 167 - Label { 168 - label: _("New tab"); 176 + styles [ 177 + "dimmed", 178 + "font-medium", 179 + ] 180 + } 181 + } 169 182 170 183 styles [ 171 - "dimmed", 172 - "reset-font-weight", 184 + "flat", 173 185 ] 174 186 } 175 - } 176 187 177 - styles [ 178 - "flat", 179 - ] 180 - } 181 - 182 - ListView tabs { 183 - model: bind view.pages; 188 + ListView tabs { 189 + vexpand: true; 190 + model: bind view.pages; 184 191 185 - factory: BuilderListItemFactory { 186 - template ListItem { 187 - child: CenterBox { 188 - start-widget: Box { 189 - spacing: 10; 192 + factory: BuilderListItemFactory { 193 + template ListItem { 194 + child: CenterBox { 195 + start-widget: Box { 196 + spacing: 10; 190 197 191 - Image tab_icon { 192 - // gicon: bind template.item as <Adw.TabPage>.icon; 193 - icon-name: "box-dotted-symbolic"; 194 - visible: bind spinner.visible inverted; 198 + Image tab_icon { 199 + // gicon: bind template.item as <Adw.TabPage>.icon; 200 + icon-name: "box-dotted-symbolic"; 201 + visible: bind spinner.visible inverted; 195 202 196 - styles [ 197 - "dimmed", 198 - ] 199 - } 203 + styles [ 204 + "dimmed", 205 + ] 206 + } 200 207 201 - Adw.Spinner spinner { 202 - width-request: 16; 203 - height-request: 16; 204 - visible: bind template.item as <Adw.TabPage>.loading; 205 - } 208 + Adw.Spinner spinner { 209 + width-request: 16; 210 + height-request: 16; 211 + visible: bind template.item as <Adw.TabPage>.loading; 212 + } 206 213 207 - Label { 208 - label: bind template.item as <Adw.TabPage>.title; 209 - ellipsize: end; 210 - halign: start; 211 - hexpand: true; 212 - tooltip-text: bind template.item as <Adw.TabPage>.keyword; 213 - } 214 - }; 214 + Label { 215 + label: bind template.item as <Adw.TabPage>.title; 216 + ellipsize: end; 217 + halign: start; 218 + hexpand: true; 219 + tooltip-text: bind template.item as <Adw.TabPage>.keyword; 220 + } 221 + }; 222 + }; 223 + } 215 224 }; 216 - } 217 - }; 218 225 219 - styles [ 220 - "navigation-sidebar", 221 - ] 226 + styles [ 227 + "navigation-sidebar", 228 + ] 229 + } 230 + } 222 231 } 223 232 } 224 233 ··· 226 235 CenterBox { 227 236 margin-bottom: 6; 228 237 margin-start: 6; 238 + margin-top: 6; 229 239 230 240 start-widget: MenuButton { 231 241 icon-name: "shoe-box-symbolic";
+26
OuchBrowser/Utils/Url.cs
··· 1 + // I FUCKING HATE THE .NET DEVELOPERS FUCK FLURL FUCK SYSTEM.URI THERE IS 2 + // NO POINT TO LIFE ANYMORE 3 + // 4 + // THIS FILE IS MY PERSONAL FUCK YOU TO THE DEVELOPERS TO EVERY SINGLE LIBRARY 5 + // WHO HAS FAILED TO HANDLE SCHEMELESS URLS AND OTHER OBSCURE URL TYPES 6 + 7 + namespace OuchBrowser.Utils; 8 + 9 + class Url 10 + { 11 + public static bool IsUrl(string url) 12 + { 13 + if (url.StartsWith("https://") || url.StartsWith("http://")) // e.g. https://example.com 14 + { 15 + return true; 16 + } 17 + else if (url.Contains('.')) // e.g. example.com 18 + { 19 + return true; 20 + } 21 + else // e.g. example com 22 + { 23 + return false; 24 + } 25 + } 26 + }
+59 -2
OuchBrowser/Window.cs
··· 3 3 using WebKit; 4 4 using Application = Adw.Application; 5 5 using Object = GObject.Object; 6 + using OuchBrowser.Utils; 6 7 7 8 namespace OuchBrowser; 8 9 9 10 public class Window 10 11 { 11 - public static void OnActivate(Object app, EventArgs args) 12 + private string palette_state = "new_tab"; 13 + 14 + public Window() { } 15 + 16 + public void OnActivate(Object app, EventArgs args) 12 17 { 13 18 var application = (Application)app; 14 19 var window = new UI.Window(application); ··· 23 28 window.url_entry!.SetBuffer(buffer); 24 29 window.url_dialog!.Present(window); 25 30 window.url_entry!.GrabFocus(); 31 + palette_state = "new_tab"; 26 32 }); 27 33 actions.AddAction("palette", (action, parameter) => 28 34 { ··· 32 38 window.url_entry!.SetBuffer(buffer); 33 39 window.url_dialog!.Present(window); 34 40 window.url_entry!.GrabFocus(); 41 + palette_state = "current_tab"; 35 42 }); 36 43 application.SetAccelsForAction("win.palette-new", ["<Ctrl>t"]); 37 44 application.SetAccelsForAction("win.palette", ["<Ctrl>l"]); 38 45 39 46 window.url_entry!.OnActivate += (entry, _) => 40 47 { 41 - view.AddTab($"https://google.com/search?q={entry.GetBuffer().GetText()}", false); 48 + string query = entry.GetBuffer().GetText(); 49 + 50 + if (palette_state == "new_tab") 51 + { 52 + Console.WriteLine($"url: {query}"); 53 + Console.WriteLine($"isURL: {Url.IsUrl(query)}"); 54 + Console.WriteLine($"starts with https or http: {query.StartsWith("https://") || query.StartsWith("http://")}"); 55 + Console.WriteLine(""); 56 + 57 + if (Url.IsUrl(query)) 58 + { 59 + if (query.StartsWith("https://") || query.StartsWith("http://")) 60 + { 61 + view.AddTab(query, false); 62 + } 63 + else 64 + { 65 + view.AddTab($"https://{query}", false); 66 + } 67 + } 68 + else 69 + { 70 + view.AddTab($"https://google.com/search?q={query}", false); 71 + } 72 + } 73 + else 74 + { 75 + TabPage page = window.view!.GetSelectedPage()!; 76 + WebView webview = (WebView)page.Child!; 77 + 78 + Console.WriteLine($"url: {query}"); 79 + Console.WriteLine($"isURL: {Url.IsUrl(query)}"); 80 + Console.WriteLine($"starts with https or http: {query.StartsWith("https://") || query.StartsWith("http://")}"); 81 + Console.WriteLine(""); 82 + 83 + if (Url.IsUrl(query)) 84 + { 85 + if (query.StartsWith("https://") || query.StartsWith("http://")) 86 + { 87 + webview.LoadUri(query); 88 + } 89 + else 90 + { 91 + webview.LoadUri($"https://{query}"); 92 + } 93 + } 94 + else 95 + { 96 + webview.LoadUri($"https://google.com/search?q={query}"); 97 + } 98 + } 42 99 43 100 window.url_dialog!.ForceClose(); 44 101 window.url_dialog!.SetCanClose(true);