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

Commit 1cad4e7

Browse files
committed
handle devdocs appcache better
1 parent 8412e2f commit 1cad4e7

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

data/com.github.mdh34.quickdocs.gschema.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<summary>Last opened tab</summary>
1414
<description>Saves the last opened tab</description>
1515
</key>
16-
<key name="first" type="i">
17-
<default>0</default>
18-
<summary>First run</summary>
19-
<description>Sets if the application has been initialised yet</description>
20-
</key>
2116
<key name="window-x" type="i">
2217
<default>-1</default>
2318
<summary>Window X position</summary>

src/quickDocs.vala

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ public class App : Gtk.Application {
373373
}
374374

375375
var dev = new WebView.with_context (context);
376-
first_run (dev);
377376
set_appcache (dev, online);
378377
dev.load_uri (user_settings.get_string ("last-dev"));
379378
stack.add_titled (dev, "dev", "DevDocs");
@@ -398,7 +397,7 @@ public class App : Gtk.Application {
398397

399398
var theme_button = new Button.from_icon_name ("object-inverse");
400399
theme_button.clicked.connect(() => {
401-
toggle_theme (dev);
400+
toggle_theme (dev, online);
402401
});
403402

404403
var package_list = new ListBox ();
@@ -518,15 +517,6 @@ public class App : Gtk.Application {
518517
}
519518
}
520519

521-
private void first_run (WebView view) {
522-
var user_settings = new GLib.Settings ("com.github.mdh34.quickdocs");
523-
if (user_settings.get_int ("first") == 0) {
524-
view.load_uri ("https://devdocs.io");
525-
user_settings.set_int ("first", 1);
526-
}
527-
}
528-
529-
530520
private void init_theme () {
531521
var window_settings = Gtk.Settings.get_default ();
532522
var user_settings = new GLib.Settings ("com.github.mdh34.quickdocs");
@@ -540,9 +530,10 @@ public class App : Gtk.Application {
540530
}
541531

542532
private void set_appcache (WebView view, bool online) {
543-
var settings = view.get_settings ();
544-
if (online) {
545-
settings.enable_offline_web_application_cache = false;
533+
var user_settings = new GLib.Settings ("com.github.mdh34.quickdocs");
534+
var dark = user_settings.get_int ("dark");
535+
if (dark == 1 && online) {
536+
view.get_settings ().enable_offline_web_application_cache = false;
546537
}
547538
}
548539

@@ -569,19 +560,23 @@ public class App : Gtk.Application {
569560
stack.set_visible_child_name (tab);
570561
}
571562

572-
private void toggle_theme (WebView view) {
563+
private void toggle_theme (WebView view, bool online) {
573564
var window_settings = Gtk.Settings.get_default ();
574565
var user_settings = new GLib.Settings ("com.github.mdh34.quickdocs");
575566
var dark = user_settings.get_int ("dark");
576567
if (dark == 1) {
577568
window_settings.set ("gtk-application-prefer-dark-theme", false);
578-
user_settings.set_int ("dark", 0);
579569
view.run_javascript.begin ("document.cookie = 'dark=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';", null);
570+
user_settings.set_int ("dark", 0);
571+
view.get_settings ().enable_offline_web_application_cache = true;
580572
view.reload_bypass_cache ();
581573
} else {
582574
window_settings.set ("gtk-application-prefer-dark-theme", true);
583-
user_settings.set_int ("dark", 1);
584575
view.run_javascript.begin ("document.cookie = 'dark=1; expires=01 Jan 2100 00:00:00 UTC';", null);
576+
user_settings.set_int ("dark", 1);
577+
if (online) {
578+
view.get_settings ().enable_offline_web_application_cache = false;
579+
}
585580
view.reload_bypass_cache ();
586581
}
587582
}

0 commit comments

Comments
 (0)