Skip to content

Truly independent web browser

LibWebView: Add a setting for checking for updates

Jelle Raaijmakerse3d4ae5a5278
diff --git a/Base/res/ladybird/about-pages/settings.html b/Base/res/ladybird/about-pages/settings.html
index e0a81536b98..6fb5519b1de 100644
--- a/Base/res/ladybird/about-pages/settings.html
+++ b/Base/res/ladybird/about-pages/settings.html
@@ -1197,6 +1197,15 @@
</label>
<input id="filter-list-updates" type="checkbox" switch />
</div>
+ <div class="card-group inline-container">
+ <label for="update-checks">
+ Update checks
+ <p class="description">
+ Periodically check whether a newer version of Ladybird is available.
+ </p>
+ </label>
+ <input id="update-checks" type="checkbox" switch />
+ </div>
</div>
<p id="services-paused-note" class="description hidden" role="status">
Automatic service connections are paused. Individual service choices are preserved.
diff --git a/Base/res/ladybird/about-pages/settings/services.js b/Base/res/ladybird/about-pages/settings/services.js
index 032ae6dda2a..6c22cdbf56c 100644
--- a/Base/res/ladybird/about-pages/settings/services.js
+++ b/Base/res/ladybird/about-pages/settings/services.js
@@ -1,5 +1,6 @@
const allowServicesNetworkAccess = document.querySelector("#allow-services-network-access");
const filterListUpdates = document.querySelector("#filter-list-updates");
+const updateChecks = document.querySelector("#update-checks");
allowServicesNetworkAccess.addEventListener("change", () => {
ladybird.sendMessage("setServicesNetworkAccessEnabled", allowServicesNetworkAccess.checked);
@@ -7,6 +8,9 @@ allowServicesNetworkAccess.addEventListener("change", () => {
filterListUpdates.addEventListener("change", () => {
ladybird.sendMessage("setFilterListUpdatesEnabled", filterListUpdates.checked);
});
+updateChecks.addEventListener("change", () => {
+ ladybird.sendMessage("setUpdateChecksEnabled", updateChecks.checked);
+});
document.addEventListener("WebUIMessage", event => {
if (event.detail.name !== "loadSettings") {
@@ -20,5 +24,7 @@ document.addEventListener("WebUIMessage", event => {
allowServicesNetworkAccess.checked = settings.enabled;
filterListUpdates.checked = settings.features.contentBlockerSubscriptionUpdates;
filterListUpdates.disabled = !settings.enabled;
+ updateChecks.checked = settings.features.updateChecks;
+ updateChecks.disabled = !settings.enabled;
document.querySelector("#services-paused-note").classList.toggle("hidden", settings.enabled);
});
diff --git a/Base/res/ladybird/about-pages/welcome.css b/Base/res/ladybird/about-pages/welcome.css
index 6c3484a067e..7bfd0174168 100644
--- a/Base/res/ladybird/about-pages/welcome.css
+++ b/Base/res/ladybird/about-pages/welcome.css
@@ -137,6 +137,35 @@ section {
flex-shrink: 0;
}
+.switch-list {
+ gap: 0;
+ padding: 0 14px;
+ border-radius: 10px;
+ box-shadow: inset 0 0 0 1px var(--separator);
+}
+
+.switch-row {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ padding: 12px 0;
+}
+
+.switch-row + .switch-row {
+ border-top: 1px solid var(--separator);
+}
+
+.switch-row > div {
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ gap: 2px;
+}
+
+.switch-row input[switch] {
+ flex-shrink: 0;
+}
+
footer {
display: flex;
align-items: center;
diff --git a/Base/res/ladybird/about-pages/welcome.html b/Base/res/ladybird/about-pages/welcome.html
index 07908bf0d51..8832d1e7a92 100644
--- a/Base/res/ladybird/about-pages/welcome.html
+++ b/Base/res/ladybird/about-pages/welcome.html
@@ -124,14 +124,32 @@ SPDX-License-Identifier: BSD-2-Clause
</label>
</div>
</section>
- <section class="switch-card" aria-labelledby="ad-blocking-title">
- <div>
- <h2 id="ad-blocking-title">Block ads, trackers and more</h2>
- <p class="muted small">
- Pages load faster. If a site breaks, turn it off for that site from the address bar.
- </p>
+ <section class="switch-list">
+ <div class="switch-row">
+ <div>
+ <h2 id="ad-blocking-title">
+ <label for="enable-content-blocking">Block ads, trackers and more</label>
+ </h2>
+ <p class="muted small">
+ Pages load faster. If a site breaks, turn it off for that site from the address bar.
+ </p>
+ </div>
+ <input
+ id="enable-content-blocking"
+ type="checkbox"
+ switch
+ aria-labelledby="ad-blocking-title"
+ />
+ </div>
+ <div class="switch-row">
+ <div>
+ <h2 id="update-checks-title">
+ <label for="enable-update-checks">Check for updates</label>
+ </h2>
+ <p class="muted small">Ladybird tells you when a newer version is available.</p>
+ </div>
+ <input id="enable-update-checks" type="checkbox" switch aria-labelledby="update-checks-title" />
</div>
- <input id="enable-content-blocking" type="checkbox" switch aria-labelledby="ad-blocking-title" />
</section>
</fieldset>
<footer>
diff --git a/Base/res/ladybird/about-pages/welcome.js b/Base/res/ladybird/about-pages/welcome.js
index 43f6ad2771f..bed6c6de091 100644
--- a/Base/res/ladybird/about-pages/welcome.js
+++ b/Base/res/ladybird/about-pages/welcome.js
@@ -14,6 +14,7 @@ const searchSuggestionsDescription = document.querySelector("#search-suggestions
const tabLayoutInputs = document.querySelectorAll('input[name="tab-layout"]');
const colorThemeInputs = document.querySelectorAll('input[name="color-theme"]');
const enableContentBlocking = document.querySelector("#enable-content-blocking");
+const enableUpdateChecks = document.querySelector("#enable-update-checks");
const saveStatus = document.querySelector("#save-status");
let settings;
@@ -109,6 +110,7 @@ function initialize() {
updateSearchSuggestions();
enableContentBlocking.checked = settings.contentBlockers.enabled;
+ enableUpdateChecks.checked = settings.backgroundNetworking.features.updateChecks;
setupOptions.disabled = false;
startBrowsing.disabled = false;
}
@@ -154,6 +156,11 @@ enableContentBlocking.addEventListener("change", () => {
ladybird.sendMessage("setFilterListUpdatesEnabled", enableContentBlocking.checked);
});
+enableUpdateChecks.addEventListener("change", () => {
+ if (!initialized) return;
+ ladybird.sendMessage("setUpdateChecksEnabled", enableUpdateChecks.checked);
+});
+
form.addEventListener("submit", event => {
event.preventDefault();
if (!initialized || startBrowsing.disabled) return;
@@ -186,6 +193,8 @@ document.addEventListener("WebUIMessage", event => {
}
if (Object.hasOwn(data, "contentBlockers"))
enableContentBlocking.checked = settings.contentBlockers.enabled;
+ if (Object.hasOwn(data, "backgroundNetworking"))
+ enableUpdateChecks.checked = settings.backgroundNetworking.features.updateChecks;
}
} else if (name === "loadEngines") {
engines = data;
diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp
index 6de6c0cb27c..8f2261aebf9 100644
--- a/Libraries/LibWebView/Settings.cpp
+++ b/Libraries/LibWebView/Settings.cpp
@@ -87,6 +87,7 @@ static constexpr auto CRASH_REPORT_SENDING_KEY = "crashReportSending"sv;
static constexpr auto BACKGROUND_NETWORKING_KEY = "backgroundNetworking"sv;
static constexpr auto BACKGROUND_NETWORKING_ENABLED_KEY = "enabled"sv;
static constexpr auto BACKGROUND_NETWORKING_FEATURES_KEY = "features"sv;
+static constexpr auto UPDATE_CHECKS_KEY = "updateChecks"sv;
static constexpr auto CONTENT_BLOCKERS_KEY = "contentBlockers"sv;
static constexpr auto CONTENT_BLOCKER_SUBSCRIPTION_UPDATES_KEY = "contentBlockerSubscriptionUpdates"sv;
@@ -207,6 +208,14 @@ static auto const& CONFIG_VARIABLE_DEFINITIONS = *new Array<ConfigVariableDefini
.default_value = false,
.array_element_type = {},
},
+ {
+ .id = ConfigVariableID::UpdateCheckInterval,
+ .name = "updates.check_interval_minutes"sv,
+ .title = "Update check interval"sv,
+ .description = "How many minutes Ladybird waits after one check for a newer release before it checks again, while it checks for updates by itself. At least 5."sv,
+ .default_value = 4 * 60,
+ .array_element_type = {},
+ },
} };
ReadonlySpan<ConfigVariableDefinition> config_variable_definitions()
@@ -379,6 +388,11 @@ static bool config_variable_value_is_valid(ConfigVariableDefinition const& varia
return milliseconds.has_value() && *milliseconds >= 0 && value.get_double_with_precision_loss().value() == *milliseconds;
}
+ if (variable.id == ConfigVariableID::UpdateCheckInterval) {
+ auto minutes = value.get_integer<u32>();
+ return minutes.has_value() && *minutes >= 5 && value.get_double_with_precision_loss() == minutes;
+ }
+
if (variable.id == ConfigVariableID::MaximumDiskCacheSize) {
auto size = value.get_integer<u64>();
return size.has_value() && *size > 0 && *size <= NumericLimits<i64>::max() / MiB
@@ -494,6 +508,8 @@ void Settings::load_from_json(JsonValue const& json_value)
if (auto features = background_networking->get_object(BACKGROUND_NETWORKING_FEATURES_KEY); features.has_value()) {
if (auto filter_list_updates_enabled = features->get_bool(CONTENT_BLOCKER_SUBSCRIPTION_UPDATES_KEY); filter_list_updates_enabled.has_value())
m_filter_list_updates_enabled = *filter_list_updates_enabled;
+ if (auto update_checks_enabled = features->get_bool(UPDATE_CHECKS_KEY); update_checks_enabled.has_value())
+ m_update_checks_enabled = *update_checks_enabled;
}
}
@@ -883,6 +899,7 @@ JsonValue Settings::serialize_json() const
JsonObject background_network_features;
background_network_features.set(CONTENT_BLOCKER_SUBSCRIPTION_UPDATES_KEY, m_filter_list_updates_enabled);
+ background_network_features.set(UPDATE_CHECKS_KEY, m_update_checks_enabled);
JsonObject background_networking;
background_networking.set(BACKGROUND_NETWORKING_ENABLED_KEY, m_background_networking_enabled);
@@ -1516,6 +1533,18 @@ void Settings::set_filter_list_updates_enabled(bool enabled)
observer.background_networking_settings_changed();
}
+void Settings::set_update_checks_enabled(bool enabled)
+{
+ if (m_update_checks_enabled == enabled)
+ return;
+
+ m_update_checks_enabled = enabled;
+ persist_settings();
+
+ for (auto& observer : m_observers)
+ observer.background_networking_settings_changed();
+}
+
Optional<ContentBlockerList const&> Settings::content_blocker_list(StringView identifier) const
{
for (auto const& list : m_content_blocker_lists) {
diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h
index 4710a3f93f2..7896244029b 100644
--- a/Libraries/LibWebView/Settings.h
+++ b/Libraries/LibWebView/Settings.h
@@ -155,6 +155,7 @@ enum class ConfigVariableID : u8 {
SplitDownloadsWithoutValidators,
RestartStalledConnections,
DisableHighDynamicRangeSurfaces,
+ UpdateCheckInterval,
Count,
};
@@ -226,6 +227,7 @@ struct WEBVIEW_API SettingsData {
bool m_background_networking_enabled { true };
bool m_filter_list_updates_enabled { false };
+ bool m_update_checks_enabled { true };
bool m_content_blocker_enabled { false };
HashTable<String> m_content_blocker_disabled_sites;
Vector<ContentBlockerList> m_content_blocker_lists;
@@ -340,6 +342,9 @@ public:
bool filter_list_updates_enabled() const { return m_filter_list_updates_enabled; }
bool automatic_filter_list_updates_allowed() const { return m_background_networking_enabled && m_filter_list_updates_enabled; }
void set_filter_list_updates_enabled(bool);
+ bool update_checks_enabled() const { return m_update_checks_enabled; }
+ bool automatic_update_checks_allowed() const { return m_background_networking_enabled && m_update_checks_enabled; }
+ void set_update_checks_enabled(bool);
bool content_blocker_enabled() const { return m_content_blocker_enabled; }
void set_content_blocker_enabled(bool);
diff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cpp
index 60097b65b13..e7259cec66f 100644
--- a/Libraries/LibWebView/WebUI/SettingsUI.cpp
+++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp
@@ -112,6 +112,9 @@ void SettingsUI::register_interfaces()
register_interface("setFilterListUpdatesEnabled"sv, [this](auto const& data) {
set_filter_list_updates_enabled(data);
});
+ register_interface("setUpdateChecksEnabled"sv, [this](auto const& data) {
+ set_update_checks_enabled(data);
+ });
register_interface("setAppearance"sv, [this](auto const& data) {
set_appearance(data);
});
@@ -726,6 +729,14 @@ void SettingsUI::set_filter_list_updates_enabled(JsonValue const& enabled)
Application::settings().set_filter_list_updates_enabled(enabled.as_bool());
}
+void SettingsUI::set_update_checks_enabled(JsonValue const& enabled)
+{
+ if (!enabled.is_bool())
+ return;
+
+ Application::settings().set_update_checks_enabled(enabled.as_bool());
+}
+
void SettingsUI::update_content_blocker_lists(JsonValue const&)
{
Application::the().update_content_blocker_lists({});
diff --git a/Libraries/LibWebView/WebUI/SettingsUI.h b/Libraries/LibWebView/WebUI/SettingsUI.h
index 57aec6ebffe..534d5d46c2b 100644
--- a/Libraries/LibWebView/WebUI/SettingsUI.h
+++ b/Libraries/LibWebView/WebUI/SettingsUI.h
@@ -98,6 +98,7 @@ private:
void set_services_network_access_enabled(JsonValue const&);
void set_filter_list_updates_enabled(JsonValue const&);
+ void set_update_checks_enabled(JsonValue const&);
void update_content_blocker_lists(JsonValue const&);
void set_content_blocker_enabled(JsonValue const&);
void set_content_blocker_enabled_for_site(JsonValue const&);
diff --git a/Tests/LibWebView/TestBackgroundNetworking.cpp b/Tests/LibWebView/TestBackgroundNetworking.cpp
index 6043a7920d6..b863a54bed6 100644
--- a/Tests/LibWebView/TestBackgroundNetworking.cpp
+++ b/Tests/LibWebView/TestBackgroundNetworking.cpp
@@ -74,6 +74,34 @@ TEST_CASE(feature_policy)
remove_settings_file();
}
+TEST_CASE(update_check_policy)
+{
+ remove_settings_file();
+ auto settings = WebView::Settings::create(settings_path());
+
+ EXPECT(settings.update_checks_enabled());
+ EXPECT(settings.automatic_update_checks_allowed());
+
+ settings.set_background_networking_enabled(false);
+ EXPECT(!settings.automatic_update_checks_allowed());
+ EXPECT(settings.update_checks_enabled());
+
+ settings.set_background_networking_enabled(true);
+ settings.set_update_checks_enabled(false);
+ EXPECT(!settings.automatic_update_checks_allowed());
+
+ auto reloaded = WebView::Settings::create(settings_path());
+ EXPECT(!reloaded.update_checks_enabled());
+ EXPECT(reloaded.automatic_update_checks_allowed() == false);
+ EXPECT_EQ(reloaded.config_variable_as_integer<u32>(WebView::ConfigVariableID::UpdateCheckInterval), 240u);
+
+ reloaded.set_config_variable(WebView::ConfigVariableID::UpdateCheckInterval, JsonValue { 4 });
+ EXPECT_EQ(reloaded.config_variable_as_integer<u32>(WebView::ConfigVariableID::UpdateCheckInterval), 240u);
+ reloaded.set_config_variable(WebView::ConfigVariableID::UpdateCheckInterval, JsonValue { 5 });
+ EXPECT_EQ(reloaded.config_variable_as_integer<u32>(WebView::ConfigVariableID::UpdateCheckInterval), 5u);
+ remove_settings_file();
+}
+
TEST_CASE(settings_are_persistent)
{
remove_settings_file();