diff --git a/.github/scripts/set-tauri-version.mjs b/.github/scripts/set-tauri-version.mjs index 439d4ed37..f4d628c01 100644 --- a/.github/scripts/set-tauri-version.mjs +++ b/.github/scripts/set-tauri-version.mjs @@ -24,9 +24,6 @@ if (updaterEndpoint && !updaterEndpoint.startsWith('https://')) { const file = 'src-tauri/tauri.conf.json'; const config = JSON.parse(readFileSync(file, 'utf8')); config.version = version; -if (version.includes('nightly')) { - config.productName = 'Sable Nightly'; -} if (updaterEndpoint) { config.plugins.updater.endpoints = [updaterEndpoint]; } diff --git a/.github/workflows/tauri-build.yml b/.github/workflows/tauri-build.yml index 29c89bf96..48c429698 100644 --- a/.github/workflows/tauri-build.yml +++ b/.github/workflows/tauri-build.yml @@ -119,14 +119,17 @@ jobs: include: - name: macOS platform: macos-latest + asset-platform: macos-universal rust-targets: aarch64-apple-darwin,x86_64-apple-darwin args: --target universal-apple-darwin - name: Windows platform: windows-latest + asset-platform: windows-x86_64 rust-targets: '' args: '' - name: Linux (CEF) platform: ubuntu-22.04 + asset-platform: linux-x86_64 rust-targets: '' cef: true env: @@ -185,8 +188,7 @@ jobs: run: node .github/scripts/set-tauri-version.mjs "$VERSION" "$UPDATER_ENDPOINT" # --- macOS / Windows: standard wry build via tauri-action --- - - name: Configure desktop bundles - if: ${{ !matrix.cef }} + - name: Configure desktop build shell: bash env: IS_NIGHTLY: ${{ needs.setup-release.outputs.nightly }} @@ -199,6 +201,9 @@ jobs: if [ "$IS_NIGHTLY" = "true" ] && [ "$MATRIX_NAME" = "Windows" ]; then ARGS="$ARGS --bundles nsis" fi + if [ "$IS_NIGHTLY" = "true" ]; then + ARGS="$ARGS --config src-tauri/tauri.nightly.conf.json" + fi echo "TAURI_BUILD_ARGS=${ARGS# }" >> "$GITHUB_ENV" - name: Build desktop bundles @@ -208,6 +213,30 @@ jobs: with: args: ${{ matrix.args }} ${{ env.TAURI_BUILD_ARGS }} + - name: Normalize desktop artifact names + if: ${{ !matrix.cef }} + shell: bash + env: + ASSET_PLATFORM: ${{ matrix.asset-platform }} + run: | + find src-tauri/target/release/bundle -type f -print0 \ + | while IFS= read -r -d '' path; do + case "$path" in + *.app.tar.gz.sig) suffix='.app.tar.gz.sig' ;; + *.app.tar.gz) suffix='.app.tar.gz' ;; + *.nsis.zip.sig) suffix='.nsis.zip.sig' ;; + *.nsis.zip) suffix='.nsis.zip' ;; + *-setup.exe.sig) suffix='-setup.exe.sig' ;; + *-setup.exe) suffix='-setup.exe' ;; + *.msi.sig) suffix='.msi.sig' ;; + *.msi) suffix='.msi' ;; + *.dmg) suffix='.dmg' ;; + *) continue ;; + esac + target="$(dirname "$path")/Sable-${VERSION}-${ASSET_PLATFORM}${suffix}" + [ "$path" = "$target" ] || mv "$path" "$target" + done + - name: Attest Windows bundles if: ${{ matrix.name == 'Windows' }} uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 @@ -223,24 +252,18 @@ jobs: shell: bash env: GH_TOKEN: ${{ github.token }} - ARTIFACTS: ${{ steps.tauri.outputs.artifactPaths }} run: | - echo "$ARTIFACTS" | jq -r '.[]' | while read -r path; do - path="${path%$'\r'}" - [ -n "$path" ] || continue - if [ -d "$path" ]; then - echo "Skipping directory artifact: $path" - continue - fi - echo "Uploading $path" - gh release upload "$TAG" "$path" --clobber + find src-tauri/target/release/bundle -type f -name 'Sable-*' -print0 \ + | while IFS= read -r -d '' path; do + echo "Uploading $path" + gh release upload "$TAG" "$path" --clobber done # --- Linux: CEF runtime, packaged as deb / rpm / AppImage --- - name: Build CEF binary if: matrix.cef shell: bash - run: pnpm tauri:cef build + run: pnpm tauri:cef build $TAURI_BUILD_ARGS - name: Build native packages if: matrix.cef @@ -251,7 +274,7 @@ jobs: if: ${{ matrix.cef && env.TAURI_SIGNING_PRIVATE_KEY != '' }} shell: bash run: | - for f in src-tauri/target/release/bundle/appimage/Sable_*_amd64.AppImage; do + for f in src-tauri/target/release/bundle/appimage/Sable-*-linux-x86_64.AppImage; do [ -e "$f" ] || continue pnpm tauri signer sign "$f" done @@ -273,9 +296,10 @@ jobs: GH_TOKEN: ${{ github.token }} run: | BUNDLE="src-tauri/target/release/bundle" - for f in "$BUNDLE"/deb/sable_*.deb "$BUNDLE"/rpm/sable-*.rpm \ - "$BUNDLE"/appimage/Sable_*_amd64.AppImage \ - "$BUNDLE"/appimage/Sable_*_amd64.AppImage.sig; do + for f in "$BUNDLE"/deb/Sable-*-linux-x86_64.deb \ + "$BUNDLE"/rpm/Sable-*-linux-x86_64.rpm \ + "$BUNDLE"/appimage/Sable-*-linux-x86_64.AppImage \ + "$BUNDLE"/appimage/Sable-*-linux-x86_64.AppImage.sig; do [ -e "$f" ] || continue echo "Uploading $f" gh release upload "$TAG" "$f" --clobber @@ -351,7 +375,21 @@ jobs: - name: Build Android bundles shell: bash - run: pnpm tauri android build --apk --aab + env: + IS_NIGHTLY: ${{ needs.setup-release.outputs.nightly }} + run: | + ARGS=() + if [ "$IS_NIGHTLY" = "true" ]; then + ARGS+=(--config src-tauri/tauri.nightly.conf.json) + fi + pnpm tauri android build --apk --aab "${ARGS[@]}" + OUT='src-tauri/gen/android/app/build/outputs' + APK=$(find "$OUT/apk/universal/release" -name '*.apk' -type f | head -1) + AAB=$(find "$OUT/bundle/universalRelease" -name '*.aab' -type f | head -1) + [ -n "$APK" ] || { echo 'APK not found' >&2; exit 1; } + [ -n "$AAB" ] || { echo 'AAB not found' >&2; exit 1; } + mv "$APK" "$OUT/apk/universal/release/Sable-${VERSION}-android-universal.apk" + mv "$AAB" "$OUT/bundle/universalRelease/Sable-${VERSION}-android-universal.aab" - name: Attest Android bundles uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 @@ -425,10 +463,19 @@ jobs: - name: Build unsigned IPA id: ipa shell: bash + env: + IS_NIGHTLY: ${{ needs.setup-release.outputs.nightly }} run: | - pnpm tauri ios build --no-sign --ci + ARGS=() + if [ "$IS_NIGHTLY" = "true" ]; then + ARGS+=(--config src-tauri/tauri.nightly.conf.json) + fi + pnpm tauri ios build --no-sign --ci "${ARGS[@]}" IPA=$(find src-tauri/gen/apple/build -name '*.ipa' -type f | head -1) [ -n "$IPA" ] || { echo "IPA not found"; ls -R src-tauri/gen/apple/build 2>/dev/null || true; exit 1; } + NORMALIZED_IPA="$(dirname "$IPA")/Sable-${VERSION}-ios-arm64.ipa" + [ "$IPA" = "$NORMALIZED_IPA" ] || mv "$IPA" "$NORMALIZED_IPA" + IPA="$NORMALIZED_IPA" echo "size=$(stat -f%z "$IPA")" >> "$GITHUB_OUTPUT" echo "path=$IPA" >> "$GITHUB_OUTPUT" echo "name=$(basename "$IPA")" >> "$GITHUB_OUTPUT" diff --git a/scripts/cef-package.sh b/scripts/cef-package.sh index deee504e4..aeff0fd11 100755 --- a/scripts/cef-package.sh +++ b/scripts/cef-package.sh @@ -25,12 +25,15 @@ WORK="$STAGE/cef-pkg" if [ -x "$STAGE/Sable Nightly" ]; then BIN_NAME="Sable Nightly" + DISPLAY_NAME="Sable Nightly" elif [ -x "$STAGE/Sable" ]; then BIN_NAME="Sable" + DISPLAY_NAME="Sable" elif [ -x "$STAGE/sable" ]; then BIN_NAME="sable" + DISPLAY_NAME="Sable" else - echo "missing $STAGE/Sable or sable; build it first (pnpm tauri:cef build)" >&2 + echo "missing $STAGE/Sable Nightly, Sable, or sable; build it first (pnpm tauri:cef build)" >&2 exit 1 fi @@ -69,10 +72,10 @@ stage_appindicator() { } write_desktop() { - cat > "$1" <<'EOF' + cat > "$1" < diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index 2c44df20b..bbf9087cc 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -938,9 +938,7 @@ function MessageInternal( style={{ width: '100%', WebkitTouchCallout: 'none', - WebkitUserSelect: 'none', WebkitTapHighlightColor: 'transparent', - userSelect: 'none', }} onContextMenu={handleContextMenu} onTouchStart={onTouchStart} diff --git a/src/app/hooks/useMobileLongPress.test.tsx b/src/app/hooks/useMobileLongPress.test.tsx new file mode 100644 index 000000000..9ea187b07 --- /dev/null +++ b/src/app/hooks/useMobileLongPress.test.tsx @@ -0,0 +1,67 @@ +import { act, renderHook } from '@testing-library/react'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { useMobileLongPress } from './useMobileLongPress'; + +const touchEvent = (clientX: number, clientY: number) => + ({ touches: [{ clientX, clientY }] }) as unknown as React.TouchEvent; + +describe('useMobileLongPress', () => { + afterEach(() => { + vi.useRealTimers(); + }); + + it('fires after the hold delay', () => { + vi.useFakeTimers(); + const callback = vi.fn<() => void>(); + const { result } = renderHook(() => useMobileLongPress(callback)); + + act(() => result.current.onTouchStart(touchEvent(20, 30))); + expect(result.current.isPressing).toBe(true); + + act(() => vi.advanceTimersByTime(500)); + expect(callback).toHaveBeenCalledOnce(); + expect(result.current.isPressing).toBe(false); + expect(result.current.firedRef.current).toBe(true); + }); + + it('allows small finger movement during a hold', () => { + vi.useFakeTimers(); + const callback = vi.fn<() => void>(); + const { result } = renderHook(() => useMobileLongPress(callback)); + + act(() => { + result.current.onTouchStart(touchEvent(20, 30)); + result.current.onTouchMove(touchEvent(32, 42)); + vi.advanceTimersByTime(500); + }); + + expect(callback).toHaveBeenCalledOnce(); + }); + + it('cancels when the touch becomes a scroll', () => { + vi.useFakeTimers(); + const callback = vi.fn<() => void>(); + const { result } = renderHook(() => useMobileLongPress(callback)); + + act(() => { + result.current.onTouchStart(touchEvent(20, 30)); + result.current.onTouchMove(touchEvent(20, 60)); + vi.advanceTimersByTime(500); + }); + + expect(callback).not.toHaveBeenCalled(); + expect(result.current.isPressing).toBe(false); + }); + + it('cancels a pending hold when unmounted', () => { + vi.useFakeTimers(); + const callback = vi.fn<() => void>(); + const { result, unmount } = renderHook(() => useMobileLongPress(callback)); + + act(() => result.current.onTouchStart(touchEvent(20, 30))); + unmount(); + act(() => vi.advanceTimersByTime(500)); + + expect(callback).not.toHaveBeenCalled(); + }); +}); diff --git a/src/app/hooks/useMobileLongPress.ts b/src/app/hooks/useMobileLongPress.ts index a0b1463e9..c5299677f 100644 --- a/src/app/hooks/useMobileLongPress.ts +++ b/src/app/hooks/useMobileLongPress.ts @@ -1,12 +1,17 @@ -import { useRef, useCallback, useState } from 'react'; +import { useRef, useCallback, useEffect, useState } from 'react'; + +const MOVE_TOLERANCE = 16; export function useMobileLongPress(callback: () => void, delay = 500) { const timerRef = useRef | null>(null); + const callbackRef = useRef(callback); const firedRef = useRef(false); const [isPressing, setIsPressing] = useState(false); const startY = useRef(null); const startX = useRef(null); + callbackRef.current = callback; + const clear = useCallback(() => { if (timerRef.current !== null) { clearTimeout(timerRef.current); @@ -19,22 +24,32 @@ export function useMobileLongPress(callback: () => void, delay = 500) { startX.current = null; }, []); + useEffect( + () => () => { + if (timerRef.current !== null) clearTimeout(timerRef.current); + }, + [] + ); + const onTouchStart = useCallback( (e: React.TouchEvent | TouchEvent) => { + clear(); firedRef.current = false; + const touch = 'touches' in e && e.touches.length === 1 ? e.touches[0] : undefined; + if (!touch) return; + setIsPressing(true); - if ('touches' in e && e.touches[0]) { - startY.current = e.touches[0].clientY; - startX.current = e.touches[0].clientX; - } + startY.current = touch.clientY; + startX.current = touch.clientX; timerRef.current = setTimeout(() => { + timerRef.current = null; firedRef.current = true; - callback(); - setTimeout(() => setIsPressing(false), 300); + setIsPressing(false); + callbackRef.current(); }, delay); }, - [callback, delay] + [clear, delay] ); const onTouchEnd = useCallback(() => { @@ -55,7 +70,7 @@ export function useMobileLongPress(callback: () => void, delay = 500) { const diffY = Math.abs(e.touches[0].clientY - startY.current); const diffX = Math.abs(e.touches[0].clientX - startX.current); - if (diffY > 10 || diffX > 10) { + if (diffY > MOVE_TOLERANCE || diffX > MOVE_TOLERANCE) { clear(); } },