Skip to content

Truly independent web browser

UI/Qt: Update the macOS app with Sparkle

Jelle Raaijmakerscfef6a8c3ff0
diff --git a/Meta/package-macos-test-bundle.py b/Meta/package-macos-test-bundle.py
index 89fa4646c48..e1ac343d71e 100755
--- a/Meta/package-macos-test-bundle.py
+++ b/Meta/package-macos-test-bundle.py
@@ -145,6 +145,12 @@ def bundle_binaries(app: Path) -> list[Path]:
return mach_o_files(contents / "MacOS", contents / "lib", contents / "Frameworks", contents / "PlugIns")
+def is_in_nested_bundle(app: Path, binary: Path) -> bool:
+ """Whether the binary belongs to a framework or app bundle inside the app, such as Sparkle.framework, whose code the
+ build signed inside out together with the bundle's seal."""
+ return any(parent.suffix in (".framework", ".app") for parent in binary.relative_to(app).parents)
+
+
def find_qt_plugins_directory(search_directories: Iterable[Path]) -> Path:
"""The plugin directory of the Qt the app was built against.
@@ -247,12 +253,13 @@ def resign(app: Path, build_directory: Path) -> list[str]:
"""Re-sign every library and plugin in the bundle ad hoc (install_name_tool rewrote most of them, which invalidated
their signatures), then the helpers ad hoc with the entitlements the build gave them (see
ladybird_helper_process), then the bundle as a whole, which signs the main executable with the entitlements it
- already has and reseals the bundle over everything copied in."""
+ already has and reseals the bundle over everything copied in. Code in nested bundles keeps the signatures the build
+ gave it, since signing its files one by one would break the seals of those bundles; verify() checks them."""
executables_directory = app / "Contents" / "MacOS"
main_executable = executables_directory / "Ladybird"
resigned = []
for library in bundle_binaries(app):
- if library.parent != executables_directory:
+ if library.parent != executables_directory and not is_in_nested_bundle(app, library):
subprocess.run(["codesign", "--sign", "-", "--force", str(library)], check=True, capture_output=True)
for executable in mach_o_files(executables_directory):
if executable == main_executable:
diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txt
index 0bfb6313da2..f486236d965 100644
--- a/Tests/UI/Qt/CMakeLists.txt
+++ b/Tests/UI/Qt/CMakeLists.txt
@@ -92,3 +92,13 @@ if (APPLE)
ARGS $<TARGET_FILE:TestNativeTextEditingBindings> ${mode})
endforeach()
endif()
+
+# The tests link Sparkle through ladybird_impl, but run from the build directory rather than from the app bundle that
+# carries Sparkle.framework, so they find it where vcpkg installed it.
+if (APPLE)
+ find_package(unofficial-sparkle CONFIG REQUIRED)
+ get_target_property(sparkle_framework unofficial::sparkle::Sparkle IMPORTED_LOCATION)
+ get_filename_component(sparkle_frameworks_directory "${sparkle_framework}" DIRECTORY)
+ set_property(TARGET TestUIQt TestEventLoopImplementation TestFullscreenDebounce
+ APPEND PROPERTY BUILD_RPATH "${sparkle_frameworks_directory}")
+endif()
diff --git a/UI/CMakeLists.txt b/UI/CMakeLists.txt
index d8528197a76..5fa4d26f0ff 100644
--- a/UI/CMakeLists.txt
+++ b/UI/CMakeLists.txt
@@ -16,6 +16,28 @@ if (APPLE)
set(LADYBIRD_ICON_COMPOSER_PLIST_ENTRY "")
message(STATUS "actool is older than Xcode 26, so the app bundle only gets the flat icon")
endif()
+
+ set(LADYBIRD_SPARKLE_PLIST_ENTRIES "")
+ set(LADYBIRD_SPARKLE_FEED_URL "https://download.ladybird.org/macos/appcast.xml" CACHE STRING "The appcast that Sparkle finds updates in")
+ set(LADYBIRD_SPARKLE_PUBLIC_KEY "30mib/1Ke84cNc8KkKajhTkCP9Zu3iZRgophONX53Ik=" CACHE STRING "The public EdDSA key, in base64, that the appcast and its updates are signed with")
+
+ # The feed URL goes into the Info.plist as XML text, so a query string's & has to be escaped.
+ set(sparkle_feed_url_xml "${LADYBIRD_SPARKLE_FEED_URL}")
+ string(REPLACE "&" "&amp;" sparkle_feed_url_xml "${sparkle_feed_url_xml}")
+ string(REPLACE "<" "&lt;" sparkle_feed_url_xml "${sparkle_feed_url_xml}")
+ string(REPLACE ">" "&gt;" sparkle_feed_url_xml "${sparkle_feed_url_xml}")
+
+ # Sparkle verifies the appcast, and each update before it unpacks it, with the key. It only looks for updates when
+ # the user asks, and so never asks whether it may look by itself.
+ foreach (entry IN ITEMS
+ "<key>SUFeedURL</key>\n <string>${sparkle_feed_url_xml}</string>"
+ "<key>SUPublicEDKey</key>\n <string>${LADYBIRD_SPARKLE_PUBLIC_KEY}</string>"
+ "<key>SURequireSignedFeed</key>\n <true/>"
+ "<key>SUVerifyUpdateBeforeExtraction</key>\n <true/>"
+ "<key>SUEnableAutomaticChecks</key>\n <false/>"
+ )
+ string(APPEND LADYBIRD_SPARKLE_PLIST_ENTRIES "${entry}\n ")
+ endforeach()
endif()
function(create_ladybird_bundle target_name)
@@ -76,6 +98,25 @@ function(create_ladybird_bundle target_name)
)
endif()
+ # Sparkle installs updates with programs of its own in its framework, which are signed before the app.
+ get_target_property(sparkle_framework unofficial::sparkle::Sparkle IMPORTED_LOCATION)
+ set(bundled_sparkle_framework "${bundle_dir}/Contents/Frameworks/Sparkle.framework")
+ set_property(TARGET ${target_name} APPEND PROPERTY BUILD_RPATH "@executable_path/../Frameworks")
+ set_property(TARGET ${target_name} APPEND PROPERTY INSTALL_RPATH "@executable_path/../Frameworks")
+ add_custom_command(TARGET ${target_name} POST_BUILD
+ COMMAND "${CMAKE_COMMAND}" -E rm -rf "${bundled_sparkle_framework}"
+ COMMAND "${CMAKE_COMMAND}" -E make_directory "${bundle_dir}/Contents/Frameworks"
+ COMMAND ditto "${sparkle_framework}" "${bundled_sparkle_framework}"
+ COMMAND "${CMAKE_COMMAND}" -E rm -rf
+ "${bundled_sparkle_framework}/Headers" "${bundled_sparkle_framework}/Versions/B/Headers"
+ "${bundled_sparkle_framework}/PrivateHeaders" "${bundled_sparkle_framework}/Versions/B/PrivateHeaders"
+ "${bundled_sparkle_framework}/Modules" "${bundled_sparkle_framework}/Versions/B/Modules"
+ COMMAND codesign -s - -f -o runtime "${bundled_sparkle_framework}/Versions/B/Autoupdate"
+ COMMAND codesign -s - -f -o runtime "${bundled_sparkle_framework}/Versions/B/Updater.app"
+ COMMAND codesign -s - -f "${bundled_sparkle_framework}"
+ VERBATIM
+ )
+
# Note: This symlink is removed in the install commands
# This makes the bundle in the build directory *NOT* relocatable
add_custom_command(TARGET ${target_name} POST_BUILD
diff --git a/UI/Info.plist b/UI/Info.plist
index eeded2b2984..adae3f83c54 100644
--- a/UI/Info.plist
+++ b/UI/Info.plist
@@ -7,6 +7,7 @@
<key>CFBundleIconFile</key>
<string>app_icon.icns</string>
${LADYBIRD_ICON_COMPOSER_PLIST_ENTRY}
+ ${LADYBIRD_SPARKLE_PLIST_ENTRIES}
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 2ba20934642..75f41b83520 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -76,6 +76,7 @@
# include <UI/Qt/MacWindow.h>
# include <UI/Qt/MicrophoneAuthorizerMacOS.h>
# include <UI/Qt/ScrollbarPreferencesMac.h>
+# include <UI/Qt/SoftwareUpdaterMac.h>
# include <UI/Qt/SpellCheckerMac.h>
#endif
@@ -525,6 +526,18 @@ public:
m_help_menu->addAction(create_application_action(*m_application_widget, application.report_website_issue_action(), IncludeActionIcon::No));
m_help_menu->addSeparator();
m_help_menu->addAction(create_application_action(*m_application_widget, application.open_about_page_action(), IncludeActionIcon::No));
+
+#if defined(AK_OS_MACOS)
+ if (auto* software_updater = Application::the().software_updater()) {
+ // NB: On macOS, this moves the item into the application menu, below About Ladybird.
+ auto* check_for_updates_action = make_action("Check for Updates…");
+ check_for_updates_action->setMenuRole(QAction::ApplicationSpecificRole);
+ QObject::connect(check_for_updates_action, &QAction::triggered, this, [software_updater]() {
+ software_updater->check_for_updates();
+ });
+ m_help_menu->addAction(check_for_updates_action);
+ }
+#endif
}
#if defined(AK_OS_MACOS)
@@ -1117,6 +1130,9 @@ void Application::create_platform_actions()
if (auto* hub = HubConnection::the_if_connected())
hub->send_settings_changes(settings);
};
+#if defined(AK_OS_MACOS)
+ m_software_updater = SoftwareUpdater::create();
+#endif
m_web_ui_pages = make<WebUIPages>();
m_bookmarks = make<Bookmarks>(*m_bookmark_store);
m_web_ui_pages->register_page("history"_string, "History"_string, [](u64 web_ui_id, WebView::IsPrivate is_private) -> NonnullOwnPtr<WebUIPage> {
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index 28e388bc7f1..72b1b9225d5 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -37,6 +37,7 @@ class WebUIPages;
class Bookmarks;
class ProcessManagerWindow;
+class SoftwareUpdater;
struct WindowConfiguration {
Optional<Web::DevicePixels> x {};
@@ -152,6 +153,10 @@ public:
BrowserWindow* active_window_if_any() const { return m_active_window; }
BrowserWindow* non_private_window_if_any() const;
+#if defined(AK_OS_MACOS)
+ SoftwareUpdater* software_updater() { return m_software_updater.ptr(); }
+#endif
+
Tab* active_tab() const { return m_active_window ? m_active_window->current_tab() : nullptr; }
void update_reopen_recently_closed_actions() const;
@@ -325,6 +330,9 @@ private:
OwnPtr<WebView::SpellChecker> m_spell_checker;
OwnPtr<WebView::MicrophoneAuthorizer> m_microphone_authorizer;
OwnPtr<WebView::Settings> m_settings;
+#if defined(AK_OS_MACOS)
+ OwnPtr<SoftwareUpdater> m_software_updater;
+#endif
OwnPtr<SessionStore> m_session_store;
OwnPtr<SessionStore> m_private_session_store;
OwnPtr<WebView::FaviconStore> m_favicon_store;
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index 9d7b343615f..28650a109a8 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -154,17 +154,20 @@ if (APPLE)
Menu.mm
PlatformColorsMac.mm
ScrollbarPreferencesMac.mm
+ SoftwareUpdaterMac.mm
SpellCheckerMac.mm
SystemAppearanceMac.mm
TranslateIconMac.mm
WebContentViewAccessibility.mm
WebContentViewMac.mm
)
- target_link_libraries(ladybird_impl PRIVATE Qt::GuiPrivate "-framework ApplicationServices" "-framework AVFoundation" "-framework Carbon" "-framework Cocoa" "-framework CoreServices" "-framework IOSurface" "-framework QuartzCore")
+ find_package(unofficial-sparkle CONFIG REQUIRED)
+ target_link_libraries(ladybird_impl PRIVATE Qt::GuiPrivate unofficial::sparkle::Sparkle "-framework ApplicationServices" "-framework AVFoundation" "-framework Carbon" "-framework Cocoa" "-framework CoreServices" "-framework IOSurface" "-framework QuartzCore")
set_source_files_properties(
LadybirdAccessibilityElement.mm
MicrophoneAuthorizerMacOS.mm
PlatformColorsMac.mm
+ SoftwareUpdaterMac.mm
SpellCheckerMac.mm
TranslateIconMac.mm
TranslatorMac.mm
diff --git a/UI/Qt/SoftwareUpdaterMac.h b/UI/Qt/SoftwareUpdaterMac.h
new file mode 100644
index 00000000000..cc53f24f8eb
--- /dev/null
+++ b/UI/Qt/SoftwareUpdaterMac.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Noncopyable.h>
+#include <AK/NonnullOwnPtr.h>
+
+namespace Ladybird {
+
+namespace Detail {
+
+struct SparkleUpdater;
+
+}
+
+class SoftwareUpdater {
+ AK_MAKE_NONCOPYABLE(SoftwareUpdater);
+ AK_MAKE_NONMOVABLE(SoftwareUpdater);
+
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ static NonnullOwnPtr<SoftwareUpdater> create();
+ ~SoftwareUpdater();
+
+ void check_for_updates();
+
+private:
+ explicit SoftwareUpdater(NonnullOwnPtr<Detail::SparkleUpdater>);
+
+ NonnullOwnPtr<Detail::SparkleUpdater> m_sparkle;
+};
+
+}
diff --git a/UI/Qt/SoftwareUpdaterMac.mm b/UI/Qt/SoftwareUpdaterMac.mm
new file mode 100644
index 00000000000..e0844353161
--- /dev/null
+++ b/UI/Qt/SoftwareUpdaterMac.mm
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <UI/Qt/SoftwareUpdaterMac.h>
+
+#import <Sparkle/Sparkle.h>
+
+namespace Ladybird {
+
+namespace Detail {
+
+struct SparkleUpdater {
+ AK_ALLOC_WITH_KMALLOC;
+
+ SPUStandardUpdaterController* controller { nil };
+};
+
+}
+
+// Sparkle finds updates in the appcast that the app's Info.plist names. The Info.plist also keeps it from looking for
+// them by itself, so it only looks when the user asks.
+NonnullOwnPtr<SoftwareUpdater> SoftwareUpdater::create()
+{
+ auto sparkle = make<Detail::SparkleUpdater>();
+ sparkle->controller = [[SPUStandardUpdaterController alloc] initWithStartingUpdater:YES updaterDelegate:nil userDriverDelegate:nil];
+ return adopt_own(*new SoftwareUpdater(move(sparkle)));
+}
+
+SoftwareUpdater::SoftwareUpdater(NonnullOwnPtr<Detail::SparkleUpdater> sparkle)
+ : m_sparkle(move(sparkle))
+{
+}
+
+SoftwareUpdater::~SoftwareUpdater() = default;
+
+void SoftwareUpdater::check_for_updates()
+{
+ [m_sparkle->controller checkForUpdates:nil];
+}
+
+}