Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polyfill-change-array-by-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Fix a crash on older WebViews that lack `toSorted`, `toReversed`, and `with`.
5 changes: 5 additions & 0 deletions .changeset/shrink-foss-android-apk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Shrink the Android APK: strip the native library, drop bundled source maps, and split the F-Droid build per ABI.
15 changes: 9 additions & 6 deletions .github/workflows/tauri-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ jobs:
echo "storeFile=$RUNNER_TEMP/keystore.jks" >> keystore.properties

# Must run before the Google build: they share one Gradle output directory.
- name: Build FOSS Android APK
- name: Build FOSS Android APKs
if: ${{ env.IS_RELEASE == 'true' }}
shell: bash
env:
Expand All @@ -335,13 +335,16 @@ jobs:
# tauri-build validates every file in capabilities/, so the geolocation
# permissions must be absent, not just unreferenced.
rm src-tauri/capabilities/geolocation.json
pnpm tauri android build --apk --target aarch64 armv7 -- --no-default-features --features wry,matrix-crypto
pnpm tauri android build --apk --split-per-abi --target aarch64 armv7 -- --no-default-features --features wry,matrix-crypto
git checkout -- src-tauri/capabilities/geolocation.json
OUT='src-tauri/gen/android/app/build/outputs/apk/universal/release'
APK=$(find "$OUT" -name '*.apk' -type f | head -1)
[ -n "$APK" ] || { echo 'FOSS APK not found' >&2; exit 1; }
mkdir -p android-artifacts
mv "$APK" "android-artifacts/Sable-${VERSION}-android-universal-foss.apk"
for pair in 'arm64:arm64' 'arm:armv7'; do
FLAVOR=${pair%%:*}
ABI=${pair##*:}
APK=$(find "src-tauri/gen/android/app/build/outputs/apk/$FLAVOR/release" -name '*.apk' -type f | head -1)
[ -n "$APK" ] || { echo "FOSS $ABI APK not found" >&2; exit 1; }
mv "$APK" "android-artifacts/Sable-${VERSION}-android-${ABI}-foss.apk"
done

- name: Build Android bundles
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,8 @@ tauri-typegen = { git = "https://github.com/SableClient/tauri-typegen", branch =
# tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "feat/cef" }
# tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "feat/cef" }
# tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "feat/cef" }

[profile.release]
strip = "symbols"
lto = "thin"
codegen-units = 1
3 changes: 3 additions & 0 deletions src-tauri/gen/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ android {
getByName("release") {
signingConfig = signingConfigs.getByName("release")
isMinifyEnabled = true
packaging {
jniLibs.useLegacyPackaging = true
}
proguardFiles(
*fileTree(".") { include("**/*.pro") }
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
Expand Down
45 changes: 45 additions & 0 deletions src/arrayCompat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { afterEach, describe, expect, it } from 'vitest';
import { installChangeArrayByCopyPolyfill } from './arrayCompat';

const proto = Array.prototype as {
toSorted?: unknown;
toReversed?: unknown;
with?: unknown;
};
const originals = {
toSorted: proto.toSorted,
toReversed: proto.toReversed,
with: proto.with,
};

afterEach(() => {
proto.toSorted = originals.toSorted;
proto.toReversed = originals.toReversed;
proto.with = originals.with;
});

describe('installChangeArrayByCopyPolyfill', () => {
it('installs the methods when the runtime does not provide them', () => {
Reflect.deleteProperty(proto, 'toSorted');
Reflect.deleteProperty(proto, 'toReversed');
Reflect.deleteProperty(proto, 'with');

installChangeArrayByCopyPolyfill();

const source = [3, 1, 2];
expect(source.toSorted((a, b) => a - b)).toEqual([1, 2, 3]);
expect(source.toReversed()).toEqual([2, 1, 3]);
// oxlint-disable-next-line unicorn/no-confusing-array-with
expect(source.with(-1, 9)).toEqual([3, 1, 9]);
expect(source).toEqual([3, 1, 2]);
expect(() => source.with(3, 9)).toThrow(RangeError);
});

it('installs them as non-enumerable', () => {
Reflect.deleteProperty(proto, 'toSorted');

installChangeArrayByCopyPolyfill();

expect(Object.keys([1, 2])).toEqual(['0', '1']);
});
});
40 changes: 40 additions & 0 deletions src/arrayCompat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
type ChangeArrayByCopyMethods = {
toSorted?: unknown;
toReversed?: unknown;
with?: unknown;
};

function define(name: string, value: unknown): void {
// oxlint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, name, { value, writable: true, configurable: true });
}

export function installChangeArrayByCopyPolyfill(): void {
const proto = Array.prototype as ChangeArrayByCopyMethods;

if (!proto.toSorted) {
define('toSorted', function toSorted<T>(this: T[], compare?: (a: T, b: T) => number): T[] {
// oxlint-disable-next-line unicorn/no-array-sort
return Array.prototype.slice.call(this).sort(compare);
});
}

if (!proto.toReversed) {
define('toReversed', function toReversed<T>(this: T[]): T[] {
// oxlint-disable-next-line unicorn/no-array-reverse
return Array.prototype.slice.call(this).reverse();
});
}

if (!proto.with) {
define('with', function withAt<T>(this: T[], index: number, value: T): T[] {
const copy = Array.prototype.slice.call(this) as T[];
const target = index < 0 ? copy.length + index : index;
if (target < 0 || target >= copy.length) throw new RangeError(`Invalid index : ${index}`);
copy[target] = value;
return copy;
});
}
}

installChangeArrayByCopyPolyfill();
1 change: 1 addition & 0 deletions src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* - VITE_APP_VERSION: Release version for tracking
*/
/* oxlint-disable no-console */
import './arrayCompat';
import './promiseCompat';
import * as Sentry from '@sentry/react';
import React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const callEmbeddedDir = 'node_modules/@sableclient/sable-call-embedded/dist';
const copyFiles = {
targets: [
{
src: callEmbeddedDir,
src: [callEmbeddedDir, `!${callEmbeddedDir}/**/*.map`],
dest: 'public/element-call',
rename: { stripBase: callEmbeddedDir.split('/').length },
},
Expand Down
Loading