21 Commits
Author SHA1 Message Date
Codex aab2bc0cee perf(tabs): release stale image and tab state
Pixel 10 APK / build (push) Successful in 37m12s
2026-08-10 17:59:50 +02:00
Codex 03227320f4 perf(android): move thumbnail encoding off UI path 2026-08-10 17:59:42 +02:00
Codex 4a5a01dc97 fix(ci): use Gitea artifact protocol
Pixel 10 APK / build (push) Successful in 36m15s
2026-08-10 08:34:02 +02:00
Codex 01dcb4705d fix(android): let Flutter own Pixel 10 ABI split
Pixel 10 APK / build (push) Failing after 33m19s
2026-08-10 07:59:11 +02:00
Codex 6508dfa8a7 fix(android): emit ARM64-only Pixel 10 APK
Pixel 10 APK / build (push) Failing after 10m35s
2026-08-10 07:47:26 +02:00
Codex ac4a267d30 fix(ci): size Android heap from measured usage
Pixel 10 APK / build (push) Failing after 32m39s
2026-08-10 07:12:29 +02:00
Codex b4afa40c19 fix(ci): bound and slim Pixel 10 build
Pixel 10 APK / build (push) Failing after 35m20s
2026-08-10 06:35:51 +02:00
Codex 96a0334a71 fix(ci): constrain Android build resources 2026-08-10 06:34:02 +02:00
Codex 56fea16f7b fix(ci): reclaim disk before Android build
Pixel 10 APK / build (push) Failing after 3h12m50s
2026-08-09 21:55:50 +02:00
Codex 2f51f3e0a2 fix(ci): install Rust Android toolchain
Pixel 10 APK / build (push) Failing after 26m16s
2026-08-09 21:27:47 +02:00
Codex 9d1d60d170 fix(ci): limit Gradle pressure on shared runner
Pixel 10 APK / build (push) Failing after 21m2s
2026-08-09 19:36:13 +02:00
Codex 158b4ffa56 fix(ci): install native minimum Android platform
Pixel 10 APK / build (push) Failing after 34m53s
2026-08-09 19:08:41 +02:00
Codex 0ecfe2cc68 fix(ci): install Android 17 preview platform
Pixel 10 APK / build (push) Failing after 11m43s
2026-08-09 18:55:23 +02:00
Codex 96aa647cf9 fix(ci): enable preview Android SDK channel
Pixel 10 APK / build (push) Failing after 1m44s
2026-08-09 18:52:27 +02:00
Codex b725d4730e fix(ci): install Android compile SDK platform
Pixel 10 APK / build (push) Failing after 1m42s
2026-08-09 18:49:02 +02:00
Codex eb47eba676 fix(scripts): support Python 3.9 quote builds
Pixel 10 APK / build (push) Failing after 11m43s
2026-08-09 18:35:29 +02:00
Codex 273035ab02 fix(ci): trust downloaded Flutter SDK
Pixel 10 APK / build (push) Failing after 4m22s
2026-08-09 18:29:53 +02:00
Codex d3fc18dbec fix(ci): use configured Android SDK manager
Pixel 10 APK / build (push) Failing after 2m48s
2026-08-09 18:25:36 +02:00
Codex 93bf64c61d fix(ci): provision Android SDK on runner
Pixel 10 APK / build (push) Failing after 1m47s
2026-08-09 18:18:36 +02:00
Codex 56fe95dbd4 fix(ci): install Flutter runner prerequisites
Pixel 10 APK / build (push) Failing after 19m20s
2026-08-09 18:03:01 +02:00
Codex 1046a1fe71 docs(android): document Gitea Pixel 10 releases
Pixel 10 APK / build (push) Failing after 5m55s
2026-08-09 17:27:14 +02:00
17 changed files with 491 additions and 58 deletions
+154 -11
View File
@@ -9,6 +9,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 45
env:
KEY_JKS: ${{ secrets.PIXEL10_KEY_JKS }}
KEY_PATH: ${{ github.workspace }}/apps/weblibre/pixel10-release.jks
@@ -17,6 +18,39 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install runner prerequisites
shell: bash
run: |
set -euo pipefail
required_commands=(jq unzip zip xz readelf python3)
missing_command=false
for command_name in "${required_commands[@]}"; do
if ! command -v "$command_name" >/dev/null 2>&1; then
missing_command=true
break
fi
done
if [[ "$missing_command" == "true" ]]; then
sudo_command=()
if [[ "$EUID" -ne 0 ]]; then
sudo_command=(sudo)
fi
export DEBIAN_FRONTEND=noninteractive
"${sudo_command[@]}" apt-get update
"${sudo_command[@]}" apt-get install -y --no-install-recommends \
jq unzip zip xz-utils binutils python3
fi
- name: Validate signing configuration
shell: bash
run: |
set -euo pipefail
test -n "$KEY_JKS"
test -n "$KEY_PASSWORD"
test -n "$KEY_ALIAS"
printf '%s' "$KEY_JKS" | base64 -d > "$KEY_PATH"
chmod 600 "$KEY_PATH"
- uses: actions/setup-java@v4
with:
distribution: temurin
@@ -26,23 +60,53 @@ jobs:
with:
go-version: 1.25.x
- name: Set up Rust Android toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Set up Android SDK
uses: android-actions/setup-android@v3
- uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.44.5
cache: true
# The act_runner cache endpoint is not reachable from job containers
# in this setup and otherwise adds two ~5 minute timeouts per run.
cache: false
- name: Install Android NDK
- name: Trust Flutter SDK checkout
shell: bash
run: |
set -euo pipefail
flutter_sdk="$(dirname "$(dirname "$(command -v flutter)")")"
git config --global --add safe.directory "$flutter_sdk"
- name: Install Android SDK platform and NDK
shell: bash
run: |
set -euo pipefail
android_api="$(sed -n 's/^[[:space:]]*compileSdkVersion[[:space:]]*=[[:space:]]*//p' apps/weblibre/android/build.gradle | head -n 1)"
android_platform="$android_api.0"
ndk_version="$(sed -n 's/^weblibre\.ndkVersion[[:space:]]*=[[:space:]]*//p' apps/weblibre/android/gradle.properties)"
test -n "$android_api"
test -n "$ndk_version"
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --install "ndk;$ndk_version" || test "${PIPESTATUS[1]}" -eq 0
yes | sdkmanager --channel=3 --install \
"platforms;android-24" \
"platforms;android-$android_platform" \
"build-tools;36.0.0" \
"cmake;3.22.1" \
"ndk;$ndk_version" || test "${PIPESTATUS[1]}" -eq 0
test -f "$ANDROID_HOME/platforms/android-24/android.jar"
test -f "$ANDROID_HOME/platforms/android-$android_platform/android.jar"
test -f "$ANDROID_HOME/build-tools/36.0.0/aapt2"
test -x "$ANDROID_HOME/cmake/3.22.1/bin/cmake"
test -f "$ANDROID_HOME/ndk/$ndk_version/source.properties"
{
echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$ndk_version"
echo "ANDROID_NDK_ROOT=$ANDROID_HOME/ndk/$ndk_version"
@@ -54,6 +118,13 @@ jobs:
dart pub global activate melos 7.8.1
melos bootstrap
- name: Test Pixel 10 performance regressions
working-directory: apps/weblibre
run: >-
flutter test --no-pub
test/features/geckoview/utils/image_helper_test.dart
test/features/geckoview/domain/providers/tab_detail_state_test.dart
- name: Generate bundled assets
run: |
melos run update-assets --no-select
@@ -76,23 +147,95 @@ jobs:
env:
SING_BOX_SOURCE: ${{ runner.temp }}/sing-box
IPTPROXY_SOURCE: ${{ runner.temp }}/IPtProxy
run: melos run build-go-runtime --no-select
- name: Create release key
# Pixel 10 is ARM64-only. Avoid building and storing three unused ABIs.
TARGET: android/arm64
# Go writes verbose compiler progress to stderr. Gitea's act runner
# otherwise labels every one of those harmless lines as "ERROR".
run: melos run build-go-runtime --no-select 2>&1
- name: Reclaim disk before Android build
shell: bash
run: |
set -euo pipefail
test -n "$KEY_JKS"
printf '%s' "$KEY_JKS" | base64 -d > "$KEY_PATH"
chmod 600 "$KEY_PATH"
# These inputs and compiler caches are only needed to create the AAR
# installed by the previous step. Cargokit, Gradle and artifact upload
# need the reclaimed space later in the same job container.
rm -rf \
"$RUNNER_TEMP/sing-box" \
"$RUNNER_TEMP/IPtProxy" \
native/go_mobile_runtime/.work/android
go clean -cache -modcache
available_kib="$(df -Pk / | awk 'NR == 2 { print $4 }')"
minimum_kib=$((8 * 1024 * 1024))
df -h /
if (( available_kib < minimum_kib )); then
echo "At least 8 GiB of free runner disk is required before the Android build; only $((available_kib / 1024 / 1024)) GiB is available." >&2
exit 1
fi
- name: Build and verify Pixel 10 APK
run: melos run build-browser-pixel10 --no-select
env:
CARGO_BUILD_JOBS: "2"
CARGO_INCREMENTAL: "0"
# The previous measured run kept about 16 GiB RAM free. GeckoView's
# Jetifier transform needs more than a 1 GiB heap, while two workers
# still leave ample headroom for the colocated Gitea instance.
JAVA_TOOL_OPTIONS: -XX:ActiveProcessorCount=2
GRADLE_OPTS: >-
-Dorg.gradle.jvmargs=-Xmx4G
-Dorg.gradle.workers.max=2
-Dorg.gradle.parallel=false
-Dorg.gradle.daemon=false
-Dkotlin.compiler.execution.strategy=in-process
shell: bash
run: |
set -euo pipefail
- uses: actions/upload-artifact@v4
# A deadlocked native build used to stay alive until act_runner's
# three-hour job container expired. Keep a hard local deadline and
# emit a heartbeat so a stalled or disk-starved build is obvious.
timeout --foreground --signal=TERM --kill-after=1m 30m \
melos run build-browser-pixel10 --no-select &
build_pid=$!
monitor_resources() {
while kill -0 "$build_pid" 2>/dev/null; do
sleep 60
kill -0 "$build_pid" 2>/dev/null || return 0
available_kib="$(df -Pk / | awk 'NR == 2 { print $4 }')"
echo "Pixel 10 build heartbeat: $((available_kib / 1024 / 1024)) GiB disk available"
awk '/MemAvailable:/ { printf "Memory available: %.1f GiB\n", $2 / 1024 / 1024 }' /proc/meminfo
if (( available_kib < 2 * 1024 * 1024 )); then
echo "Stopping Android build before the runner disk is exhausted." >&2
kill -TERM "$build_pid" 2>/dev/null || true
return 1
fi
done
}
monitor_resources &
monitor_pid=$!
cleanup_monitor() {
kill "$monitor_pid" 2>/dev/null || true
wait "$monitor_pid" 2>/dev/null || true
}
trap cleanup_monitor EXIT
set +e
wait "$build_pid"
build_status=$?
set -e
exit "$build_status"
# Gitea's artifact service implements the v3 protocol. The v4 action
# rejects non-GitHub servers with GHESNotSupportedError before upload.
- uses: actions/upload-artifact@v3
with:
name: mrbweblibre-pixel10
path: apps/weblibre/build/app/outputs/flutter-apk/app-pixel10-release.apk
if-no-files-found: error
- name: Remove release key
if: always()
+29 -1
View File
@@ -32,7 +32,8 @@ the generated assets and native runtime, then run:
melos run build-browser-pixel10 --no-select
```
The command produces:
The command asks Flutter for a split ARM64 artifact, verifies that no other
ABI is packaged, and publishes it under the stable path:
```text
apps/weblibre/build/app/outputs/flutter-apk/app-pixel10-release.apk
@@ -41,6 +42,33 @@ apps/weblibre/build/app/outputs/flutter-apk/app-pixel10-release.apk
Release builds require the same signing environment variables as upstream:
`KEY_PATH`, `KEY_ALIAS`, and `KEY_PASSWORD`.
## Gitea Actions
The workflow at `.gitea/workflows/pixel10.yml` runs on every push to the
`pixel10` branch and can also be started manually. It needs an Actions runner
with the `ubuntu-latest` label and these repository secrets:
| Secret | Value |
| --- | --- |
| `PIXEL10_KEY_JKS` | Base64-encoded Android signing keystore |
| `PIXEL10_KEY_ALIAS` | Alias of the signing key |
| `PIXEL10_KEY_PASSWORD` | Keystore and key password |
Create a dedicated key once and keep both the keystore and password backed up.
Losing the signing key makes it impossible to install future updates over an
existing MrbWebLibre installation.
```bash
keytool -genkeypair -v \
-keystore pixel10-release.jks \
-alias mrbweblibre \
-keyalg RSA -keysize 4096 -validity 10000
base64 -w 0 pixel10-release.jks
```
Add the resulting one-line Base64 value as `PIXEL10_KEY_JKS`; do not commit the
keystore itself. The workflow removes the decoded file even when a build fails.
## Verify an existing APK
```bash
+4 -6
View File
@@ -74,17 +74,15 @@ android {
manifestPlaceholders = [appName: "WebLibre Alpha (Legacy)", enableImpeller: "false"]
}
// Pixel 10 devices are 64-bit only and ship a 120 Hz display. Keep a
// separate, side-by-side installable identity for the optimized fork,
// retain Impeller, and prevent transitive dependencies from packaging
// unused 32-bit native libraries.
// separate, side-by-side installable identity for the optimized fork
// and retain Impeller. The Pixel 10 build script selects android-arm64
// with Flutter's ABI split; Gradle forbids combining that split with a
// second ndk.abiFilters declaration here.
pixel10 {
dimension "track"
applicationId "cc.mrblake.mrbweblibre"
versionNameSuffix "-pixel10"
manifestPlaceholders = [appName: "MrbWebLibre", enableImpeller: "true"]
ndk {
abiFilters "arm64-v8a"
}
}
}
@@ -54,6 +54,14 @@ class TabProgressStates extends _$TabProgressStates {
state = {...state}..[tabId] = progress;
}
void removeAll(Set<String> tabIds) {
if (!state.keys.any(tabIds.contains)) {
return;
}
state = {...state}..removeWhere((tabId, _) => tabIds.contains(tabId));
}
}
@Riverpod()
@@ -88,6 +96,17 @@ class TabThumbnails extends _$TabThumbnails {
state = {...state}..[tabId] = thumbnail;
}
void removeAll(Set<String> tabIds) {
if (!state.keys.any(tabIds.contains)) {
return;
}
// EquatableImage owns its ui.Image through a finalizer. Dropping the map
// reference is safer than disposing it here because an outgoing tab-preview
// frame may still hold the same wrapper briefly.
state = {...state}..removeWhere((tabId, _) => tabIds.contains(tabId));
}
}
@Riverpod()
@@ -112,6 +131,14 @@ class TabHistoryStates extends _$TabHistoryStates {
state = {...state}..[tabId] = history;
}
void removeAll(Set<String> tabIds) {
if (!state.keys.any(tabIds.contains)) {
return;
}
state = {...state}..removeWhere((tabId, _) => tabIds.contains(tabId));
}
}
@Riverpod()
@@ -142,6 +169,14 @@ class TabFindResultStates extends _$TabFindResultStates {
FindResultState resultFor(String tabId) =>
state[tabId] ?? FindResultState.$default();
void removeAll(Set<String> tabIds) {
if (!state.keys.any(tabIds.contains)) {
return;
}
state = {...state}..removeWhere((tabId, _) => tabIds.contains(tabId));
}
}
@Riverpod()
@@ -170,6 +205,14 @@ class TabTranslationStates extends _$TabTranslationStates {
state = {...state}..[tabId] = translation;
}
void removeAll(Set<String> tabIds) {
if (!state.keys.any(tabIds.contains)) {
return;
}
state = {...state}..removeWhere((tabId, _) => tabIds.contains(tabId));
}
}
@Riverpod()
@@ -36,6 +36,7 @@ import 'package:weblibre/features/geckoview/domain/entities/states/translation.d
import 'package:weblibre/features/geckoview/domain/providers.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_detail_state.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_list.dart';
import 'package:weblibre/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/isolation_context.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
@@ -75,6 +76,14 @@ class TabStates extends _$TabStates {
state = {...state}..[tabId] = next;
}
void _removeAll(Set<String> tabIds) {
if (!state.keys.any(tabIds.contains)) {
return;
}
state = {...state}..removeWhere((tabId, _) => tabIds.contains(tabId));
}
Future<void> _onTabContentStateChange(TabContentState contentState) async {
final current = await patchedState(contentState.id);
@@ -187,6 +196,9 @@ class TabStates extends _$TabStates {
bytes,
targetWidth: thumbnailDecodeWidth,
allowUpscaling: false,
// Periodic screenshots are almost always unique. Caching each decode
// retained up to 100 obsolete GPU images in the global icon LRU.
cacheResult: false,
),
);
@@ -415,6 +427,29 @@ class TabStates extends _$TabStates {
},
);
ref.listen(tabListProvider, (previous, next) {
if (previous == null) {
// The first list can be a partial restore snapshot. There is no reliable
// removal signal until Gecko has emitted at least two snapshots.
return;
}
final activeTabIds = next.value.toSet();
final removedTabIds = previous.value
.where((tabId) => !activeTabIds.contains(tabId))
.toSet();
if (removedTabIds.isEmpty) {
return;
}
_removeAll(removedTabIds);
ref.read(tabProgressStatesProvider.notifier).removeAll(removedTabIds);
ref.read(tabThumbnailsProvider.notifier).removeAll(removedTabIds);
ref.read(tabHistoryStatesProvider.notifier).removeAll(removedTabIds);
ref.read(tabFindResultStatesProvider.notifier).removeAll(removedTabIds);
ref.read(tabTranslationStatesProvider.notifier).removeAll(removedTabIds);
});
ref.onDispose(() async {
for (final sub in subscriptions) {
await sub.cancel();
@@ -32,15 +32,18 @@ import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/geckoview/domain/entities/states/tab.dart';
import 'package:weblibre/features/geckoview/domain/entities/tab_container_selection.dart';
import 'package:weblibre/features/geckoview/domain/providers.dart';
import 'package:weblibre/features/geckoview/domain/providers/desktop_mode.dart';
import 'package:weblibre/features/geckoview/domain/providers/pending_tab_selection.dart';
import 'package:weblibre/features/geckoview/domain/providers/restore_complete.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_detail_state.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_list.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_session.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/controllers/home_target_controller.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_data.dart';
import 'package:weblibre/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/database/database.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/isolation_context.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
@@ -1211,6 +1214,21 @@ class TabRepository extends _$TabRepository {
ref.listen(
tabListProvider,
(previous, next) async {
final activeTabIds = next.value.toSet();
final removedTabIds = previous?.value
.where((tabId) => !activeTabIds.contains(tabId))
.toSet();
if (removedTabIds != null) {
for (final tabId in removedTabIds) {
// These families are keepAlive so tab-specific state survives while
// a tab is merely in the background. Once Gecko confirms removal,
// keeping their services and listeners serves no purpose.
ref.invalidate(tabSessionProvider(tabId: tabId));
ref.invalidate(desktopModeProvider(tabId));
ref.invalidate(findInPageRepositoryProvider(tabId));
}
}
if (_suppressNextReclose) {
_suppressNextReclose = false;
// Drop tombstones for the tabs that just came back via undo so
@@ -1000,6 +1000,20 @@ class BrowserScreen extends HookConsumerWidget {
final pendingProxyLoadErrors = useRef(<String, _PendingProxyLoadError>{});
final selectedTabIdForProxyPrompt = ref.watch(selectedTabProvider);
ref.listen(tabListProvider, (previous, next) {
if (previous == null) return;
final activeTabIds = next.value.toSet();
for (final tabId in previous.value.where(
(tabId) => !activeTabIds.contains(tabId),
)) {
// UI-scoped families intentionally survive while a tab is backgrounded,
// but must not retain listeners and text state after it is closed.
ref.invalidate(toolbarVisibilityControllerProvider(tabId));
ref.invalidate(findInPageControllerProvider(tabId));
}
});
Future<void> handleProxyLoadError({
required String tabId,
required String? contextId,
@@ -111,8 +111,16 @@ class _BrowserViewState extends ConsumerState<BrowserView>
static const _pointerThrottleInterval = Duration(milliseconds: 32);
DateTime _lastPointerEvent = DateTime(0);
Offset _accumulatedDelta = Offset.zero;
bool _screenshotCaptureInFlight = false;
Future<void> _timerTick(Timer timer) async {
// Timer.periodic does not await async callbacks. A slow Gecko capture used
// to overlap the next tick, multiplying GPU readbacks, bitmap encoders and
// thumbnail events exactly while the device was already under load.
if (_screenshotCaptureInFlight) {
return;
}
// Skip the (expensive) Gecko render-to-bitmap while a full-cover route
// (settings, tab tray, search, …) occludes the browser. The screenshot
// would force an off-screen render the user can't see and competes for the
@@ -133,15 +141,17 @@ class _BrowserViewState extends ConsumerState<BrowserView>
return;
}
await ref
.read(selectedTabSessionProvider)
.requestScreenshot(requireImageResult: false)
.onError((error, stackTrace) {
logger.e(error, stackTrace: stackTrace);
timer.cancel();
return null;
});
_screenshotCaptureInFlight = true;
try {
await ref
.read(selectedTabSessionProvider)
.requestScreenshot(requireImageResult: false);
} catch (error, stackTrace) {
logger.e(error, stackTrace: stackTrace);
timer.cancel();
} finally {
_screenshotCaptureInFlight = false;
}
}
@override
@@ -27,6 +27,7 @@ import 'package:weblibre/core/logger.dart';
import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/geckoview/domain/providers.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_list.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/features/pwa/domain/pwa_installability.dart';
import 'package:weblibre/features/web_search/domain/controllers/sandbox_capture_controller.dart';
@@ -66,6 +67,21 @@ class PwaManifestState extends _$PwaManifestState {
},
);
ref.listen(tabListProvider, (previous, next) {
if (previous == null) return;
final activeTabIds = next.value.toSet();
final removedTabIds = previous.value
.where((tabId) => !activeTabIds.contains(tabId))
.toSet();
if (!removedTabIds.any(state.containsKey)) {
return;
}
state = {...state}
..removeWhere((tabId, _) => removedTabIds.contains(tabId));
});
return {};
}
}
@@ -42,6 +42,7 @@ Future<EquatableImage?> tryDecodeImage(
int? targetWidth,
int? targetHeight,
bool allowUpscaling = true,
bool cacheResult = true,
}) async {
// The decode options are part of the identity of the result, not just of the
// request: the same bytes decoded at a thumbnail's target width and at an
@@ -55,11 +56,13 @@ Future<EquatableImage?> tryDecodeImage(
allowUpscaling: allowUpscaling,
);
final cached = _cache.get(identity);
if (cached?.value != null) {
return cached;
} else if (cached != null) {
_cache.remove(identity);
if (cacheResult) {
final cached = _cache.get(identity);
if (cached?.value != null) {
return cached;
} else if (cached != null) {
_cache.remove(identity);
}
}
try {
@@ -74,7 +77,9 @@ Future<EquatableImage?> tryDecodeImage(
final image = EquatableImage(frameInfo.image, identity: identity);
if (image.value != null && image.value!.width > 0) {
_cache.set(identity, image);
if (cacheResult) {
_cache.set(identity, image);
}
return image;
}
} catch (e, s) {
@@ -87,7 +92,9 @@ Future<EquatableImage?> tryDecodeImage(
targetHeight: targetHeight,
);
if (svgImage != null) {
_cache.set(identity, svgImage);
if (cacheResult) {
_cache.set(identity, svgImage);
}
return svgImage;
}
} catch (svgError, svgStackTrace) {
+1 -1
View File
@@ -2,7 +2,7 @@ name: weblibre
description: "The Privacy-Focused & AI-Powered Research Browser"
publish_to: 'none'
resolution: workspace
version: 0.30.0-alpha-3+40
version: 0.30.0-alpha-3+41
environment:
sdk: '>=3.8.0 <4.0.0'
@@ -0,0 +1,34 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:riverpod/riverpod.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_detail_state.dart';
void main() {
test('closed tab progress is pruned without touching active tabs', () {
final container = ProviderContainer();
addTearDown(container.dispose);
final notifier = container.read(tabProgressStatesProvider.notifier);
notifier.update('closed-tab', 80);
notifier.update('active-tab', 40);
notifier.removeAll({'closed-tab', 'unknown-tab'});
expect(container.read(tabProgressStatesProvider), {'active-tab': 40});
});
test('pruning unrelated ids does not publish a new map', () {
final container = ProviderContainer();
addTearDown(container.dispose);
final notifier = container.read(tabProgressStatesProvider.notifier);
notifier.update('active-tab', 40);
final before = container.read(tabProgressStatesProvider);
notifier.removeAll({'unknown-tab'});
expect(
identical(container.read(tabProgressStatesProvider), before),
isTrue,
);
});
}
@@ -75,6 +75,27 @@ void main() {
});
});
testWidgets('tryDecodeImage can bypass the global image cache', (
tester,
) async {
await tester.runAsync(() async {
clearImageCache();
final svgBytes = Uint8List.fromList(utf8.encode(_svgIcon));
final first = await tryDecodeImage(svgBytes, cacheResult: false);
final second = await tryDecodeImage(svgBytes, cacheResult: false);
expect(first, isNotNull);
expect(second, isNotNull);
expect(first, equals(second));
expect(identical(first, second), isFalse);
// These are deliberately distinct uncached image resources.
first!.dispose();
second!.dispose();
});
});
test('ImageIdentity compares structurally, not by a folded hash', () {
const a = (
digest: 0x0123456789ABCDEF,
@@ -9,32 +9,42 @@ package eu.weblibre.flutter_mozilla_components.ext
import android.graphics.Bitmap
import android.os.Build
import java.io.ByteArrayOutputStream
import kotlin.math.roundToInt
fun Bitmap.resize(maxWidth: Int, maxHeight: Int): Bitmap {
var width = this.width
var height = this.height
val aspectRatio: Float = width.toFloat() / height.toFloat()
if (width > height) {
width = maxWidth
height = (width / aspectRatio).toInt()
} else {
height = maxHeight
width = (height * aspectRatio).toInt()
require(maxWidth > 0 && maxHeight > 0) {
"Bitmap bounds must be positive"
}
return Bitmap.createScaledBitmap(this, width, height, true)
if (width <= maxWidth && height <= maxHeight) {
return this
}
val scale = minOf(
maxWidth.toFloat() / width.toFloat(),
maxHeight.toFloat() / height.toFloat(),
)
val targetWidth = (width * scale).roundToInt().coerceAtLeast(1)
val targetHeight = (height * scale).roundToInt().coerceAtLeast(1)
return Bitmap.createScaledBitmap(this, targetWidth, targetHeight, true)
}
fun Bitmap.toWebPBytes(): ByteArray {
fun Bitmap.toWebPBytes(
lossless: Boolean = true,
quality: Int = 100,
): ByteArray {
val stream = ByteArrayOutputStream()
val compressFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Bitmap.CompressFormat.WEBP_LOSSLESS
if (lossless) {
Bitmap.CompressFormat.WEBP_LOSSLESS
} else {
Bitmap.CompressFormat.WEBP_LOSSY
}
} else {
@Suppress("DEPRECATION")
Bitmap.CompressFormat.WEBP
}
compress(compressFormat, 100, stream)
compress(compressFormat, quality.coerceIn(0, 100), stream)
return stream.toByteArray()
}
}
@@ -19,6 +19,15 @@ import eu.weblibre.flutter_mozilla_components.pigeons.ImageSrcHitResult
import eu.weblibre.flutter_mozilla_components.pigeons.PhoneHitResult
import eu.weblibre.flutter_mozilla_components.pigeons.UnknownHitResult
import eu.weblibre.flutter_mozilla_components.pigeons.VideoHitResult
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import mozilla.components.browser.state.action.BrowserAction
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.LastAccessAction
@@ -44,6 +53,53 @@ class FlutterEventMiddleware(private val flutterEvents: GeckoStateEvents) : Midd
private val components by lazy {
requireNotNull(GlobalComponents.components) { "Components not initialized" }
}
/**
* Thumbnail scaling and WebP encoding are CPU-heavy and this middleware is
* normally invoked on the browser/UI dispatch path. Keep that work off the
* frame-critical thread and serialize it so periodic captures cannot build
* up a queue of competing bitmap encoders.
*/
private val thumbnailEncodingScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
private val thumbnailEncodingMutex = Mutex()
private var thumbnailEncodingJob: Job? = null
private fun forwardThumbnail(action: ContentAction.UpdateThumbnailAction) {
// Only the newest selected-tab preview is useful. Cancellation does not
// interrupt Bitmap.compress itself, so the mutex also prevents a newer
// request from starting a second encoder before the old one unwinds.
thumbnailEncodingJob?.cancel()
thumbnailEncodingJob = thumbnailEncodingScope.launch {
thumbnailEncodingMutex.withLock {
if (!isActive) return@withLock
val resized = action.thumbnail.resize(maxWidth = 720, maxHeight = 720)
try {
// Thumbnails are displayed at a few hundred logical pixels;
// lossless 1280x800 WebP added CPU and channel traffic with
// no visible benefit.
val bytes = resized.toWebPBytes(lossless = false, quality = 82)
if (!isActive) return@withLock
runOnUiThread {
flutterEvents.onThumbnailChange(
EventSequence.next(),
action.sessionId,
bytes,
) { _ -> }
}
} catch (error: CancellationException) {
throw error
} catch (error: Exception) {
Log.e("FlutterEventMiddleware", "Failed to encode thumbnail", error)
} finally {
if (resized !== action.thumbnail && !resized.isRecycled) {
resized.recycle()
}
}
}
}
}
@Suppress("ComplexMethod")
override fun invoke(
@@ -53,12 +109,7 @@ class FlutterEventMiddleware(private val flutterEvents: GeckoStateEvents) : Midd
) {
when (action) {
is ContentAction.UpdateThumbnailAction -> {
val resized = action.thumbnail.resize(maxWidth = 1280, maxHeight = 800);
val bytes = resized.toWebPBytes()
runOnUiThread {
flutterEvents.onThumbnailChange(EventSequence.next(), action.sessionId, bytes) { _ -> }
}
forwardThumbnail(action)
}
//UpdateReaderConnectRequiredAction seems to be the only event that is called predictable
//after a hot reload
+4 -1
View File
@@ -111,5 +111,8 @@ melos:
run: |
set -e
cd apps/weblibre
flutter build apk --release --flavor pixel10 --target-platform android-arm64 --no-tree-shake-icons
flutter build apk --release --flavor pixel10 --target-platform android-arm64 --split-per-abi --no-tree-shake-icons
arm64_apk="$(find build/app/outputs/flutter-apk -maxdepth 1 -type f -name '*pixel10*' -name '*arm64-v8a*' -name '*release.apk' -print -quit)"
test -n "$arm64_apk"
mv "$arm64_apk" build/app/outputs/flutter-apk/app-pixel10-release.apk
../../scripts/verify-pixel10-apk.sh build/app/outputs/flutter-apk/app-pixel10-release.apk
+2
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import sqlite3