Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 46d2217

Browse files
committed
cleanup and separate view code
1 parent ae07163 commit 46d2217

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ executable(
1414
'src/Application.vala',
1515
'src/Downloader.vala',
1616
'src/MainWindow.vala',
17+
'src/View.vala',
1718
dependencies: [
1819
dependency('gtk+-3.0'),
1920
dependency('libarchive'),

src/MainWindow.vala

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,8 @@ public class MainWindow : Gtk.Window {
360360
stack_switcher.set_stack (stack);
361361
header.set_custom_title (stack_switcher);
362362

363-
var context = new WebContext ();
364-
var cookies = context.get_cookie_manager ();
365-
set_cookies (cookies);
366-
367363
var online = check_online ();
368-
var vala = new WebView();
364+
var vala = new View();
369365

370366
if (online) {
371367
vala.load_uri (settings.get_string ("last-vala"));
@@ -384,8 +380,9 @@ public class MainWindow : Gtk.Window {
384380
stack.add_titled (pane, "vala", "Valadoc");
385381
}
386382

387-
var dev = new WebView.with_context (context);
388-
set_appcache (dev, online);
383+
var dev = new View ();
384+
dev.set_cookies ();
385+
dev.appcache_init (online);
389386
dev.load_uri (settings.get_string ("last-dev"));
390387
stack.add_titled (dev, "dev", "DevDocs");
391388

@@ -535,35 +532,12 @@ public class MainWindow : Gtk.Window {
535532
}
536533
}
537534

538-
private void set_appcache (WebView view, bool online) {
539-
var dark = settings.get_int ("dark");
540-
if (dark == 1 && online) {
541-
view.get_settings ().enable_offline_web_application_cache = false;
542-
}
543-
}
544-
545-
private void set_cookies (CookieManager cookies) {
546-
string path = Path.build_filename (Environment.get_user_config_dir (), "com.github.mdh34.quickdocs", "cookies");
547-
string folder = Path.build_filename (Environment.get_user_config_dir (), "com.github.mdh34.quickdocs");
548-
549-
if (!GLib.FileUtils.test (folder, GLib.FileTest.IS_DIR)) {
550-
var file = File.new_for_path (folder);
551-
try {
552-
file.make_directory ();
553-
} catch (Error e) {
554-
warning ("Unable to create config directory: %s", e.message);
555-
}
556-
}
557-
cookies.set_accept_policy (CookieAcceptPolicy.ALWAYS);
558-
cookies.set_persistent_storage (path, CookiePersistentStorage.SQLITE);
559-
}
560-
561535
private void set_tab () {
562536
var tab = settings.get_string ("tab");
563537
stack.set_visible_child_name (tab);
564538
}
565539

566-
private void toggle_theme (WebView view, bool online) {
540+
private void toggle_theme (View view, bool online) {
567541
var window_settings = Gtk.Settings.get_default ();
568542
var dark = settings.get_int ("dark");
569543
if (dark == 1) {

src/View.vala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2018 Matt Harris
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2 of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public
15+
* License along with this program; if not, write to the
16+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301 USA
18+
*
19+
* Authored by: Matt Harris <[email protected]>
20+
*/
21+
22+
public class View : WebKit.WebView {
23+
public void appcache_init (bool online) {
24+
var dark = new GLib.Settings ("com.github.mdh34.quickdocs").get_int ("dark");
25+
if (dark == 1 && online) {
26+
get_settings ().enable_offline_web_application_cache = false;
27+
}
28+
}
29+
30+
public void set_cookies () {
31+
string path = Path.build_filename (Environment.get_user_config_dir (), "com.github.mdh34.quickdocs", "cookies");
32+
string folder = Path.build_filename (Environment.get_user_config_dir (), "com.github.mdh34.quickdocs");
33+
var cookies = get_context ().get_cookie_manager ();
34+
if (!GLib.FileUtils.test (folder, GLib.FileTest.IS_DIR)) {
35+
var file = File.new_for_path (folder);
36+
try {
37+
file.make_directory ();
38+
} catch (Error e) {
39+
warning ("Unable to create config directory: %s", e.message);
40+
}
41+
}
42+
cookies.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS);
43+
cookies.set_persistent_storage (path, WebKit.CookiePersistentStorage.SQLITE);
44+
}
45+
}

0 commit comments

Comments
 (0)