diff --git a/.forgejo/workflows/deploy-dev.yml b/.forgejo/workflows/deploy-dev.yml index 26053ff..eca2545 100644 --- a/.forgejo/workflows/deploy-dev.yml +++ b/.forgejo/workflows/deploy-dev.yml @@ -4,20 +4,31 @@ on: - dev jobs: - deploy: + build-web: runs-on: docker - steps: - name: Check out repo uses: https://data.forgejo.org/actions/checkout@v4 - - name: Setup Bun + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v30 + + - name: Install Bun uses: oven-sh/setup-bun@v2 - name: Install dependencies run: bun install --frozen-lockfile - - name: Build + - name: Copy licenses + run: bun run copy-licenses + + - name: Build packages + run: bun run build:packages + + - name: Build web run: bun run build:web - name: Install rsync @@ -25,3 +36,204 @@ jobs: - name: Deploy run: rsync -a --delete apps/web/dist/ /var/lib/www/tensamin-web-dev/ + + build-mobile: + runs-on: docker + steps: + - name: Check out repo + uses: https://data.forgejo.org/actions/checkout@v4 + + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v30 + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Copy licenses + run: bun run copy-licenses + + - name: Build packages + run: bun run build:packages + + - name: Setup Android Keystore + env: + KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} + KEYSTORE_PROPERTIES: ${{ secrets.ANDROID_KEYSTORE_PROPERTIES }} + run: | + bun -e "require('fs').writeFileSync('keystore.jks', Buffer.from(process.env.KEYSTORE_BASE64.replace(/\s+/g, ''), 'base64'))" + bun -e "const content = process.env.KEYSTORE_PROPERTIES.replace(/\\n/g, '\n').replace(/\r/g, '').split('\n').map(l => l.trim()).filter(l => l).join('\n'); require('fs').writeFileSync('keystore.properties', content)" + + - name: Build mobile + run: bun run build:mobile + + - name: Upload mobile artifact + uses: https://data.forgejo.org/actions/upload-artifact@v3 + with: + name: mobile-apk + path: apps/tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk + + build-desktop: + runs-on: docker + steps: + - name: Check out repo + uses: https://data.forgejo.org/actions/checkout@v4 + + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v30 + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Copy licenses + run: bun run copy-licenses + + - name: Build packages + run: bun run build:packages + + - name: Build desktop + run: bun run build:desktop + + - name: Upload desktop artifacts + uses: https://data.forgejo.org/actions/upload-artifact@v3 + with: + name: desktop-bundles + path: apps/tauri/src-tauri/target/release/bundle/ + + release: + runs-on: docker + needs: [build-web, build-mobile, build-desktop] + steps: + - name: Check out repo + uses: https://data.forgejo.org/actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Download mobile artifact + uses: https://data.forgejo.org/actions/download-artifact@v3 + with: + name: mobile-apk + path: apps/tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/ + + - name: Download desktop artifacts + uses: https://data.forgejo.org/actions/download-artifact@v3 + with: + name: desktop-bundles + path: apps/tauri/src-tauri/target/release/bundle/ + + - name: Copy releases + run: bun --bun run copy-releases + + - name: Read version and hash + id: version + run: | + VERSION="$(node -p "require('./package.json').version")" + SHORT_SHA="$(git rev-parse --short HEAD)" + echo "version=$VERSION" >> "$FORGEJO_OUTPUT" + echo "short_sha=$SHORT_SHA" >> "$FORGEJO_OUTPUT" + echo "tag=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT" + echo "title=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT" + + - name: Create pre-release and upload files + env: + TOKEN: ${{ forgejo.token }} + API: ${{ forgejo.api_url }} + REPO: ${{ forgejo.repository }} + SHA: ${{ forgejo.sha }} + TAG: ${{ steps.version.outputs.tag }} + TITLE: ${{ steps.version.outputs.title }} + run: | + set -eu + + test -d releases + find releases -type f | grep -q . + + LATEST_PROD_TAG="$(git tag --sort=-v:refname | head -n 1 || true)" + + if [ -n "$LATEST_PROD_TAG" ]; then + RAW_LOG="$(git log "$LATEST_PROD_TAG"..HEAD --pretty=format:'- %s')" + else + RAW_LOG="$(git log --pretty=format:'- %s')" + fi + + export RAW_LOG LATEST_PROD_TAG API REPO TAG + BODY="$(node -e ' + const raw = process.env.RAW_LOG; + const lines = raw.split("\n"); + const commits = []; + for (const line of lines) { + const msg = line.replace(/^- /, ""); + const parts = msg.split(/(?=\([^)]+\):)/).filter(Boolean).map(s => s.trim()).filter(s => s); + for (const part of parts) { + commits.push(part); + } + } + const priority = { "(feat):": 1, "(fix):": 2, "(qol):": 3 }; + commits.sort((a, b) => { + const tagA = a.match(/^(\([^)]+\):)/)?.[1] || ""; + const tagB = b.match(/^(\([^)]+\):)/)?.[1] || ""; + return (priority[tagA] || 99) - (priority[tagB] || 99); + }); + const log = commits.map(c => "- " + c).join("\n"); + const latestTag = process.env.LATEST_PROD_TAG; + if (latestTag) { + const serverUrl = process.env.API.replace(/\/api\/v1.*/, ""); + const compareUrl = serverUrl + "/" + process.env.REPO + "/compare/" + latestTag + "..." + process.env.TAG; + console.log(log + "\n\n[View changes](" + compareUrl + ")"); + } else { + console.log(log); + } + ')" + + HTTP_STATUS=$(curl -s -w "%{http_code}" -o release_out.json -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/tags/$TAG") + + if [ "$HTTP_STATUS" = "200" ]; then + echo "Release $TAG already exists." + RELEASE_ID="$(jq -r .id release_out.json)" + else + echo "Creating new pre-release for $TAG" + RELEASE_JSON="$(curl -f -sS -X POST "$API/repos/$REPO/releases" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg tag "$TAG" \ + --arg name "$TITLE" \ + --arg body "$BODY" \ + --arg target "$SHA" \ + '{ + tag_name: $tag, + name: $name, + body: $body, + target_commitish: $target, + draft: false, + prerelease: true + }')")" + RELEASE_ID="$(echo "$RELEASE_JSON" | jq -r .id)" + fi + + find releases -type f -print0 | while IFS= read -r -d '' file; do + name="$(basename "$file")" + curl -fsS -X POST "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$name" \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@$file" + done diff --git a/.forgejo/workflows/deploy-prod.yml b/.forgejo/workflows/deploy-prod.yml index 1df5b60..3463fca 100644 --- a/.forgejo/workflows/deploy-prod.yml +++ b/.forgejo/workflows/deploy-prod.yml @@ -4,9 +4,8 @@ on: - main jobs: - deploy: + build-web: runs-on: docker - steps: - name: Check out repo uses: https://data.forgejo.org/actions/checkout@v4 @@ -23,16 +22,14 @@ jobs: - name: Install dependencies run: bun install --frozen-lockfile - - name: Setup Android Keystore - env: - KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} - KEYSTORE_PROPERTIES: ${{ secrets.ANDROID_KEYSTORE_PROPERTIES }} - run: | - bun -e "require('fs').writeFileSync('keystore.jks', Buffer.from(process.env.KEYSTORE_BASE64.replace(/\s+/g, ''), 'base64'))" - bun -e "const content = process.env.KEYSTORE_PROPERTIES.replace(/\\\\n/g, '\n').replace(/\\r/g, '').split('\n').map(l => l.trim()).filter(l => l).join('\n'); require('fs').writeFileSync('keystore.properties', content)" + - name: Copy licenses + run: bun run copy-licenses - - name: Build - run: bun run build:apps + - name: Build packages + run: bun run build:packages + + - name: Build web + run: bun run build:web - name: Install rsync run: apt-get update && apt-get install -y rsync @@ -40,12 +37,117 @@ jobs: - name: Deploy run: rsync -a --delete apps/web/dist/ /var/lib/www/tensamin-web-prod/ + build-mobile: + runs-on: docker + steps: + - name: Check out repo + uses: https://data.forgejo.org/actions/checkout@v4 + + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v30 + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Copy licenses + run: bun run copy-licenses + + - name: Build packages + run: bun run build:packages + + - name: Setup Android Keystore + env: + KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} + KEYSTORE_PROPERTIES: ${{ secrets.ANDROID_KEYSTORE_PROPERTIES }} + run: | + bun -e "require('fs').writeFileSync('keystore.jks', Buffer.from(process.env.KEYSTORE_BASE64.replace(/\s+/g, ''), 'base64'))" + bun -e "const content = process.env.KEYSTORE_PROPERTIES.replace(/\\n/g, '\n').replace(/\r/g, '').split('\n').map(l => l.trim()).filter(l => l).join('\n'); require('fs').writeFileSync('keystore.properties', content)" + + - name: Build mobile + run: bun run build:mobile + + - name: Upload mobile artifact + uses: https://data.forgejo.org/actions/upload-artifact@v3 + with: + name: mobile-apk + path: apps/tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk + + build-desktop: + runs-on: docker + steps: + - name: Check out repo + uses: https://data.forgejo.org/actions/checkout@v4 + + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v30 + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Copy licenses + run: bun run copy-licenses + + - name: Build packages + run: bun run build:packages + + - name: Build desktop + run: bun run build:desktop + + - name: Upload desktop artifacts + uses: https://data.forgejo.org/actions/upload-artifact@v3 + with: + name: desktop-bundles + path: apps/tauri/src-tauri/target/release/bundle/ + + release: + runs-on: docker + needs: [build-web, build-mobile, build-desktop] + steps: + - name: Check out repo + uses: https://data.forgejo.org/actions/checkout@v4 + + - name: Install Packages + run: apt-get update && apt-get install -y sudo curl jq + + - name: Install Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Download mobile artifact + uses: https://data.forgejo.org/actions/download-artifact@v3 + with: + name: mobile-apk + path: apps/tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/ + + - name: Download desktop artifacts + uses: https://data.forgejo.org/actions/download-artifact@v3 + with: + name: desktop-bundles + path: apps/tauri/src-tauri/target/release/bundle/ + + - name: Copy releases + run: bun --bun run copy-releases + - name: Read version id: version run: | VERSION="$(node -p "require('./package.json').version")" echo "version=$VERSION" >> "$FORGEJO_OUTPUT" - echo "tag=v$VERSION" >> "$FORGEJO_OUTPUT" + echo "tag=$VERSION" >> "$FORGEJO_OUTPUT" - name: Create release and upload files env: @@ -54,39 +156,40 @@ jobs: REPO: ${{ forgejo.repository }} SHA: ${{ forgejo.sha }} TAG: ${{ steps.version.outputs.tag }} - VERSION: ${{ steps.version.outputs.version }} run: | set -eu test -d releases find releases -type f | grep -q . + COMMIT_MSG="$(git log -1 --pretty=%B | sed 's/$/ /')" + HTTP_STATUS=$(curl -s -w "%{http_code}" -o release_out.json -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/tags/$TAG") if [ "$HTTP_STATUS" = "200" ]; then echo "Release $TAG already exists." - RELEASE_ID="$(jq -r .id release_out.json)" - else - echo "Creating new release for $TAG" - RELEASE_JSON="$(curl -f -sS -X POST "$API/repos/$REPO/releases" \ - -H "Authorization: token $TOKEN" \ - -H "Content-Type: application/json" \ - -d "$(jq -n \ - --arg tag "$TAG" \ - --arg name "$TAG" \ - --arg body "Release $VERSION" \ - --arg target "$SHA" \ - '{ - tag_name: $tag, - name: $name, - body: $body, - target_commitish: $target, - draft: false, - prerelease: false - }')")" - RELEASE_ID="$(echo "$RELEASE_JSON" | jq -r .id)" + exit 0 fi + echo "Creating new release for $TAG" + RELEASE_JSON="$(curl -f -sS -X POST "$API/repos/$REPO/releases" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg tag "$TAG" \ + --arg name "$TAG" \ + --arg body "$COMMIT_MSG" \ + --arg target "$SHA" \ + '{ + tag_name: $tag, + name: $name, + body: $body, + target_commitish: $target, + draft: false, + prerelease: false + }')")" + RELEASE_ID="$(echo "$RELEASE_JSON" | jq -r .id)" + find releases -type f -print0 | while IFS= read -r -d '' file; do name="$(basename "$file")" curl -fsS -X POST "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$name" \ diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 5bb82f5..34ff437 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,7 +2,6 @@ "recommendations": [ "tauri-apps.tauri-vscode", "rust-lang.rust-analyzer", - "bradlc.vscode-tailwindcss", - "antfu.vite" + "bradlc.vscode-tailwindcss" ] } diff --git a/apps/tauri/android.png b/apps/tauri/android.png new file mode 100644 index 0000000..f77258e Binary files /dev/null and b/apps/tauri/android.png differ diff --git a/apps/tauri/background.png b/apps/tauri/background.png new file mode 100644 index 0000000..e6157bd Binary files /dev/null and b/apps/tauri/background.png differ diff --git a/apps/tauri/logo.json b/apps/tauri/logo.json new file mode 100644 index 0000000..9cd2fcb --- /dev/null +++ b/apps/tauri/logo.json @@ -0,0 +1,8 @@ +{ + "default": "./logo.svg", + + "android_fg": "./android.png", + "android_bg": "./background.png", + "android_fg_scale": 100, + "android_monochrome": "./monochrome.png" +} \ No newline at end of file diff --git a/apps/tauri/logo.png b/apps/tauri/logo.png deleted file mode 100644 index 7cb66f6..0000000 Binary files a/apps/tauri/logo.png and /dev/null differ diff --git a/apps/tauri/logo.svg b/apps/tauri/logo.svg new file mode 100644 index 0000000..e40aa0f --- /dev/null +++ b/apps/tauri/logo.svg @@ -0,0 +1,237 @@ + + + + diff --git a/apps/tauri/monochrome.png b/apps/tauri/monochrome.png new file mode 100644 index 0000000..04d3abd Binary files /dev/null and b/apps/tauri/monochrome.png differ diff --git a/apps/tauri/package.json b/apps/tauri/package.json index db9894e..a89a309 100644 --- a/apps/tauri/package.json +++ b/apps/tauri/package.json @@ -25,12 +25,12 @@ "dev:mobile:raw": "tauri android dev", "build:mobile:raw": "tauri android build", "dev:mobile": "if command -v nix >/dev/null 2>&1; then nix develop --command bun dev:mobile:raw; else bun dev:mobile:raw; fi", - "build:mobile": "if command -v nix >/dev/null 2>&1; then nix develop --command bun build:mobile:raw; else bun build:mobile:raw; fi", + "build:mobile": "bun run render-version.ts && if command -v nix >/dev/null 2>&1; then nix develop --command bun build:mobile:raw; else bun build:mobile:raw; fi && bun run render-version.ts --unrender", "dev:desktop:raw": "tauri dev", "build:desktop:raw": "tauri build", "dev:desktop": "if command -v nix >/dev/null 2>&1; then nix develop --command bun dev:desktop:raw; else bun dev:desktop:raw; fi", "build:desktop": "if command -v nix >/dev/null 2>&1; then nix develop --command bun build:desktop:raw; else bun build:desktop:raw; fi", - "gen-icons": "tauri icon ./logo.png", + "gen-icons": "tauri icon ./logo.json", "format": "bunx prettier --write .", "lint": "eslint src" }, @@ -46,6 +46,7 @@ "react-dom": "^19.2.0" }, "devDependencies": { - "@tauri-apps/cli": "^2" + "@tauri-apps/cli": "^2", + "@types/node": "^25.9.1" } } diff --git a/apps/tauri/render-version.ts b/apps/tauri/render-version.ts new file mode 100644 index 0000000..0bd3fca --- /dev/null +++ b/apps/tauri/render-version.ts @@ -0,0 +1,65 @@ +import fs from "fs"; +import path from "path"; + +// Config +const PLACEHOLDER_VERSION = "0.0.0"; + +const rootPackageJsonPath = path.resolve(__dirname, "../../package.json"); +const cargoTomlPath = path.resolve(__dirname, "./src-tauri/Cargo.toml"); +const tauriConfigPath = path.resolve(__dirname, "./src-tauri/tauri.conf.json"); + +// Args +const isUnrender = process.argv.includes("--unrender"); + +// Version Source +const packageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, "utf8")); + +const packageVersion: string = packageJson.version; + +if (!packageVersion && !isUnrender) { + throw new Error("No version found in package.json"); +} + +const targetVersion = isUnrender ? PLACEHOLDER_VERSION : packageVersion; + +// Helpers +function updateCargoToml(content: string): string { + const regex = /^version\s*=\s*".*"$/m; + + if (!regex.test(content)) { + throw new Error("Could not find version field in Cargo.toml"); + } + + return content.replace(regex, `version = "${targetVersion}"`); +} + +function updateTauriConfig(content: string): string { + const regex = /"version"\s*:\s*".*"/; + + if (!regex.test(content)) { + throw new Error("Could not find version field in tauri.conf.json"); + } + + return content.replace(regex, `"version": "${targetVersion}"`); +} + +// Update Cargo.toml +const cargoToml = fs.readFileSync(cargoTomlPath, "utf8"); + +const updatedCargoToml = updateCargoToml(cargoToml); + +fs.writeFileSync(cargoTomlPath, updatedCargoToml, "utf8"); + +// Update tauri.conf.json +const tauriConfig = fs.readFileSync(tauriConfigPath, "utf8"); + +const updatedTauriConfig = updateTauriConfig(tauriConfig); + +fs.writeFileSync(tauriConfigPath, updatedTauriConfig, "utf8"); + +// Finished +if (isUnrender) { + console.log(`Unrendered versions back to ${PLACEHOLDER_VERSION}`); +} else { + console.log(`Rendered version ${targetVersion}`); +} diff --git a/apps/tauri/src-tauri/Cargo.lock b/apps/tauri/src-tauri/Cargo.lock index e65d82e..77d465a 100644 --- a/apps/tauri/src-tauri/Cargo.lock +++ b/apps/tauri/src-tauri/Cargo.lock @@ -4838,7 +4838,7 @@ dependencies = [ [[package]] name = "tensamin" -version = "0.1.0" +version = "0.0.0" dependencies = [ "base64 0.22.1", "image 0.25.10", diff --git a/apps/tauri/src-tauri/Cargo.toml b/apps/tauri/src-tauri/Cargo.toml index 90b9504..c5b2b18 100644 --- a/apps/tauri/src-tauri/Cargo.toml +++ b/apps/tauri/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tensamin" -version = "0.1.0" +version = "0.0.0" description = "Privacy focused messanger" authors = ["methanium"] edition = "2021" diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index 2ffbf24..0343c28 100644 --- a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,5 +1,6 @@ - + + \ No newline at end of file diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index 6de2c44..fbd7184 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_background.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_background.png new file mode 100644 index 0000000..b038821 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_background.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png index c6da8ae..0eac8d0 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..b1a2c84 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png index c42517c..7b90201 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index 1d61eb2..10832d3 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_background.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_background.png new file mode 100644 index 0000000..5635294 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_background.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png index eceb132..b2a3603 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..b13236e Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png index be24593..f5fb52c 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 5aeb1dc..4a07614 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png new file mode 100644 index 0000000..16908ba Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png index cebe007..ac4b850 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..c929b14 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png index 1b7aa3d..7ed0607 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 14abb66..7aee207 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png new file mode 100644 index 0000000..15cf062 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png index a918033..6ab46b6 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..21f0293 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index 5bd12fa..f596b89 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 4583924..1030031 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png new file mode 100644 index 0000000..0b02649 Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png index f480384..f20325b 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..8c3f92e Binary files /dev/null and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index 17279d6..d70a938 100644 Binary files a/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/apps/tauri/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/apps/tauri/src-tauri/gen/android/app/src/main/res/values/strings.xml b/apps/tauri/src-tauri/gen/android/app/src/main/res/values/strings.xml index e9951d1..2551e9e 100644 --- a/apps/tauri/src-tauri/gen/android/app/src/main/res/values/strings.xml +++ b/apps/tauri/src-tauri/gen/android/app/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ - tensamin - tensamin + Tensamin + Tensamin \ No newline at end of file diff --git a/apps/tauri/src-tauri/icons/128x128.png b/apps/tauri/src-tauri/icons/128x128.png index 2e64037..425ffb4 100644 Binary files a/apps/tauri/src-tauri/icons/128x128.png and b/apps/tauri/src-tauri/icons/128x128.png differ diff --git a/apps/tauri/src-tauri/icons/128x128@2x.png b/apps/tauri/src-tauri/icons/128x128@2x.png index d379bfa..9fe4117 100644 Binary files a/apps/tauri/src-tauri/icons/128x128@2x.png and b/apps/tauri/src-tauri/icons/128x128@2x.png differ diff --git a/apps/tauri/src-tauri/icons/32x32.png b/apps/tauri/src-tauri/icons/32x32.png index c98f4e9..3c9a880 100644 Binary files a/apps/tauri/src-tauri/icons/32x32.png and b/apps/tauri/src-tauri/icons/32x32.png differ diff --git a/apps/tauri/src-tauri/icons/64x64.png b/apps/tauri/src-tauri/icons/64x64.png index e579c32..0f9e690 100644 Binary files a/apps/tauri/src-tauri/icons/64x64.png and b/apps/tauri/src-tauri/icons/64x64.png differ diff --git a/apps/tauri/src-tauri/icons/Square107x107Logo.png b/apps/tauri/src-tauri/icons/Square107x107Logo.png index 32c273f..1ec3cb3 100644 Binary files a/apps/tauri/src-tauri/icons/Square107x107Logo.png and b/apps/tauri/src-tauri/icons/Square107x107Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square142x142Logo.png b/apps/tauri/src-tauri/icons/Square142x142Logo.png index b344198..5b92228 100644 Binary files a/apps/tauri/src-tauri/icons/Square142x142Logo.png and b/apps/tauri/src-tauri/icons/Square142x142Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square150x150Logo.png b/apps/tauri/src-tauri/icons/Square150x150Logo.png index a055b76..e1c1b1b 100644 Binary files a/apps/tauri/src-tauri/icons/Square150x150Logo.png and b/apps/tauri/src-tauri/icons/Square150x150Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square284x284Logo.png b/apps/tauri/src-tauri/icons/Square284x284Logo.png index 322f113..2d33951 100644 Binary files a/apps/tauri/src-tauri/icons/Square284x284Logo.png and b/apps/tauri/src-tauri/icons/Square284x284Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square30x30Logo.png b/apps/tauri/src-tauri/icons/Square30x30Logo.png index 563a719..686bcb7 100644 Binary files a/apps/tauri/src-tauri/icons/Square30x30Logo.png and b/apps/tauri/src-tauri/icons/Square30x30Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square310x310Logo.png b/apps/tauri/src-tauri/icons/Square310x310Logo.png index 2c05099..20207a5 100644 Binary files a/apps/tauri/src-tauri/icons/Square310x310Logo.png and b/apps/tauri/src-tauri/icons/Square310x310Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square44x44Logo.png b/apps/tauri/src-tauri/icons/Square44x44Logo.png index 9e7d8cb..7fcb138 100644 Binary files a/apps/tauri/src-tauri/icons/Square44x44Logo.png and b/apps/tauri/src-tauri/icons/Square44x44Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square71x71Logo.png b/apps/tauri/src-tauri/icons/Square71x71Logo.png index 949270a..6be9a53 100644 Binary files a/apps/tauri/src-tauri/icons/Square71x71Logo.png and b/apps/tauri/src-tauri/icons/Square71x71Logo.png differ diff --git a/apps/tauri/src-tauri/icons/Square89x89Logo.png b/apps/tauri/src-tauri/icons/Square89x89Logo.png index 2e7bf91..84bab9e 100644 Binary files a/apps/tauri/src-tauri/icons/Square89x89Logo.png and b/apps/tauri/src-tauri/icons/Square89x89Logo.png differ diff --git a/apps/tauri/src-tauri/icons/StoreLogo.png b/apps/tauri/src-tauri/icons/StoreLogo.png index 4b82c14..df2463e 100644 Binary files a/apps/tauri/src-tauri/icons/StoreLogo.png and b/apps/tauri/src-tauri/icons/StoreLogo.png differ diff --git a/apps/tauri/src-tauri/icons/icon.icns b/apps/tauri/src-tauri/icons/icon.icns index dbdc5e3..daf2362 100644 Binary files a/apps/tauri/src-tauri/icons/icon.icns and b/apps/tauri/src-tauri/icons/icon.icns differ diff --git a/apps/tauri/src-tauri/icons/icon.ico b/apps/tauri/src-tauri/icons/icon.ico index 7b2783e..fc67bfb 100644 Binary files a/apps/tauri/src-tauri/icons/icon.ico and b/apps/tauri/src-tauri/icons/icon.ico differ diff --git a/apps/tauri/src-tauri/icons/icon.png b/apps/tauri/src-tauri/icons/icon.png index 33853b3..8e56359 100644 Binary files a/apps/tauri/src-tauri/icons/icon.png and b/apps/tauri/src-tauri/icons/icon.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@1x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@1x.png index 294193c..d7880c7 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@1x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@1x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x-1.png b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x-1.png index 02a5874..a447149 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x-1.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x-1.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x.png index 02a5874..a447149 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@2x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@3x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@3x.png index 3453672..3524382 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@3x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-20x20@3x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@1x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@1x.png index 10af386..5aa9fac 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@1x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@1x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x-1.png b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x-1.png index a13e395..36d8549 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x-1.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x-1.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x.png index a13e395..36d8549 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@2x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@3x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@3x.png index f4f2ccf..4ece183 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@3x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-29x29@3x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@1x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@1x.png index 02a5874..a447149 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@1x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@1x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x-1.png b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x-1.png index 5414b1d..8b4aaa8 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x-1.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x-1.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x.png index 5414b1d..8b4aaa8 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@2x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@3x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@3x.png index aa8cbd8..dd1ff43 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@3x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-40x40@3x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-512@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-512@2x.png index 1beaa86..25d9e54 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-512@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-512@2x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@2x.png index aa8cbd8..dd1ff43 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@2x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@3x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@3x.png index 17aa19b..e46366a 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@3x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-60x60@3x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@1x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@1x.png index 67faaf8..c732ee4 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@1x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@1x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@2x.png index c00d463..52368fe 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-76x76@2x.png differ diff --git a/apps/tauri/src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png b/apps/tauri/src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png index f3ca0dd..d328f97 100644 Binary files a/apps/tauri/src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png and b/apps/tauri/src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png differ diff --git a/apps/tauri/src-tauri/tauri.conf.json b/apps/tauri/src-tauri/tauri.conf.json index c416f81..5651486 100644 --- a/apps/tauri/src-tauri/tauri.conf.json +++ b/apps/tauri/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Tensamin", - "version": "0.1.0", + "version": "0.0.0", "mainBinaryName": "tensamin", "identifier": "net.tensamin.client", "build": { diff --git a/apps/tauri/src/deeplinkHandler.tsx b/apps/tauri/src/deeplinkHandler.tsx index 36def6d..1053ea3 100644 --- a/apps/tauri/src/deeplinkHandler.tsx +++ b/apps/tauri/src/deeplinkHandler.tsx @@ -7,6 +7,7 @@ import { } from "react"; import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"; import { isTauri } from "@tauri-apps/api/core"; +import { useIsMobile } from "@tensamin/ui"; type DeeplinkContextValue = { deeplinks: readonly string[]; @@ -31,10 +32,10 @@ export default function DeeplinkProvider({ children: ReactNode; }) { const [deeplinks, setDeeplinks] = useState([]); - const isTauriEnv = isTauri(); + const isMobile = useIsMobile(); useEffect(() => { - if (!isTauriEnv) return; + if (!isTauri() || !isMobile) return; let mounted = true; let unlisten: (() => void) | undefined; @@ -57,7 +58,7 @@ export default function DeeplinkProvider({ mounted = false; unlisten?.(); }; - }, [isTauriEnv]); + }, [isMobile]); return ( - - - {reduceDisplay(props.user.display)} - -
-

{props.user.display}

+
+ + + + {user.display.slice(0, 2).toUpperCase()} + + + + +
+
+ } + /> + + {user.online_status + .split("_") + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(" ")} + +
+
+

{user.display}

+
+
{extra}
); diff --git a/apps/web/src/components/modals/profile.tsx b/apps/web/src/components/modals/profile.tsx new file mode 100644 index 0000000..6a31e36 --- /dev/null +++ b/apps/web/src/components/modals/profile.tsx @@ -0,0 +1,34 @@ +import type { User } from "@tensamin/user/context"; +import { Avatar, AvatarFallback, AvatarImage } from "@tensamin/ui"; +import Text from "@tensamin/markdown/text"; + +export default function Profile({ user }: { user: User }) { + return ( +
+
+ + + + {user.display.slice(0, 2).toUpperCase()} + + +
+

{user.display}

+

{user.username}

+
+
+ +
+

+ iota: {user.iota_id} +

+

+ user: {user.user_id} +

+

+ pub key: {user.public_key} +

+
+
+ ); +} diff --git a/apps/web/src/components/modals/utils.ts b/apps/web/src/components/modals/utils.ts deleted file mode 100644 index 248dcd5..0000000 --- a/apps/web/src/components/modals/utils.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Executes reduceDisplay. - * @param display Parameter display. - * @returns unknown. - */ -export function reduceDisplay(display: string) { - const words = display.split(" "); - if (words.length === 1) { - return display.slice(0, 2).toUpperCase(); - } else { - return words[0].charAt(0).toUpperCase() + words[1].charAt(0).toUpperCase(); - } -} diff --git a/apps/web/src/components/navbar.tsx b/apps/web/src/components/navbar.tsx index 162a057..a49a318 100644 --- a/apps/web/src/components/navbar.tsx +++ b/apps/web/src/components/navbar.tsx @@ -1,5 +1,13 @@ -import { Button } from "@tensamin/ui"; -import { ArrowLeft, House, Phone, Settings, User } from "lucide-react"; +import { Button, Popover, PopoverContent, PopoverTrigger } from "@tensamin/ui"; +import { + ArrowLeft, + ChevronDown, + ChevronUp, + House, + Phone, + Settings, + User, +} from "lucide-react"; import { useLocation, useNavigate, useSearch } from "@tanstack/react-router"; import { joinCall, useCall } from "@tensamin/call/store"; import Wrapper from "@tensamin/user/wrapper"; @@ -10,6 +18,7 @@ import { useState } from "react"; import { SidebarTrigger, useSidebar } from "@tensamin/ui"; import { WindowControls as Controls } from "@tensamin/ui"; import { useSession } from "@tensamin/storage/session"; +import Profile from "./modals/profile"; export default function Navbar({ forMobile }: { forMobile: boolean }) { const navigate = useNavigate(); @@ -23,10 +32,11 @@ export default function Navbar({ forMobile }: { forMobile: boolean }) { const currentCalls = calls.filter((call) => call.call_members.some((member) => member === id), ); - //const currentCalls = ["leck", "schleck", "und", "eck"]; const [selectOpen, setSelectOpen] = useState(false); + const [userInfoOpen, setUserInfoOpen] = useState(false); + return (
( -

{user?.display}

+ <> + + +

{user?.display}

+ {userInfoOpen ? : } + + } + /> + + + +
+ )} loading={} /> @@ -126,7 +156,7 @@ export default function Navbar({ forMobile }: { forMobile: boolean }) { )} )} - +
); diff --git a/apps/web/src/components/screens/login/form.tsx b/apps/web/src/components/screens/login/form.tsx index da5726c..e318c4b 100644 --- a/apps/web/src/components/screens/login/form.tsx +++ b/apps/web/src/components/screens/login/form.tsx @@ -1,4 +1,4 @@ -import { Button } from "@tensamin/ui"; +import { Button, cn, useIsMobile } from "@tensamin/ui"; import { Input } from "@tensamin/ui"; import { Label } from "@tensamin/ui"; import { useStorage } from "@tensamin/storage/context"; @@ -23,7 +23,7 @@ const fetchedUser = z.object({ }); const formSchema = z.object({ - username: z.string().min(1).max(15), + username: z.string().min(1).max(255), private_key: z.string().min(1).max(92), }); @@ -35,6 +35,7 @@ const formSchema = z.object({ function parseTuFileContent(rawFileContent: string): { userId: number; privateKey: string; + domain: string | null; } { if (rawFileContent.trim().length === 0) { throw new Error("File is empty"); @@ -42,42 +43,59 @@ function parseTuFileContent(rawFileContent: string): { throw new Error("Invalid file"); } else if (rawFileContent.split("::").length !== 2) { throw new Error("Invalid file"); - } else if (rawFileContent.split("::")[0].length === 0) { + } + + const left = rawFileContent.split("::")[0]; + const right = rawFileContent.split("::")[1]; + + if (left.length === 0) { throw new Error("Invalid file"); - } else if (rawFileContent.split("::")[1].length === 0) { + } else if (right.length === 0) { throw new Error("Invalid file"); - } else if (isNaN(Number(rawFileContent.split("::")[0]))) { + } else if (isNaN(Number(left)) && !left.includes("@")) { throw new Error("Invalid file"); } const [userIdString, privateKey] = rawFileContent.split("::"); - const userId = Number(userIdString); + const userId = isNaN(Number(userIdString)) + ? Number(userIdString.split("@")[0]) + : Number(userIdString); + + const rawDomain = userIdString.includes("@") + ? userIdString.split("@")[1] + : null; + const domain = rawDomain + ? rawDomain.includes(":") + ? rawDomain + : rawDomain + ":1984" + : null; + if (!userId || !privateKey) { throw new Error("Invalid file"); } - return { userId, privateKey }; + console.log({ + domain, + rawDomain, + userId, + }); + + return { userId, privateKey, domain }; } -/** - * Renders the login form for file upload and manual credential login. - * @returns Login form JSX. - */ export default function Form() { + const isMobile = useIsMobile(); const uploadRef = React.useRef(null); + const [isDragging, setIsDragging] = React.useState(false); const { save } = useStorage(); - /** - * Handles uploaded .tu files and stores resolved credentials. - * @param event Change event from the hidden file input. - * @returns Promise that resolves when processing has finished. - */ - const handleFileInputChange = React.useCallback( - async (event: React.ChangeEvent): Promise => { + // Process dropped files + const processDroppedFile = React.useCallback( + async (file: globalThis.File): Promise => { try { - const file = event.currentTarget.files?.[0]; - if (!file) { - throw new Error("No file selected"); + if (!file.name.endsWith(".tu")) { + toast("error", "Please upload a .tu file"); + return; } const raw = await file.text(); @@ -86,6 +104,9 @@ export default function Form() { await save("session_id", Date.now()); await save("user_id", parsed.userId); await save("private_key", parsed.privateKey); + if (parsed.domain) { + await save("ttp_url", `https://${parsed.domain}/`); + } location.href = "/"; } catch (error) { @@ -96,13 +117,94 @@ export default function Form() { [save], ); + // Handle .tu files + const handleFileInputChange = React.useCallback( + async (event: React.ChangeEvent): Promise => { + const file = event.currentTarget.files?.[0]; + + if (!file) { + toast("error", "No file selected"); + return; + } + + await processDroppedFile(file); + }, + [processDroppedFile], + ); + + // Drag and drop listener + React.useEffect(() => { + let dragCounter = 0; + + const handleDragEnter = (event: DragEvent) => { + event.preventDefault(); + event.stopPropagation(); + + dragCounter++; + + if (event.dataTransfer?.items?.length) { + setIsDragging(true); + } + }; + + const handleDragLeave = (event: DragEvent) => { + event.preventDefault(); + event.stopPropagation(); + + dragCounter--; + + if (dragCounter <= 0) { + setIsDragging(false); + } + }; + + const handleDragOver = (event: DragEvent) => { + event.preventDefault(); + event.stopPropagation(); + + if (event.dataTransfer) { + event.dataTransfer.dropEffect = "copy"; + } + }; + + const handleDrop = async (event: DragEvent) => { + event.preventDefault(); + event.stopPropagation(); + + dragCounter = 0; + + setIsDragging(false); + + const file = event.dataTransfer?.files?.[0]; + + if (!file) { + toast("error", "No file dropped"); + return; + } + + await processDroppedFile(file); + }; + + window.addEventListener("dragenter", handleDragEnter); + window.addEventListener("dragleave", handleDragLeave); + window.addEventListener("dragover", handleDragOver); + window.addEventListener("drop", handleDrop); + + return () => { + window.removeEventListener("dragenter", handleDragEnter); + window.removeEventListener("dragleave", handleDragLeave); + window.removeEventListener("dragover", handleDragOver); + window.removeEventListener("drop", handleDrop); + }; + }, [processDroppedFile]); + /** * Handles username and private key login submission. * @param event Form submit event. * @returns Promise that resolves after login processing. */ const handleCredentialsSubmit = React.useCallback( - async (event: React.SubmitEvent): Promise => { + async (event: React.FormEvent): Promise => { event.preventDefault(); const formData = new FormData(event.currentTarget); @@ -114,9 +216,22 @@ export default function Form() { return; } + const inputUsername = inputParse.data.username; + const actualUsername = inputUsername.includes("@") + ? inputUsername.split("@")[0] + : inputUsername; + const rawDomain = inputUsername.includes("@") + ? inputUsername.split("@")[1] + : null; + const domain = rawDomain + ? rawDomain.includes(":") + ? rawDomain + : rawDomain + ":1984" + : null; + try { const response = await fetch( - `https://omega.tensamin.net/api/get/id/${inputParse.data.username}`, + `https://omega.tensamin.net/api/get/id/${actualUsername}`, ); const rawData = await response.arrayBuffer(); @@ -137,6 +252,9 @@ export default function Form() { await save("session_id", Date.now()); await save("user_id", user.user_id); await save("private_key", inputParse.data.private_key); + if (domain) { + await save("ttp_url", `https://${domain}/`); + } location.href = "/"; } catch (error) { @@ -147,30 +265,35 @@ export default function Form() { [save], ); - const isTauriEnv = isTauri(); - return ( -
- {isTauriEnv ? ( +
+ {isTauri() && isMobile ? ( <> { + onData={async (data) => { if (!data.startsWith("tensamin://tu::")) { toast("error", "Invalid QR code"); return; - } else { - const decoded = data.replace("tensamin://tu::", ""); + } - try { - const { userId, privateKey } = parseTuFileContent(decoded); - save("session_id", Date.now()); - save("user_id", userId); - save("private_key", privateKey); - location.href = "/"; - } catch (error) { - log(0, "login", "red", error); - toast("error", "Failed to parse QR code data"); + const decoded = data.replace("tensamin://tu::", ""); + + try { + const { userId, privateKey, domain } = + parseTuFileContent(decoded); + + await save("session_id", Date.now()); + await save("user_id", userId); + await save("private_key", privateKey); + + if (domain) { + await save("ttp_url", `https://${domain}/`); } + + location.href = "/"; + } catch (error) { + log(0, "login", "red", error); + toast("error", "Failed to parse QR code data"); } }} /> @@ -181,10 +304,30 @@ export default function Form() { ) : (
uploadRef.current?.click()} - className="flex flex-col gap-3 cursor-pointer w-55 aspect-square bg-input/13 hover:bg-input/30 transition-all duration-300 ease-in-out border-3 items-center justify-center rounded-lg" + className={cn( + "flex flex-col gap-3 cursor-pointer w-55 aspect-square", + "border-3 items-center justify-center rounded-lg", + "transition-all duration-300 ease-in-out", + "border-input", + "bg-input/13 hover:bg-input/30", + isDragging ? "animate-wiggle" : "", + )} > - -

Select .tu file

+ + +

+ Select .tu file +

)} ; + +const onlineStatusLabels: Record = { + user_online: "Online", + user_offline: "Offline", + user_dnd: "Do not disturb", + user_idle: "Idle", + user_wc: "Away", + user_borked: "Borked", + iota_offline: "Iota offline", + iota_online: "Iota online", + iota_borked: "Iota borked", +}; + +function StatusDialog({ + user, + open, + onOpenChange, + send, + draftStatus, + setDraftStatus, + draftOnlineStatus, + setDraftOnlineStatus, + errorMessage, + setErrorMessage, + saveSucceeded, + setSaveSucceeded, +}: { + user: User; + open: boolean; + onOpenChange: (open: boolean) => void; + send: ReturnType["send"]; + draftStatus: string; + setDraftStatus: (value: string) => void; + draftOnlineStatus: OnlineStatus; + setDraftOnlineStatus: (value: OnlineStatus) => void; + errorMessage: string; + setErrorMessage: (value: string) => void; + saveSucceeded: boolean; + setSaveSucceeded: (value: boolean) => void; +}) { + return ( + { + if (!nextOpen) { + setDraftStatus(user.status ?? ""); + setDraftOnlineStatus(user.online_status); + setErrorMessage(""); + setSaveSucceeded(false); + } + + onOpenChange(nextOpen); + }} + > + + + Update Status + +
+ + { + setSaveSucceeded(false); + setErrorMessage(""); + setDraftStatus(e.target.value); + }} + /> + + +
+ {errorMessage && ( +

{errorMessage}

+ )} + + Cancel} /> + + +
+
+ ); +} -/** - * Renders the conversation sidebar with account summary and conversation list. - * @returns Sidebar JSX. - */ export default function Sidebar() { const isMobile = useIsMobile(); const showMobileNavbar = useShowMobileNavbar(); + const { openMobile, setOpenMobile } = useSidebar(); + const [draftStatus, setDraftStatus] = useState(""); + const [draftOnlineStatus, setDraftOnlineStatus] = + useState("user_online"); + const [dialogOpen, setDialogOpen] = useState(false); + const [statusErrorMessage, setStatusErrorMessage] = useState(""); + const [statusSaveSucceeded, setStatusSaveSucceeded] = useState(false); - return ( - + const { send } = useTTP(); + + const content = ( + <> } userId={"own"} - component={(user) => } + component={(user) => ( + <> + + + + + } + /> + + + Profile + { + setDraftStatus(user.status ?? ""); + setDraftOnlineStatus(user.online_status); + setStatusErrorMessage(""); + setStatusSaveSucceeded(false); + setDialogOpen(true); + }} + > + Set Status + + + + + } + /> + { + if (!nextOpen) { + setDraftStatus(user.status ?? ""); + setDraftOnlineStatus(user.online_status); + setStatusErrorMessage(""); + setStatusSaveSucceeded(false); + } + + setDialogOpen(nextOpen); + }} + send={send} + draftStatus={draftStatus} + setDraftStatus={setDraftStatus} + draftOnlineStatus={draftOnlineStatus} + setDraftOnlineStatus={setDraftOnlineStatus} + errorMessage={statusErrorMessage} + setErrorMessage={setStatusErrorMessage} + saveSucceeded={statusSaveSucceeded} + setSaveSucceeded={setStatusSaveSucceeded} + /> + + )} />
@@ -52,6 +287,34 @@ export default function Sidebar() { )} - + ); + + if (isMobile) { + return ( + <> + {openMobile && ( +
setOpenMobile(false)} + /> + )} +
+
{content}
+
+ + ); + } + + return {content}; } diff --git a/apps/web/src/features/conversation/list/body.tsx b/apps/web/src/features/conversation/list/body.tsx index 7092b6f..d240655 100644 --- a/apps/web/src/features/conversation/list/body.tsx +++ b/apps/web/src/features/conversation/list/body.tsx @@ -76,6 +76,16 @@ export default function List() {
); })} +
diff --git a/apps/web/src/features/settings/components.tsx b/apps/web/src/features/settings/components.tsx index ff1d7f1..7b4157b 100644 --- a/apps/web/src/features/settings/components.tsx +++ b/apps/web/src/features/settings/components.tsx @@ -36,7 +36,7 @@ export function Switch({ label, id, }: { - label: string; + label: React.ReactNode; id: keyof typeof settingsStorageDefaults & BooleanStorageKey; }) { const { save, load } = useStorage(); diff --git a/apps/web/src/features/settings/layout.tsx b/apps/web/src/features/settings/layout.tsx index fa27444..36d366a 100644 --- a/apps/web/src/features/settings/layout.tsx +++ b/apps/web/src/features/settings/layout.tsx @@ -1,4 +1,4 @@ -import { Button } from "@tensamin/ui"; +import { Button, ClearStorageButton } from "@tensamin/ui"; import options from "@tensamin/shared/settings"; import { cn, useIsMobile } from "@tensamin/ui"; @@ -69,6 +69,9 @@ export function SettingsSidebar() { ))} ))} +
+ +
); } diff --git a/apps/web/src/index.css b/apps/web/src/index.css index d243481..8175c9c 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -6,6 +6,20 @@ @source "./**/*.{ts,tsx}"; @source "../../../packages/**/src/**/*.{ts,tsx}"; +@theme { + --animate-wiggle: wiggle 0.5s ease-in-out infinite; + + @keyframes wiggle { + 0%, + 100% { + transform: rotate(-2deg); + } + 50% { + transform: rotate(2deg); + } + } +} + html, body, #root { @@ -17,3 +31,32 @@ body, #root { min-height: 0; } + +@layer base { + * { + scrollbar-width: thin; + scrollbar-color: var(--border) transparent; + } + + ::-webkit-scrollbar { + width: 6px; + height: 6px; + } + + ::-webkit-scrollbar-track { + background: transparent; + } + + ::-webkit-scrollbar-thumb { + background-color: var(--border); + border-radius: 9999px; + } + + ::-webkit-scrollbar-thumb:hover { + opacity: 0.8; + } + + ::-webkit-scrollbar-corner { + background: transparent; + } +} diff --git a/apps/web/src/routes/app/home.tsx b/apps/web/src/routes/app/home.tsx index 90f6a26..3e2c477 100644 --- a/apps/web/src/routes/app/home.tsx +++ b/apps/web/src/routes/app/home.tsx @@ -11,12 +11,12 @@ import { useIsMobile, } from "@tensamin/ui"; import z from "zod"; -import { toast } from "@tensamin/shared/log"; import { useTTP } from "@tensamin/ttp"; import { useState } from "react"; import { Loader2 } from "lucide-react"; import { isTauri } from "@tauri-apps/api/core"; import { useStorage } from "@tensamin/storage/context"; +import { useSession } from "@tensamin/storage/session"; // The page export default function Page() { @@ -43,11 +43,16 @@ export default function Page() { // Add Conversation Button Component function AddConversationButton() { const { send } = useTTP(); + const { contacts, insertContact } = useSession(); const [loading, setLoading] = useState(false); + const [open, setOpen] = useState(false); + const [error, setError] = useState(null); - function submit(username: string | null) { + async function submit(username: string | null) { if (loading) return; + setError(null); + // username check const schema = z .string() .min(1, "Username is too short") @@ -56,26 +61,50 @@ function AddConversationButton() { const result = schema.safeParse(username?.toLowerCase().trim()); if (!result.success) { - toast("error", result.error.issues[0].message); + setError(result.error.issues[0].message); return; } + // user existence check + const user = await send("get_user_data", { + username: result.data, + }) + .then((data) => { + if (data.data.user_id === 0) { + throw new Error(); + } + + return data; + }) + .catch(() => { + setError("User not found"); + return; + }); + if (!user) return; + + // alrady added check + if (contacts.some((contact) => contact.user_id === user.data.user_id)) { + setError("Conversation already exists"); + return; + } + + // add the conv const timeout = setTimeout(() => setLoading(true), 500); send("add_conversation", { chat_partner_name: result.data, }) .then(() => { - toast("success", "Conversation added"); + insertContact(user.data.user_id); + setOpen(false); }) .catch((error) => { if (String(error).includes("error_not_found")) { - toast("error", "User not found"); + setError("User not found"); return; } - toast("error", "Failed to add conversation, check console for details"); - console.error("Failed to add conversation", error); + setError(String(error)); }) .finally(() => { clearTimeout(timeout); @@ -84,7 +113,15 @@ function AddConversationButton() { } return ( - + { + if (value) { + setError(null); + } + setOpen(value); + }} + > Add Conversation} /> @@ -110,7 +147,10 @@ function AddConversationButton() { name="username" placeholder="Enter username..." /> -
+
+ {error && ( +

{error}

+ )} Cancel} /> + +
+

+ GIFs are supported in decentralised mode or with Tensamin Premium. +
+ Maximum file size is 16mb. +

+
+ + + updateDraftUser((prev) => ({ + ...prev, + display: event.target.value, + })) + } + placeholder="Display Name" + value={draftUser.display || ""} + /> + + updateDraftUser((prev) => ({ + ...prev, + username: event.target.value, + })) + } + placeholder="Username" + value={draftUser.username || ""} + /> + + updateDraftUser((prev) => ({ ...prev, about: value })) + } + value={draftUser.about || ""} + /> + + {errorMessage && ( +

{errorMessage}

+ )} + + + ) : ( +

Loading...

+ ); } diff --git a/apps/web/src/routes/settings/security.tsx b/apps/web/src/routes/settings/security.tsx index 15a6155..86c580e 100644 --- a/apps/web/src/routes/settings/security.tsx +++ b/apps/web/src/routes/settings/security.tsx @@ -46,6 +46,7 @@ function QrCodeLogin() { const [qrCodeBase64, setQrCodeBase64] = useState( undefined, ); + const [connectionString, setConnectionString] = useState(null); useEffect(() => { load("private_key").then((value) => { @@ -58,15 +59,25 @@ function QrCodeLogin() { setUserId(value); } }); + load("ttp_url") + .then((value) => { + if (value) { + const url = new URL(value); + setConnectionString(`@${url.host}`); + } else { + setConnectionString(""); + } + }) + .catch(() => setConnectionString("")); }, [load]); useEffect(() => { - if (userId && privateKey) { - generateQR(`tensamin://tu::${userId}::${privateKey}`).then( - setQrCodeBase64, - ); + if (userId && privateKey && connectionString !== null) { + generateQR( + `tensamin://tu::${userId}${connectionString}::${privateKey}`, + ).then(setQrCodeBase64); } - }, [userId, privateKey]); + }, [userId, privateKey, connectionString]); const [qrCodeVisible, setQrCodeVisible] = useState(false); diff --git a/bun.lock b/bun.lock index 5b4b4cd..1f1b34a 100644 --- a/bun.lock +++ b/bun.lock @@ -40,6 +40,7 @@ }, "devDependencies": { "@tauri-apps/cli": "^2", + "@types/node": "^25.9.1", }, }, "apps/web": { @@ -55,6 +56,7 @@ "@tensamin/call": "workspace:*", "@tensamin/chat": "workspace:*", "@tensamin/crypto": "workspace:*", + "@tensamin/markdown": "workspace:*", "@tensamin/notifications": "workspace:*", "@tensamin/shared": "workspace:*", "@tensamin/storage": "workspace:*", @@ -169,6 +171,7 @@ "name": "@tensamin/notifications", "version": "0.0.0", "dependencies": { + "@tanstack/react-router": "^1.169.1", "@tauri-apps/api": "^2.11.0", "@tensamin/chat": "workspace:*", "@tensamin/crypto": "workspace:*", @@ -258,8 +261,8 @@ }, }, "overrides": { - "@tensamin/ttp-core": "https://git.methanium.net/tensamin/ttp/archive/0.0.17.tar.gz", - "@tensamin/ui": "https://git.methanium.net/tensamin/ui/archive/0.0.31.tar.gz", + "@tensamin/ttp-core": "https://git.methanium.net/tensamin/ttp/archive/0.0.19.tar.gz", + "@tensamin/ui": "https://git.methanium.net/tensamin/ui/archive/0.0.34.tar.gz", }, "packages": { "@antfu/ni": ["@antfu/ni@25.0.0", "", { "dependencies": { "ansis": "^4.0.0", "fzf": "^0.5.2", "package-manager-detector": "^1.3.0", "tinyexec": "^1.0.1" }, "bin": { "na": "bin/na.mjs", "ni": "bin/ni.mjs", "nr": "bin/nr.mjs", "nci": "bin/nci.mjs", "nlx": "bin/nlx.mjs", "nun": "bin/nun.mjs", "nup": "bin/nup.mjs" } }, "sha512-9q/yCljni37pkMr4sPrI3G4jqdIk074+iukc5aFJl7kmDCCsiJrbZ6zKxnES1Gwg+i9RcDZwvktl23puGslmvA=="], @@ -698,9 +701,9 @@ "@tensamin/ttp": ["@tensamin/ttp@workspace:packages/ttp"], - "@tensamin/ttp-core": ["@tensamin/ttp-core@https://git.methanium.net/tensamin/ttp/archive/0.0.17.tar.gz", { "dependencies": { "@eslint/js": "^10.0.1", "@typescript-eslint/parser": "^8.59.1", "@webtransport-bun/webtransport": "^0.3.0", "globals": "^17.5.0", "typescript": "^6.0.3", "typescript-eslint": "^8.59.1", "zod": "^4.4.1" } }, "sha512-smyx+04hSnWM1oyWJfJrRWmxu7OInwyHeIlaD1h3tUrkrSxiKWHl1qCmxVO1bC+cDwyUXhJ5HUnNCbx1aWx7Dg=="], + "@tensamin/ttp-core": ["@tensamin/ttp-core@https://git.methanium.net/tensamin/ttp/archive/0.0.19.tar.gz", { "dependencies": { "@eslint/js": "^10.0.1", "@typescript-eslint/parser": "^8.59.1", "@webtransport-bun/webtransport": "^0.3.0", "globals": "^17.5.0", "typescript": "^6.0.3", "typescript-eslint": "^8.59.1", "zod": "^4.4.1" } }, "sha512-La9VqXqJFtzzsRQotXVp+3Vr6u8kj4mQ4wTlSIMRDxKFBnbCvtZyB3V/f8HiIlf7FlZ0Xg0suUUpnamvtcvs9w=="], - "@tensamin/ui": ["@tensamin/ui@https://git.methanium.net/tensamin/ui/archive/0.0.31.tar.gz", { "dependencies": { "@base-ui/react": "^1.3.0", "@fontsource-variable/inter": "^5.2.6", "@tauri-apps/api": "^2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.1.1", "date-fns": "^4.1.0", "embla-carousel-react": "^8.6.0", "input-otp": "^1.4.2", "lucide-react": "^1.8.0", "next-themes": "^0.4.6", "react-day-picker": "^9.14.0", "react-resizable-panels": "^4.10.0", "recharts": "3.8.0", "shadcn": "^3.5.0", "sonner": "^2.0.7", "tailwind-merge": "^3.5.0", "tw-animate-css": "^1.3.0", "vaul": "^1.1.2" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-I2FhsDtR5ElHwCasf6CfFCiyr5T2Cp9MQ2uAhcMnoNZ0tsK0mJhs+Rz9nUDmysydNyqOj8j/uC0CYXnnG1pCxQ=="], + "@tensamin/ui": ["@tensamin/ui@https://git.methanium.net/tensamin/ui/archive/0.0.34.tar.gz", { "dependencies": { "@base-ui/react": "^1.3.0", "@fontsource-variable/inter": "^5.2.6", "@tauri-apps/api": "^2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.1.1", "date-fns": "^4.1.0", "embla-carousel-react": "^8.6.0", "input-otp": "^1.4.2", "lucide-react": "^1.8.0", "next-themes": "^0.4.6", "react-day-picker": "^9.14.0", "react-resizable-panels": "^4.10.0", "recharts": "3.8.0", "shadcn": "^3.5.0", "sonner": "^2.0.7", "tailwind-merge": "^3.5.0", "tw-animate-css": "^1.3.0", "vaul": "^1.1.2" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-hp7rV0a0gfD/rNw9et+PqM1PPkgFC6/Z7eYfza6NIp/m+a8/r5Um+S/8tzBDCgZmQC9Y1sJsjesH7mXZz6Jmuw=="], "@tensamin/user": ["@tensamin/user@workspace:packages/user"], @@ -1660,6 +1663,8 @@ "@tailwindcss/oxide-wasm32-wasi/tslib": ["tslib@2.8.1", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], + "@tensamin/tauri/@types/node": ["@types/node@25.9.1", "", { "dependencies": { "undici-types": ">=7.24.0 <7.24.7" } }, "sha512-xfrlY7UD5rMJk3ZVJP8BNzS28J36YJg+xp+LPXV1TdWxr8uMH5A860QNxYDGQe/ylDSgjxE52Q9VnO7p75tJxg=="], + "@tensamin/ui/recharts": ["recharts@3.8.0", "", { "dependencies": { "@reduxjs/toolkit": "^1.9.0 || 2.x.x", "clsx": "^2.1.1", "decimal.js-light": "^2.5.1", "es-toolkit": "^1.39.3", "eventemitter3": "^5.0.1", "immer": "^10.1.1", "react-redux": "8.x.x || 9.x.x", "reselect": "5.1.1", "tiny-invariant": "^1.3.3", "use-sync-external-store": "^1.2.2", "victory-vendor": "^37.0.2" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-is": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-Z/m38DX3L73ExO4Tpc9/iZWHmHnlzWG4njQbxsF5aSjwqmHNDDIm0rdEBArkwsBvR8U6EirlEHiQNYWCVh9sGQ=="], "@tensamin/ui/shadcn": ["shadcn@3.8.5", "", { "dependencies": { "@antfu/ni": "^25.0.0", "@babel/core": "^7.28.0", "@babel/parser": "^7.28.0", "@babel/plugin-transform-typescript": "^7.28.0", "@babel/preset-typescript": "^7.27.1", "@dotenvx/dotenvx": "^1.48.4", "@modelcontextprotocol/sdk": "^1.26.0", "@types/validate-npm-package-name": "^4.0.2", "browserslist": "^4.26.2", "commander": "^14.0.0", "cosmiconfig": "^9.0.0", "dedent": "^1.6.0", "deepmerge": "^4.3.1", "diff": "^8.0.2", "execa": "^9.6.0", "fast-glob": "^3.3.3", "fs-extra": "^11.3.1", "fuzzysort": "^3.1.0", "https-proxy-agent": "^7.0.6", "kleur": "^4.1.5", "msw": "^2.10.4", "node-fetch": "^3.3.2", "open": "^11.0.0", "ora": "^8.2.0", "postcss": "^8.5.6", "postcss-selector-parser": "^7.1.0", "prompts": "^2.4.2", "recast": "^0.23.11", "stringify-object": "^5.0.0", "tailwind-merge": "^3.0.1", "ts-morph": "^26.0.0", "tsconfig-paths": "^4.2.0", "validate-npm-package-name": "^7.0.1", "zod": "^3.24.1", "zod-to-json-schema": "^3.24.6" }, "bin": { "shadcn": "dist/index.js" } }, "sha512-jPRx44e+eyeV7xwY3BLJXcfrks00+M0h5BGB9l6DdcBW4BpAj4x3lVmVy0TXPEs2iHEisxejr62sZAAw6B1EVA=="], @@ -1720,6 +1725,8 @@ "@modelcontextprotocol/sdk/ajv/json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], + "@tensamin/tauri/@types/node/undici-types": ["undici-types@7.24.6", "", {}, "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg=="], + "@tensamin/ui/shadcn/zod": ["zod@3.25.76", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="], "ajv-formats/ajv/json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], diff --git a/licenses/@tensamin_ttp-core@0.0.15/LICENSE b/licenses/@tensamin_ttp-core@0.0.19/LICENSE similarity index 100% rename from licenses/@tensamin_ttp-core@0.0.15/LICENSE rename to licenses/@tensamin_ttp-core@0.0.19/LICENSE diff --git a/licenses/THIRD_PARTY_NOTICES.md b/licenses/THIRD_PARTY_NOTICES.md index 51009a7..2dcc4e3 100644 --- a/licenses/THIRD_PARTY_NOTICES.md +++ b/licenses/THIRD_PARTY_NOTICES.md @@ -163,18 +163,18 @@ Generated from bun.lock and installed packages in workspace node_modules folders - Folder: `licenses/@tauri-apps_plugin-opener@2.5.4` - Source package dir: `apps/tauri/node_modules/@tauri-apps/plugin-opener` -## @tensamin/ttp-core@0.0.15 +## @tensamin/ttp-core@0.0.19 - License: UNKNOWN - Included files: LICENSE -- Folder: `licenses/@tensamin_ttp-core@0.0.15` +- Folder: `licenses/@tensamin_ttp-core@0.0.19` - Source package dir: `packages/ttp/node_modules/@tensamin/ttp-core` -## @tensamin/ui@0.0.30 +## @tensamin/ui@0.0.34 - License: UNKNOWN - Included files: none found -- Folder: `licenses/@tensamin_ui@0.0.30` +- Folder: `licenses/@tensamin_ui@0.0.34` - Source package dir: `apps/tauri/node_modules/@tensamin/ui` ## @types/node@25.6.0 @@ -449,6 +449,16 @@ Generated from bun.lock and installed packages in workspace node_modules folders - Folder: `licenses/tailwindcss@4.2.4` - Source package dir: `apps/web/node_modules/tailwindcss` +## tauri-plugin-app-events-api@0.2.0 + +- License: MIT +- Homepage: https://github.com/wtto00/tauri-plugin-app-events#readme +- Repository: git+https://github.com/wtto00/tauri-plugin-app-events.git +- Description: A plugin for tauri@v2 to listen some events on iOS and Android. +- Included files: LICENSE +- Folder: `licenses/tauri-plugin-app-events-api@0.2.0` +- Source package dir: `apps/web/node_modules/tauri-plugin-app-events-api` + ## tw-animate-css@1.4.0 - License: MIT diff --git a/licenses/sbom.cyclonedx.json b/licenses/sbom.cyclonedx.json index 6e10a91..4d1284c 100644 --- a/licenses/sbom.cyclonedx.json +++ b/licenses/sbom.cyclonedx.json @@ -3,7 +3,7 @@ "specVersion": "1.5", "version": 1, "metadata": { - "timestamp": "2026-05-04T13:05:17.472Z", + "timestamp": "2026-05-21T10:15:15.541Z", "tools": [ { "vendor": "OpenAI", @@ -580,15 +580,15 @@ }, { "type": "library", - "bomRef": "pkg:npm/%40tensamin/ttp-core@0.0.15", + "bomRef": "pkg:npm/%40tensamin/ttp-core@0.0.19", "name": "@tensamin/ttp-core", - "version": "0.0.15", - "purl": "pkg:npm/%40tensamin/ttp-core@0.0.15", + "version": "0.0.19", + "purl": "pkg:npm/%40tensamin/ttp-core@0.0.19", "externalReferences": [], "properties": [ { "name": "local:licenseFolder", - "value": "licenses/@tensamin_ttp-core@0.0.15" + "value": "licenses/@tensamin_ttp-core@0.0.19" }, { "name": "local:sourcePackageDir", @@ -598,15 +598,15 @@ }, { "type": "library", - "bomRef": "pkg:npm/%40tensamin/ui@0.0.30", + "bomRef": "pkg:npm/%40tensamin/ui@0.0.34", "name": "@tensamin/ui", - "version": "0.0.30", - "purl": "pkg:npm/%40tensamin/ui@0.0.30", + "version": "0.0.34", + "purl": "pkg:npm/%40tensamin/ui@0.0.34", "externalReferences": [], "properties": [ { "name": "local:licenseFolder", - "value": "licenses/@tensamin_ui@0.0.30" + "value": "licenses/@tensamin_ui@0.0.34" }, { "name": "local:sourcePackageDir", @@ -1562,6 +1562,41 @@ } ] }, + { + "type": "library", + "bomRef": "pkg:npm/tauri-plugin-app-events-api@0.2.0", + "name": "tauri-plugin-app-events-api", + "version": "0.2.0", + "purl": "pkg:npm/tauri-plugin-app-events-api@0.2.0", + "description": "A plugin for tauri@v2 to listen some events on iOS and Android.", + "licenses": [ + { + "license": { + "id": "MIT" + } + } + ], + "externalReferences": [ + { + "type": "website", + "url": "https://github.com/wtto00/tauri-plugin-app-events#readme" + }, + { + "type": "vcs", + "url": "git+https://github.com/wtto00/tauri-plugin-app-events.git" + } + ], + "properties": [ + { + "name": "local:licenseFolder", + "value": "licenses/tauri-plugin-app-events-api@0.2.0" + }, + { + "name": "local:sourcePackageDir", + "value": "apps/web/node_modules/tauri-plugin-app-events-api" + } + ] + }, { "type": "library", "bomRef": "pkg:npm/tw-animate-css@1.4.0", diff --git a/licenses/tauri-plugin-app-events-api@0.2.0/LICENSE b/licenses/tauri-plugin-app-events-api@0.2.0/LICENSE new file mode 100644 index 0000000..637004f --- /dev/null +++ b/licenses/tauri-plugin-app-events-api@0.2.0/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 简静凡 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/licenses/third-party-credits.json b/licenses/third-party-credits.json index a1d7968..bf9eab8 100644 --- a/licenses/third-party-credits.json +++ b/licenses/third-party-credits.json @@ -1,6 +1,6 @@ { - "generatedAt": "2026-05-04T13:05:17.471Z", - "packageCount": 53, + "generatedAt": "2026-05-21T10:15:15.540Z", + "packageCount": 54, "packages": [ { "name": "@codemirror/commands", @@ -227,7 +227,7 @@ }, { "name": "@tensamin/ttp-core", - "version": "0.0.15", + "version": "0.0.19", "license": "UNKNOWN", "homepage": null, "repository": null, @@ -235,18 +235,18 @@ "files": [ "LICENSE" ], - "licenseFolder": "licenses/@tensamin_ttp-core@0.0.15", + "licenseFolder": "licenses/@tensamin_ttp-core@0.0.19", "sourcePackageDir": "packages/ttp/node_modules/@tensamin/ttp-core" }, { "name": "@tensamin/ui", - "version": "0.0.30", + "version": "0.0.34", "license": "UNKNOWN", "homepage": null, "repository": null, "description": null, "files": [], - "licenseFolder": "licenses/@tensamin_ui@0.0.30", + "licenseFolder": "licenses/@tensamin_ui@0.0.34", "sourcePackageDir": "apps/tauri/node_modules/@tensamin/ui" }, { @@ -614,6 +614,19 @@ "licenseFolder": "licenses/tailwindcss@4.2.4", "sourcePackageDir": "apps/web/node_modules/tailwindcss" }, + { + "name": "tauri-plugin-app-events-api", + "version": "0.2.0", + "license": "MIT", + "homepage": "https://github.com/wtto00/tauri-plugin-app-events#readme", + "repository": "git+https://github.com/wtto00/tauri-plugin-app-events.git", + "description": "A plugin for tauri@v2 to listen some events on iOS and Android.", + "files": [ + "LICENSE" + ], + "licenseFolder": "licenses/tauri-plugin-app-events-api@0.2.0", + "sourcePackageDir": "apps/web/node_modules/tauri-plugin-app-events-api" + }, { "name": "tw-animate-css", "version": "1.4.0", diff --git a/package.json b/package.json index 40e19a8..d408353 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tensamin", - "version": "0.0.1", + "version": "0.0.3", "private": true, "workspaces": [ "packages/*", @@ -40,8 +40,8 @@ "jsonc-parser": "^3.3.1" }, "overrides": { - "@tensamin/ui": "https://git.methanium.net/tensamin/ui/archive/0.0.31.tar.gz", - "@tensamin/ttp-core": "https://git.methanium.net/tensamin/ttp/archive/0.0.17.tar.gz" + "@tensamin/ui": "https://git.methanium.net/tensamin/ui/archive/0.0.34.tar.gz", + "@tensamin/ttp-core": "https://git.methanium.net/tensamin/ttp/archive/0.0.19.tar.gz" }, "dependencies": { "@tensamin/ttp-core": "*", diff --git a/packages/call/src/components/buttons/screenshare.tsx b/packages/call/src/components/buttons/screenshare.tsx index 4471539..21ba118 100644 --- a/packages/call/src/components/buttons/screenshare.tsx +++ b/packages/call/src/components/buttons/screenshare.tsx @@ -18,10 +18,12 @@ export default function ScreenshareButton({ className, iconSize, tooltip, + defaultPortal, }: { className?: string; iconSize?: number; tooltip?: string; + defaultPortal?: boolean; }) { const isScreensharing = useCall((state) => state.screenShareEnabled); const screenRef = useCall((state) => state.screenRef); @@ -30,8 +32,9 @@ export default function ScreenshareButton({ const [menuOpen, setMenuOpen] = useState(false); useEffect(() => { + if (defaultPortal) return; setPortalContainer(screenRef?.current ?? undefined); - }, [screenRef]); + }, [screenRef, defaultPortal]); async function startWebShare() { try { @@ -110,7 +113,9 @@ export default function ScreenshareButton({ /> } /> - - Click to open call page - + Click to open call page ); } -export function TinyPingGraph({ - portalContainer, -}: { - portalContainer?: HTMLElement; -}) { - const room = useCall((store) => store.room); +export function TinyPingGraph() { + const room = getRoom(); const [mapData, setMapData] = useState>(() => new Map()); @@ -176,7 +164,7 @@ export function TinyPingGraph({ } /> - + {data.length > 0 ? `${data.at(-1)?.ping} ms` : "Measuring ping..."} diff --git a/packages/call/src/components/top.tsx b/packages/call/src/components/top.tsx index 62e8bfc..610493a 100644 --- a/packages/call/src/components/top.tsx +++ b/packages/call/src/components/top.tsx @@ -1,5 +1,5 @@ import { useUser, type User } from "@tensamin/user/context"; -import { useCall } from "../store"; +import { useCall, getRoom } from "../store"; import { useEffect, useState } from "react"; import { useStorage } from "@tensamin/storage/context"; import { @@ -14,7 +14,7 @@ import { export default function TopBar() { const { get } = useUser(); const { load } = useStorage(); - const room = useCall((state) => state.room); + const room = getRoom(); const screenRef = useCall((state) => state.screenRef); const [portalContainer, setPortalContainer] = useState(); diff --git a/packages/call/src/components/videoViewer.tsx b/packages/call/src/components/videoViewer.tsx index 40cf6ac..1268b22 100644 --- a/packages/call/src/components/videoViewer.tsx +++ b/packages/call/src/components/videoViewer.tsx @@ -1,6 +1,6 @@ import { VideoTrack, useParticipantTracks } from "@livekit/components-react"; import { TrackPublication } from "livekit-client"; -import { useCall } from "../store"; +import { getRoom } from "../store"; import { cn } from "@tensamin/ui"; import { Loader2 } from "lucide-react"; @@ -17,7 +17,7 @@ export default function VideoViewer({ publication: TrackPublication; participantId: string; }) { - const room = useCall((state) => state.room); + const room = getRoom(); const tracks = useParticipantTracks([publication.source], { participantIdentity: participantId, room, diff --git a/packages/call/src/speakingIndicator.ts b/packages/call/src/speakingIndicator.ts new file mode 100644 index 0000000..0c4f5a5 --- /dev/null +++ b/packages/call/src/speakingIndicator.ts @@ -0,0 +1,252 @@ +import { log } from "@tensamin/shared/log"; +import { useCall } from "./store"; + +const SPEAKING_THRESHOLD = 0.01; +const SPEAKING_HANGTIME_MS = 500; +const ANALYSIS_INTERVAL_MS = 30; +const FFT_SIZE = 256; + +type AnalyserEntry = { + source: MediaStreamAudioSourceNode; + analyser: AnalyserNode; + track: MediaStreamTrack; + originalTrack?: MediaStreamTrack; + lastSpeakingTime: number; + isSpeaking: boolean; +}; + +class SpeakingDetector { + private audioContext: AudioContext | null = null; + private entries = new Map(); + private intervalId: ReturnType | null = null; + private deaf = false; + private gateThresholdStart = -50; + private gateThresholdEnd = -40; + private localParticipantId: number | null = null; + private localMicGateClosed = false; + + private ensureAudioContext(): AudioContext { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + if (this.audioContext.state === "suspended") { + void this.audioContext.resume(); + } + return this.audioContext; + } + + setLocalParticipantId(id: number) { + this.localParticipantId = id; + } + + setGateThresholds(start: number, end: number) { + this.gateThresholdStart = start; + this.gateThresholdEnd = end; + } + + addTrack( + participantId: number, + track: MediaStreamTrack, + originalTrack?: MediaStreamTrack, + ) { + if (track.kind !== "audio") return; + + this.removeParticipant(participantId); + + const ctx = this.ensureAudioContext(); + const stream = new MediaStream([track]); + const source = ctx.createMediaStreamSource(stream); + const analyser = ctx.createAnalyser(); + analyser.fftSize = FFT_SIZE; + source.connect(analyser); + + this.entries.set(participantId, { + source, + analyser, + track, + originalTrack, + lastSpeakingTime: 0, + isSpeaking: false, + }); + + if (!this.intervalId) { + this.startLoop(); + } + } + + removeParticipant(participantId: number) { + const entry = this.entries.get(participantId); + if (!entry) return; + + try { + entry.source.disconnect(); + } catch { + // ignore + } + this.entries.delete(participantId); + + useCall.setState((state) => { + if (!state.speakingParticipantIds.has(participantId)) return state; + const next = new Set(state.speakingParticipantIds); + next.delete(participantId); + return { speakingParticipantIds: next }; + }); + + if (participantId === this.localParticipantId && this.localMicGateClosed) { + this.muteLocalTrack(false); + } + } + + setDeaf(deaf: boolean) { + this.deaf = deaf; + if (deaf) { + for (const entry of this.entries.values()) { + entry.isSpeaking = false; + entry.lastSpeakingTime = 0; + } + useCall.setState({ speakingParticipantIds: new Set() }); + } + } + + private startLoop() { + if (this.intervalId) return; + this.intervalId = setInterval(() => this.analyse(), ANALYSIS_INTERVAL_MS); + } + + private stopLoop() { + if (this.intervalId) { + clearInterval(this.intervalId); + this.intervalId = null; + } + } + + private muteLocalTrack(muted: boolean) { + const entry = this.localParticipantId + ? this.entries.get(this.localParticipantId) + : undefined; + const target = entry?.originalTrack ?? entry?.track; + + if (target && target.enabled === muted) { + target.enabled = !muted; + } + + this.localMicGateClosed = muted; + useCall.setState({ micGated: muted }); + } + + private applyNoiseGate(rms: number) { + const db = 20 * Math.log10(Math.max(rms, 0.0001)); + + if (!this.localMicGateClosed && db < this.gateThresholdStart) { + log(3, "noise gate", "purple", "closed"); + this.muteLocalTrack(true); + } else if (this.localMicGateClosed && db > this.gateThresholdEnd) { + log(3, "noise gate", "purple", "opened"); + this.muteLocalTrack(false); + } + } + + private analyse() { + if (this.deaf || this.entries.size === 0) return; + + const now = Date.now(); + const changed = new Map(); + + for (const [participantId, entry] of this.entries) { + const { analyser, track } = entry; + + if (track.muted || track.readyState === "ended" || !track.enabled) { + if (entry.isSpeaking) { + entry.isSpeaking = false; + entry.lastSpeakingTime = 0; + changed.set(participantId, false); + } + continue; + } + + const bufferLength = analyser.frequencyBinCount; + const dataArray = new Uint8Array(bufferLength); + analyser.getByteTimeDomainData(dataArray); + + let sum = 0; + for (let i = 0; i < bufferLength; i++) { + const sample = (dataArray[i] - 128) / 128.0; + sum += sample * sample; + } + const rms = Math.sqrt(sum / bufferLength); + + let nextIsSpeaking = entry.isSpeaking; + if (rms > SPEAKING_THRESHOLD) { + entry.lastSpeakingTime = now; + nextIsSpeaking = true; + } else if (now - entry.lastSpeakingTime > SPEAKING_HANGTIME_MS) { + nextIsSpeaking = false; + } + + if (participantId === this.localParticipantId) { + this.applyNoiseGate(rms); + if (this.localMicGateClosed) { + nextIsSpeaking = false; + } + } + + if (nextIsSpeaking !== entry.isSpeaking) { + entry.isSpeaking = nextIsSpeaking; + changed.set(participantId, nextIsSpeaking); + } + } + + if (changed.size > 0) { + useCall.setState((state) => { + let hasDiff = false; + const next = new Set(state.speakingParticipantIds); + for (const [id, speaking] of changed) { + if (speaking) { + if (!next.has(id)) { + next.add(id); + hasDiff = true; + } + } else { + if (next.has(id)) { + next.delete(id); + hasDiff = true; + } + } + } + return hasDiff ? { speakingParticipantIds: next } : state; + }); + } + } + + dispose() { + this.stopLoop(); + for (const id of Array.from(this.entries.keys())) { + this.removeParticipant(id); + } + this.entries.clear(); + if (this.audioContext) { + void this.audioContext.close(); + this.audioContext = null; + } + } +} + +let detectorInstance: SpeakingDetector | null = null; + +export function getSpeakingDetector(): SpeakingDetector { + if (!detectorInstance) { + detectorInstance = new SpeakingDetector(); + } + return detectorInstance; +} + +export function disposeSpeakingDetector(): void { + if (detectorInstance) { + detectorInstance.dispose(); + detectorInstance = null; + } +} + +export function useIsSpeaking(participantId: number): boolean { + return useCall((state) => state.speakingParticipantIds.has(participantId)); +} diff --git a/packages/call/src/store.tsx b/packages/call/src/store.tsx index e605ece..5398e70 100644 --- a/packages/call/src/store.tsx +++ b/packages/call/src/store.tsx @@ -11,6 +11,7 @@ import { DeepFilterNoiseFilterProcessor } from "deepfilternet3-noise-filter"; import { ExternalE2EEKeyProvider, LocalAudioTrack, + type LocalTrackPublication, type Participant, type RemoteParticipant, type RemoteTrackPublication, @@ -28,6 +29,10 @@ import { createScreenShareController, type ScreenShareSession, } from "./screenshare"; +import { + getSpeakingDetector, + disposeSpeakingDetector, +} from "./speakingIndicator"; // logging setLogExtension( @@ -86,6 +91,7 @@ type CallStore = { screenShareEnabled: boolean; screenShareSession: ScreenShareSession | null; focusedParticipantId: number | null; + focusedParticipantType: "user" | "stream" | null; usersInFocusedViewHidden: boolean; watchedStreamParticipantIds: number[]; pendingWatchedParticipantIds: number[]; @@ -95,25 +101,46 @@ type CallStore = { callIsPopout: boolean; layoutVersion: number; screenRef: React.RefObject | null; - room: Room; - keyProvider: ExternalE2EEKeyProvider; - e2eeWorker: Worker; runtime: Runtime | null; + speakingParticipantIds: Set; + micGated: boolean; }; -const keyProvider = new ExternalE2EEKeyProvider(); -const e2eeWorker = new Worker( - new URL("livekit-client/e2ee-worker", import.meta.url), -); -const room = new Room({ - dynacast: true, - adaptiveStream: true, - loggerName: "tensamin", - encryption: { - keyProvider, - worker: e2eeWorker, - }, -}); +let _keyProvider: ExternalE2EEKeyProvider | null = null; +let _e2eeWorker: Worker | null = null; +let _room: Room | null = null; + +function getKeyProvider(): ExternalE2EEKeyProvider { + if (!_keyProvider) { + _keyProvider = new ExternalE2EEKeyProvider(); + } + return _keyProvider; +} + +function getE2EEWorker(): Worker { + if (!_e2eeWorker) { + _e2eeWorker = new Worker( + new URL("livekit-client/e2ee-worker", import.meta.url), + ); + } + return _e2eeWorker; +} + +export function getRoom(): Room { + if (!_room) { + _room = new Room({ + dynacast: true, + adaptiveStream: true, + loggerName: "tensamin", + encryption: { + keyProvider: getKeyProvider(), + worker: getE2EEWorker(), + }, + }); + } + return _room; +} + const remoteAudioElements = new Map(); const SCREEN_SHARE_PREVIEW_MAX_WIDTH = 320; @@ -152,7 +179,7 @@ function clearRemoteAudio() { } } -function getParticipantId(identity: string | undefined): number | null { +export function getParticipantId(identity: string | undefined): number | null { if (!identity) { return null; } @@ -162,6 +189,7 @@ function getParticipantId(identity: string | undefined): number | null { } function getAllParticipants(): Participant[] { + const room = getRoom(); return [...room.remoteParticipants.values(), room.localParticipant]; } @@ -179,7 +207,7 @@ function getTrackPublicationBySource( } function getRemoteParticipant(participantId: number) { - return [...room.remoteParticipants.values()].find( + return [...getRoom().remoteParticipants.values()].find( (participant) => getParticipantId(participant.identity) === participantId, ); } @@ -199,12 +227,15 @@ function matchesRemoteTrackSelector( function syncRemoteParticipantTrackSubscriptions(participantId: number) { for (const publication of getRemoteTrackPublications(participantId)) { - publication.setSubscribed(publication.kind === Track.Kind.Audio); + publication.setSubscribed( + publication.kind === Track.Kind.Audio && + publication.source !== Track.Source.ScreenShareAudio, + ); } } function syncAllRemoteTrackSubscriptions() { - for (const participant of room.remoteParticipants.values()) { + for (const participant of getRoom().remoteParticipants.values()) { const participantId = getParticipantId(participant.identity); if (participantId != null) { @@ -245,7 +276,7 @@ function hasParticipant(participantId: number) { function getLocalScreenShareTrack(): MediaStreamTrack | null { const track = getTrackPublicationBySource( - room.localParticipant, + getRoom().localParticipant, Track.Source.ScreenShare, )?.track; @@ -264,13 +295,15 @@ async function updateLocalParticipantAttributes( screenSharePreviewLength: attributes.screenSharePreview?.length ?? 0, }); - await room.localParticipant.setAttributes(attributes).catch((error) => { - log(1, "call", "red", "Failed to update local participant attributes", { - attributes: Object.keys(attributes), - error, + await getRoom() + .localParticipant.setAttributes(attributes) + .catch((error) => { + log(1, "call", "red", "Failed to update local participant attributes", { + attributes: Object.keys(attributes), + error, + }); + throw error; }); - throw error; - }); log(2, "call", "purple", "Updated local participant attributes", { attributeKeys: Object.keys(attributes), @@ -457,6 +490,8 @@ function syncScreenShareParticipants() { watchedStreamParticipantIds, pendingWatchedParticipantIds, focusedParticipantId, + focusedParticipantType: + focusedParticipantId == null ? null : state.focusedParticipantType, view: state.view === "focused" && focusedParticipantId == null ? "grid" @@ -474,7 +509,7 @@ function requireRuntime(runtime: Runtime | null): Runtime { } export function getRoomMetadata() { - const roomMetadata = room.metadata; + const roomMetadata = getRoom().metadata; try { const data = JSON.parse(roomMetadata || '{"admins": []}'); return data as { admins: number[] }; @@ -485,7 +520,8 @@ export function getRoomMetadata() { // Sync local participant flags and screen-share derived state for the active call UI. export function syncParticipantState() { - const { room, screenShareSession } = useCall.getState(); + const { screenShareSession } = useCall.getState(); + const room = getRoom(); useCall.setState({ micEnabled: room.localParticipant.isMicrophoneEnabled, @@ -614,6 +650,7 @@ export function startWatchingStream(participantId: number) { const trackReady = getScreenShareTrackForParticipant(participantId) != null; setParticipantTrackSubscribed(participantId, Track.Source.ScreenShare); + setParticipantTrackSubscribed(participantId, Track.Source.ScreenShareAudio); useCall.setState((state) => ({ watchedStreamParticipantIds: state.watchedStreamParticipantIds.includes( @@ -627,6 +664,7 @@ export function startWatchingStream(participantId: number) { ? state.pendingWatchedParticipantIds : [...state.pendingWatchedParticipantIds, participantId], focusedParticipantId: participantId, + focusedParticipantType: "stream", })); } @@ -646,9 +684,13 @@ export function setParticipantTrackSubscribed( } // Focus a participant in the main call view even when they are not sharing a screen. -export function focusParticipant(participantId: number) { +export function focusParticipant( + participantId: number, + type: "user" | "stream" = "user", +) { useCall.setState({ focusedParticipantId: participantId, + focusedParticipantType: type, view: "focused", }); } @@ -656,6 +698,11 @@ export function focusParticipant(participantId: number) { // Stop tracking a participant's shared screen and clean up related UI state. export function stopWatchingStream(participantId: number) { setParticipantTrackSubscribed(participantId, Track.Source.ScreenShare, false); + setParticipantTrackSubscribed( + participantId, + Track.Source.ScreenShareAudio, + false, + ); useCall.setState((state) => ({ watchedStreamParticipantIds: state.watchedStreamParticipantIds.filter( @@ -668,6 +715,10 @@ export function stopWatchingStream(participantId: number) { state.focusedParticipantId === participantId ? null : state.focusedParticipantId, + focusedParticipantType: + state.focusedParticipantId === participantId + ? null + : state.focusedParticipantType, view: state.view === "focused" && state.focusedParticipantId === participantId ? "grid" @@ -693,7 +744,7 @@ let screenShareController: ReturnType< function getScreenShareController() { if (!screenShareController) { screenShareController = createScreenShareController({ - room, + room: getRoom(), getState: () => ({ screenShareSession: useCall.getState().screenShareSession, }), @@ -705,7 +756,7 @@ function getScreenShareController() { ); }, getLocalParticipantId: () => - getParticipantId(room.localParticipant.identity), + getParticipantId(getRoom().localParticipant.identity), startWatching: startWatchingStream, stopWatching: stopWatchingStream, syncParticipantState, @@ -730,7 +781,7 @@ export async function connect(callId: string) { callSecret: useCall.getState().callSecret, }); - await room + await getRoom() .connect("wss://call.tensamin.net", token, { autoSubscribe: false, }) @@ -746,17 +797,20 @@ export async function connect(callId: string) { syncAllRemoteTrackSubscriptions(); - await room.localParticipant.setMicrophoneEnabled(true).catch((error) => { - log(1, "call", "red", "Failed to enable microphone", error); - toast("error", "Failed to enable microphone."); - throw error; - }); + await getRoom() + .localParticipant.setMicrophoneEnabled(true) + .catch((error) => { + log(1, "call", "red", "Failed to enable microphone", error); + toast("error", "Failed to enable microphone."); + throw error; + }); syncParticipantState(); } // Tear down the active call session and return the store to a closed state. export async function disconnect() { + disposeSpeakingDetector(); await clearScreenSharePreview(); try { @@ -782,18 +836,20 @@ export async function disconnect() { view: "preview", screenShareSession: null, focusedParticipantId: null, + focusedParticipantType: null, usersInFocusedViewHidden: false, watchedStreamParticipantIds: [], pendingWatchedParticipantIds: [], activeScreenShareParticipantIds: [], + micGated: false, }); - room.remoteParticipants.forEach((participant) => { + getRoom().remoteParticipants.forEach((participant) => { participant.setVolume(1); }); try { - await room.disconnect(); + await getRoom().disconnect(); } catch (error) { log(1, "call", "red", "Failed to disconnect from room", error); } finally { @@ -836,8 +892,8 @@ export async function joinCall( callSecret, ); - await keyProvider.setKey(decryptedSecret); - await room.setE2EEEnabled(true); + await getKeyProvider().setKey(decryptedSecret); + await getRoom().setE2EEEnabled(true); useCall.setState({ callSecret: decryptedSecret }); } catch (err) { log(1, "call", "red", "Failed getting call secret", err); @@ -847,8 +903,8 @@ export async function joinCall( } else { const random = crypto.randomUUID(); - await keyProvider.setKey(random); - await room.setE2EEEnabled(true); + await getKeyProvider().setKey(random); + await getRoom().setE2EEEnabled(true); useCall.setState({ callSecret: random }); } @@ -867,11 +923,11 @@ export async function joinCall( export async function toggleDeaf() { const nextDeaf = !useCall.getState().deaf; - room.remoteParticipants.forEach((participant) => { + getRoom().remoteParticipants.forEach((participant) => { participant.setVolume(nextDeaf ? 0 : 1); }); - if (nextDeaf && room.localParticipant.isMicrophoneEnabled) { + if (nextDeaf && getRoom().localParticipant.isMicrophoneEnabled) { await toggleMute(); } @@ -879,6 +935,7 @@ export async function toggleDeaf() { deafened: nextDeaf ? "true" : "false", }); + getSpeakingDetector().setDeaf(nextDeaf); useCall.setState({ deaf: nextDeaf }); } @@ -890,7 +947,7 @@ export async function toggleMute() { await toggleDeaf(); } - await room.localParticipant.setMicrophoneEnabled(!micEnabled); + await getRoom().localParticipant.setMicrophoneEnabled(!micEnabled); syncParticipantState(); } @@ -940,6 +997,7 @@ export function resetCallState() { deaf: false, screenShareSession: null, focusedParticipantId: null, + focusedParticipantType: null, usersInFocusedViewHidden: false, watchedStreamParticipantIds: [], pendingWatchedParticipantIds: [], @@ -953,7 +1011,7 @@ export function resetCallState() { async function ensureNoiseFilter( noiseFilter: DeepFilterNoiseFilterProcessor, ): Promise { - const microphoneTrack = room.localParticipant.getTrackPublication( + const microphoneTrack = getRoom().localParticipant.getTrackPublication( Track.Source.Microphone, )?.track; @@ -967,6 +1025,16 @@ async function ensureNoiseFilter( await microphoneTrack.setProcessor(noiseFilter).catch((err) => { log(1, "call", "red", "Failed to enable noise filter", err); }); + + const participantId = getParticipantId(getRoom().localParticipant.identity); + if (participantId != null) { + const processedTrack = microphoneTrack.mediaStreamTrack; + getSpeakingDetector().addTrack( + participantId, + processedTrack.clone(), + processedTrack, + ); + } } export const useCall = create(() => ({ @@ -978,24 +1046,23 @@ export const useCall = create(() => ({ livekitToken: null, currentCallData: null, deaf: false, - micEnabled: room.localParticipant.isMicrophoneEnabled, - screenShareEnabled: room.localParticipant.isScreenShareEnabled, + micEnabled: false, + screenShareEnabled: false, screenShareSession: null, focusedParticipantId: null, + focusedParticipantType: null, usersInFocusedViewHidden: false, watchedStreamParticipantIds: [], pendingWatchedParticipantIds: [], activeScreenShareParticipantIds: [], - isEncrypted: - room.localParticipant.isE2EEEnabled && room.localParticipant.isEncrypted, + isEncrypted: false, callIsFullscreen: false, callIsPopout: false, layoutVersion: 0, screenRef: null, - room, - keyProvider, - e2eeWorker, runtime: null, + speakingParticipantIds: new Set(), + micGated: false, })); // Register app-level call listeners and wire React dependencies into the store. @@ -1016,7 +1083,7 @@ export function useInitializeCall() { new DeepFilterNoiseFilterProcessor({ enabled: true, enableNoiseReduction: true, - noiseReductionLevel: 80, + noiseReductionLevel: 60, sampleRate: 48000, assetConfig: { cdnUrl: "/assets", @@ -1137,10 +1204,46 @@ export function useInitializeCall() { listenersRegistered.current = true; - const onConnected = () => { + const onConnected = async () => { useCall.setState({ state: "open" }); syncParticipantState(); + const detector = getSpeakingDetector(); + const localParticipantId = getParticipantId( + room.localParticipant.identity, + ); + if (localParticipantId != null) { + detector.setLocalParticipantId(localParticipantId); + } + + const [start, end] = await Promise.all([ + load("call_mute_range_start"), + load("call_mute_range_end"), + ]); + detector.setGateThresholds(start, end); + + // Scan existing audio tracks for speaking detection + for (const participant of getAllParticipants()) { + const participantId = getParticipantId(participant.identity); + if (participantId == null) continue; + + for (const publication of participant.trackPublications.values()) { + if ( + publication.kind === Track.Kind.Audio && + publication.source === Track.Source.Microphone && + publication.track + ) { + const mediaTrack = publication.track.mediaStreamTrack; + if (participant === room.localParticipant) { + const clonedTrack = mediaTrack.clone(); + detector.addTrack(participantId, clonedTrack, mediaTrack); + } else { + detector.addTrack(participantId, mediaTrack); + } + } + } + } + const invitedUserId = useCall.getState().invitedUserId; if (invitedUserId != null) { @@ -1177,6 +1280,7 @@ export function useInitializeCall() { if (participantId != null) { stopWatchingStream(participantId); + getSpeakingDetector().removeParticipant(participantId); } syncParticipantState(); @@ -1197,6 +1301,40 @@ export function useInitializeCall() { void ensureNoiseFilter(noiseFilter); }; + const onLocalTrackPublished = (publication: LocalTrackPublication) => { + if ( + publication.kind === Track.Kind.Audio && + publication.source === Track.Source.Microphone && + publication.track + ) { + const participantId = getParticipantId(room.localParticipant.identity); + if (participantId != null) { + const originalTrack = publication.track.mediaStreamTrack; + const clonedTrack = originalTrack.clone(); + getSpeakingDetector().addTrack( + participantId, + clonedTrack, + originalTrack, + ); + } + } + syncParticipantState(); + void ensureNoiseFilter(noiseFilter); + }; + + const onLocalTrackUnpublished = (publication: LocalTrackPublication) => { + if ( + publication.kind === Track.Kind.Audio && + publication.source === Track.Source.Microphone + ) { + const participantId = getParticipantId(room.localParticipant.identity); + if (participantId != null) { + getSpeakingDetector().removeParticipant(participantId); + } + } + syncParticipantState(); + }; + const onTrackPublished = ( publication: RemoteTrackPublication, participant: RemoteParticipant, @@ -1204,7 +1342,10 @@ export function useInitializeCall() { const participantId = getParticipantId(participant.identity); if (participantId != null) { - if (publication.kind === Track.Kind.Audio) { + if ( + publication.kind === Track.Kind.Audio && + publication.source !== Track.Source.ScreenShareAudio + ) { publication.setSubscribed(true); } else { publication.setSubscribed(false); @@ -1214,9 +1355,21 @@ export function useInitializeCall() { onParticipantStateChange(); }; - const onTrackSubscribed = (track: RemoteTrack) => { + const onTrackSubscribed = ( + track: RemoteTrack, + publication: RemoteTrackPublication, + participant: RemoteParticipant, + ) => { if (track.kind === "audio" && track.sid) { attachRemoteAudio(track.sid, track.attach()); + + const participantId = getParticipantId(participant.identity); + if ( + participantId != null && + publication.source === Track.Source.Microphone + ) { + getSpeakingDetector().addTrack(participantId, track.mediaStreamTrack); + } } syncParticipantState(); @@ -1224,15 +1377,22 @@ export function useInitializeCall() { const onTrackUnsubscribed = ( track: RemoteTrack, - _publication: unknown, + publication: RemoteTrackPublication, participant: Participant, ) => { + const participantId = getParticipantId(participant.identity); + if (track.kind === "audio" && track.sid) { track.detach(); detachRemoteAudio(track.sid); - } - const participantId = getParticipantId(participant.identity); + if ( + participantId != null && + publication.source === Track.Source.Microphone + ) { + getSpeakingDetector().removeParticipant(participantId); + } + } if ( participantId != null && @@ -1245,6 +1405,7 @@ export function useInitializeCall() { syncParticipantState(); }; + const room = getRoom(); room.on(RoomEvent.Connected, onConnected); room.on(RoomEvent.Reconnected, onConnected); room.on(RoomEvent.Disconnected, onDisconnected); @@ -1256,8 +1417,8 @@ export function useInitializeCall() { room.on(RoomEvent.ParticipantDisconnected, onParticipantDisconnected); room.on(RoomEvent.TrackMuted, onParticipantStateChange); room.on(RoomEvent.TrackUnmuted, onParticipantStateChange); - room.on(RoomEvent.LocalTrackPublished, onParticipantStateChange); - room.on(RoomEvent.LocalTrackUnpublished, onParticipantStateChange); + room.on(RoomEvent.LocalTrackPublished, onLocalTrackPublished); + room.on(RoomEvent.LocalTrackUnpublished, onLocalTrackUnpublished); room.on(RoomEvent.MediaDevicesError, onMediaDeviceFailure); room.on(RoomEvent.EncryptionError, onEncryptionError); room.on(RoomEvent.ConnectionStateChanged, onParticipantStateChange); @@ -1277,17 +1438,17 @@ export function useInitializeCall() { room.off(RoomEvent.ParticipantDisconnected, onParticipantDisconnected); room.off(RoomEvent.TrackMuted, onParticipantStateChange); room.off(RoomEvent.TrackUnmuted, onParticipantStateChange); - room.off(RoomEvent.LocalTrackPublished, onParticipantStateChange); - room.off(RoomEvent.LocalTrackUnpublished, onParticipantStateChange); + room.off(RoomEvent.LocalTrackPublished, onLocalTrackPublished); + room.off(RoomEvent.LocalTrackUnpublished, onLocalTrackUnpublished); room.off(RoomEvent.MediaDevicesError, onMediaDeviceFailure); room.off(RoomEvent.EncryptionError, onEncryptionError); room.off(RoomEvent.ConnectionStateChanged, onParticipantStateChange); clearRemoteAudio(); listenersRegistered.current = false; room.disconnect(); - e2eeWorker.terminate(); + if (_e2eeWorker) _e2eeWorker.terminate(); }; - }, [noiseFilter]); + }, [noiseFilter, load]); // fetch call data for preview page useEffect(() => { diff --git a/packages/call/src/views/main/focused.tsx b/packages/call/src/views/main/focused.tsx index d52362b..f8239c5 100644 --- a/packages/call/src/views/main/focused.tsx +++ b/packages/call/src/views/main/focused.tsx @@ -1,13 +1,13 @@ import { RoomEvent } from "livekit-client"; import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; -import { useCall } from "../../store"; +import { useCall, getRoom } from "../../store"; import Base from "../../components/modals/base"; const SECONDARY_ROW_HEIGHT_PX = 180; const STACK_GAP_PX = 12; export default function View() { - const room = useCall((state) => state.room); + const room = getRoom(); const layoutVersion = useCall((state) => state.layoutVersion); const usersInFocusedViewHidden = useCall( @@ -16,6 +16,9 @@ export default function View() { const callIsFullscreen = useCall((state) => state.callIsFullscreen); const focusedParticipantId = useCall((state) => state.focusedParticipantId); + const focusedParticipantType = useCall( + (state) => state.focusedParticipantType, + ); const activeScreenShareParticipantIds = useCall( (state) => state.activeScreenShareParticipantIds, ); @@ -157,6 +160,11 @@ export default function View() { const focusedParticipant = getParticipantById(focusedParticipantId); const focusedParticipantHasActiveScreenShare = activeScreenShareParticipantIdSet.has(focusedParticipantId); + const focusedTileType: "user" | "stream" = + focusedParticipantType === "stream" && + focusedParticipantHasActiveScreenShare + ? "stream" + : "user"; const isImmersiveFocusedView = callIsFullscreen && usersInFocusedViewHidden; return ( @@ -179,7 +187,7 @@ export default function View() { diff --git a/packages/call/src/views/main/grid.tsx b/packages/call/src/views/main/grid.tsx index 833d7b5..956842d 100644 --- a/packages/call/src/views/main/grid.tsx +++ b/packages/call/src/views/main/grid.tsx @@ -1,6 +1,6 @@ import { RoomEvent } from "livekit-client"; import { useEffect, useMemo, useRef, useState } from "react"; -import { useCall } from "../../store"; +import { useCall, getRoom } from "../../store"; import Base from "../../components/modals/base"; const TILE_ASPECT_RATIO = 16 / 9; @@ -82,7 +82,7 @@ function calculateOptimalGridLayout( } export default function View() { - const room = useCall((state) => state.room); + const room = getRoom(); const layoutVersion = useCall((state) => state.layoutVersion); const activeScreenShareParticipantIds = useCall( (state) => state.activeScreenShareParticipantIds, diff --git a/packages/call/todo.md b/packages/call/todo.md index 952858f..4db4db0 100644 --- a/packages/call/todo.md +++ b/packages/call/todo.md @@ -1,4 +1,3 @@ -- Speaking indicator - Overlay for stream modals - User modals - Bg based on avatar @@ -11,3 +10,4 @@ - Disconnect - Desktop-App screenshares - Context menus +- Popout Window diff --git a/packages/chat/src/components/input.tsx b/packages/chat/src/components/input.tsx index 487c813..cf74848 100644 --- a/packages/chat/src/components/input.tsx +++ b/packages/chat/src/components/input.tsx @@ -97,6 +97,9 @@ export default function InputComponent({ > - {message.failed && message.message_state === "awaiting" && ( - - -

Failed to send message

-
- } /> -
- )} - + ( + <> + {grouped ? ( +

+ {new Date(message.send_time).toLocaleString([], { + hour: "2-digit", + minute: "2-digit", + })} +

+ ) : ( + + + + {user.display.slice(0, 2).toUpperCase()} + + + )} + {message.failed && message.message_state === "awaiting" && ( + + +

Failed to send message

+
+ } /> +
+ )} +
+ {!grouped && ( +
+

{user.display}

+

+ {new Date(message.send_time).toLocaleString([], { + hour: "2-digit", + minute: "2-digit", + })} +

+
+ )} + +
+ + )} + /> } /> diff --git a/packages/chat/src/screen.tsx b/packages/chat/src/screen.tsx index a23760d..44e581b 100644 --- a/packages/chat/src/screen.tsx +++ b/packages/chat/src/screen.tsx @@ -8,6 +8,7 @@ import Message from "./components/message"; import { PAGE_SIZE } from "./values"; import { useIsMobile } from "@tensamin/ui"; +import { Loader2 } from "lucide-react"; function getDistanceFromBottom(element: HTMLDivElement) { return element.scrollHeight - (element.scrollTop + element.clientHeight); @@ -101,12 +102,6 @@ export default function Screen() { const virtualRowCount = messages.length + (shouldShowConversationStart ? 1 : 0); - const messagesRef = React.useRef(messages); - - React.useEffect(() => { - messagesRef.current = messages; - }, [messages]); - const getItemKey = React.useCallback( (index: number) => { if (shouldShowConversationStart && index === 0) { @@ -114,9 +109,9 @@ export default function Screen() { } const messageIndex = shouldShowConversationStart ? index - 1 : index; - return messagesRef.current[messageIndex]?.send_time ?? index; + return messages[messageIndex]?.send_time ?? index; }, - [shouldShowConversationStart], + [shouldShowConversationStart, messages], ); const setMeasurementRef = React.useCallback( @@ -360,9 +355,38 @@ export default function Screen() { return; } - scrollRef.current.scrollTop = scrollRef.current.scrollHeight; - isAtBottomRef.current = true; - setHasScrolledToBottomInitially(true); + let rafId: number; + let stableFrames = 0; + let lastScrollHeight = 0; + + const settleToBottom = () => { + if (!scrollRef.current || hasScrolledToBottomInitially) { + return; + } + + scrollRef.current.scrollTop = scrollRef.current.scrollHeight; + const currentScrollHeight = scrollRef.current.scrollHeight; + + if (currentScrollHeight === lastScrollHeight) { + stableFrames++; + } else { + stableFrames = 0; + lastScrollHeight = currentScrollHeight; + } + + if (stableFrames >= 2) { + isAtBottomRef.current = true; + setHasScrolledToBottomInitially(true); + } else { + rafId = requestAnimationFrame(settleToBottom); + } + }; + + settleToBottom(); + + return () => { + cancelAnimationFrame(rafId); + }; }, [hasScrolledToBottomInitially, virtualRowCount]); React.useLayoutEffect(() => { @@ -435,13 +459,26 @@ export default function Screen() {
+ {messagesQuery.isPending && ( +
+

+ + Loading... +

+
+ )} + {messagesQuery.isFetchingNextPage && ( +
+ +
+ )}
-
- This is the start of your conversation with{" "} +
+ Conversation start
@@ -481,6 +517,13 @@ export default function Screen() { return null; } + const lastMessage = messages[messageIndex - 1]; + const isGrouped = + lastMessage && + lastMessage.sent_by_self === message.sent_by_self && + Math.round(lastMessage.send_time / 10000) === + Math.round(message.send_time / 10000); + return (
- +
); })} @@ -509,17 +551,25 @@ export default function Screen() { className="pointer-events-none absolute left-0 top-0 -z-10 overflow-hidden opacity-0" style={{ width: scrollWidth > 0 ? `${scrollWidth}px` : "100%" }} > - {messages.map((message) => ( -
{ - setMeasurementRef(message.send_time, element); - }} - style={{ padding: "4px 0" }} - > - -
- ))} + {messages.map((message, messageIndex) => { + const lastMessage = messages[messageIndex - 1]; + const isGrouped = + lastMessage && + lastMessage.sent_by_self === message.sent_by_self && + Math.round(lastMessage.send_time / 10000) === + Math.round(message.send_time / 10000); + + return ( +
{ + setMeasurementRef(message.send_time, element); + }} + > + +
+ ); + })}
); diff --git a/packages/chat/todo.md b/packages/chat/todo.md new file mode 100644 index 0000000..122f14e --- /dev/null +++ b/packages/chat/todo.md @@ -0,0 +1 @@ +- Add context menu to messages diff --git a/packages/markdown/src/input.tsx b/packages/markdown/src/input.tsx index f44ced6..3222ddf 100644 --- a/packages/markdown/src/input.tsx +++ b/packages/markdown/src/input.tsx @@ -23,6 +23,7 @@ import { indentWithTab, } from "@codemirror/commands"; import { useEffect, useRef } from "react"; +import type { CSSProperties } from "react"; import { collectInlineRanges, ensureMarkdownStyles } from "./markdown"; @@ -33,8 +34,36 @@ export type InputProps = { setValue: (value: string) => void; onSubmit?: () => void; invertEnterBehavior?: boolean; + styled?: boolean; + fontSize?: CSSProperties["fontSize"]; + paddingX?: CSSProperties["padding"]; + paddingY?: CSSProperties["padding"]; + className?: string; }; +type InputStyle = CSSProperties & { + "--tm-md-content-padding"?: string; +}; + +function toCssLength(value: CSSProperties["padding"]): string | undefined { + if (value === undefined) { + return undefined; + } + + return typeof value === "number" ? `${value}px` : value; +} + +function toCssPadding( + vertical: CSSProperties["padding"], + horizontal: CSSProperties["padding"], + styled: boolean, +): string { + const defaultVertical = styled ? "0.25rem" : "0"; + const defaultHorizontal = styled ? "0.625rem" : "0"; + + return `${toCssLength(vertical) ?? defaultVertical} ${toCssLength(horizontal) ?? defaultHorizontal}`; +} + type TokenRange = { from: number; to: number; @@ -80,6 +109,10 @@ const markdownDecorations = ViewPlugin.fromClass( export default function Input(props: InputProps) { ensureMarkdownStyles(); + const shellClassName = props.styled + ? "min-h-8 w-full min-w-0 rounded-lg border border-input bg-transparent text-base transition-colors outline-none placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40" + : ""; + const elementRef = useRef(null); const viewRef = useRef(undefined); const ignoreSyncRef = useRef(false); @@ -143,7 +176,22 @@ export default function Input(props: InputProps) { }); }, [props.value]); - return
; + return ( +
+ ); } /** @@ -204,7 +252,7 @@ function createEditorExtensions( }), EditorView.theme({ "&": { - fontSize: "1rem", + fontSize: "inherit", }, "&.cm-editor": { width: "100%", diff --git a/packages/markdown/src/markdown.tsx b/packages/markdown/src/markdown.tsx index c3a17a6..46ebb92 100644 --- a/packages/markdown/src/markdown.tsx +++ b/packages/markdown/src/markdown.tsx @@ -560,7 +560,7 @@ export function renderBlocks(blocks: MarkdownBlock[]): React.ReactElement { } return ( -

+

{block.text.split("\n").map((line, lineIndex) => ( {lineIndex > 0 ?
: null} @@ -645,7 +645,6 @@ export const markdownStyles = ` .tm-md-h4 { font-size: 1.1rem; } .tm-md-h5 { font-size: 1rem; } .tm-md-h6 { font-size: 0.95rem; opacity: 0.9; } -.tm-md-p { margin: 0.25rem 0; } .tm-md-blockquote { margin: 0.45rem 0; padding-left: 0.75rem; opacity: 0.95; } .tm-md-blockquote p { margin: 0.2rem 0; } .tm-md-pre { margin: 0.45rem 0; padding: 0.65rem 0.75rem; border-radius: 0.5rem; background: hsl(var(--muted)); overflow-x: auto; } @@ -665,12 +664,12 @@ export const markdownStyles = ` .tm-md-table th { background: hsl(var(--muted)); font-weight: 600; } .tm-md-hr { margin: 0.55rem 0; } -.cm-editor.tm-md-editor { border-radius: 0.65rem; background: hsl(var(--card)); caret-color: var(--foreground); } +.cm-editor.tm-md-editor { border-radius: inherit; background: transparent; caret-color: var(--foreground); } .cm-editor.tm-md-editor.cm-focused { outline: none; box-shadow: none; } .cm-editor.tm-md-editor .cm-scroller { font-family: inherit; line-height: 1.55; max-height: 30vh; overflow-y: auto; overflow-x: hidden; } .cm-editor.tm-md-editor .cm-content { caret-color: var(--foreground); } -.cm-editor.tm-md-editor .cm-content { padding: 0.7rem 0.85rem; min-height: 2.75rem; } -.cm-editor.tm-md-editor .cm-line { padding: 0 1px; color: hsl(var(--foreground)); } +.cm-editor.tm-md-editor .cm-content { padding: var(--tm-md-content-padding, 0.25rem 0.625rem); min-height: 2rem; } +.cm-editor.tm-md-editor .cm-line { padding: 0; color: hsl(var(--foreground)); } .cm-editor.tm-md-editor .tm-md-hidden-token { color: transparent; opacity: 0; font-size: inherit; } .cm-editor.tm-md-editor .tm-md-code-line { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; background: hsl(var(--muted)); border-radius: 0.3rem; } `; diff --git a/packages/notifications/package.json b/packages/notifications/package.json index af90c45..a6b06be 100644 --- a/packages/notifications/package.json +++ b/packages/notifications/package.json @@ -12,6 +12,7 @@ "build": "tsc -p tsconfig.json --noEmit" }, "dependencies": { + "@tanstack/react-router": "^1.169.1", "@tauri-apps/api": "^2.11.0", "@tensamin/crypto": "workspace:*", "@tensamin/shared": "workspace:*", diff --git a/packages/notifications/src/context.tsx b/packages/notifications/src/context.tsx index 4e433a3..8da45f4 100644 --- a/packages/notifications/src/context.tsx +++ b/packages/notifications/src/context.tsx @@ -10,25 +10,27 @@ import { message as messageSchema } from "@tensamin/shared/data"; import { Avatar, AvatarFallback, AvatarImage } from "@tensamin/ui"; import { isTauri } from "@tauri-apps/api/core"; import { useSession } from "@tensamin/storage/session"; +import { useNavigate } from "@tanstack/react-router"; export const context = createContext(undefined); -function reduceDisplay(display: string) { - const words = display.split(" "); - if (words.length === 1) { - return display.slice(0, 2).toUpperCase(); - } else { - return words[0].charAt(0).toUpperCase() + words[1].charAt(0).toUpperCase(); - } +async function requestNotificationPermission() { + if (!("Notification" in window)) return false; + + if (Notification.permission === "granted") return true; + + const permission = await Notification.requestPermission(); + return permission === "granted"; } export default function Provider(props: { children: React.ReactNode }) { - const { subscribePush } = useTTP(); + const { subscribePush, send } = useTTP(); const { load } = useStorage(); const { get } = useUser(); const { decryptText, getSharedSecret } = useCrypto(); const { addLiveMessage, userId } = useChat(); const { moveUserIdToTop } = useSession(); + const navigate = useNavigate(); useEffect(() => { return subscribePush(async (ttpMessage) => { @@ -49,7 +51,32 @@ export default function Provider(props: { children: React.ReactNode }) { message.content, ); - console.log(userId, sender_id, userId === sender_id); + // Update message state + if ( + (await load("settings.read_confirmations")) && + userId === sender_id + ) { + void send( + "message_state", + { + message_state: "read", + }, + { + id: ttpMessage.id, + }, + ); + } else { + void send( + "message_state", + { + message_state: "received", + }, + { + id: ttpMessage.id, + }, + ); + } + if (userId === sender_id) { addLiveMessage({ ...message, @@ -60,25 +87,48 @@ export default function Provider(props: { children: React.ReactNode }) { return; } - // add notification symbol to conversation cards + // todo: add notification symbol to conversation cards (incl. message start) moveUserIdToTop(sender_id); if (isTauri()) { console.log("weewoo"); } else { - sonnerToast(user.display, { - classNames: { - content: "pl-4", - }, - description: decryptedContent, - icon: ( - - - {reduceDisplay(user.display)} - - ), - }); + const hasPermissions = await requestNotificationPermission(); + + if (hasPermissions) { + const notification = new Notification(user.display, { + body: decryptedContent, + icon: user.avatar || user.display.slice(0, 2).toUpperCase(), + badge: user.avatar || user.display.slice(0, 2).toUpperCase(), + tag: `message-${user.user_id}`, + silent: true, + }); + + notification.onclick = () => { + window.focus(); + navigate({ + to: `/chat?id=${user.user_id}`, + }); + + notification.close(); + }; + } else { + sonnerToast(user.display, { + classNames: { + content: "pl-4", + }, + description: decryptedContent, + icon: ( + + + + {user.display.slice(0, 2).toUpperCase()} + + + ), + }); + } } } }); @@ -91,6 +141,8 @@ export default function Provider(props: { children: React.ReactNode }) { addLiveMessage, userId, moveUserIdToTop, + send, + navigate, ]); return ( diff --git a/packages/shared/src/data.ts b/packages/shared/src/data.ts index a059e9c..2210192 100644 --- a/packages/shared/src/data.ts +++ b/packages/shared/src/data.ts @@ -48,6 +48,31 @@ export type Communities = z.infer< export type Calls = z.infer; // TTP +const user = z.object({ + about: z.string().max(255).optional(), + avatar: z.string().optional(), + display: z.string().min(1).max(15), + iota_id: z.number(), + omikron_connections: z.array(z.number()), + omikron_id: z.number().optional(), + online_status: z.enum([ + "user_offline", + "user_online", + "user_dnd", + "user_idle", + "user_wc", + "user_borked", + "iota_offline", + "iota_online", + "iota_borked", + ]), + public_key: z.base64(), + status: z.string().max(15).optional(), + sub_end: z.number(), + sub_level: z.number(), + user_id: z.number(), + username: z.string().min(1).max(15), +}); export const ttp = { identification: { request: z.object({ @@ -90,33 +115,14 @@ export const ttp = { }, get_user_data: { request: z.object({ - user_id: z.number(), - }), - response: z.object({ - about: z.string().max(255).optional(), - avatar: z.string().optional(), - display: z.string().max(15), - iota_id: z.number(), - omikron_connections: z.array(z.number()), - omikron_id: z.number().optional(), - online_status: z.enum([ - "user_offline", - "user_online", - "user_dnd", - "user_idle", - "user_wc", - "user_borked", - "iota_offline", - "iota_online", - "iota_borked", - ]), - public_key: z.base64(), - status: z.string().max(15).optional(), - sub_end: z.number(), - sub_level: z.number(), - user_id: z.number(), - username: z.string().max(15), + user_id: z.number().optional(), + username: z.string().optional(), }), + response: user, + }, + change_user_data: { + request: user.partial(), + response: z.object({}), }, ping: { request: z.object({ @@ -161,11 +167,17 @@ export const ttp = { response: z.object({}), }, message_state: { - request: z.object({ - chat_partner_id: z.number(), - send_time: z.number(), - message_state: message.shape.message_state, - }), + request: z + .object({ + chat_partner_id: z.number(), + send_time: z.number(), + message_state: message.shape.message_state, + }) + .or( + z.object({ + message_state: message.shape.message_state, + }), + ), response: z.object({ chat_partner_id: z.number(), message_state: message.shape.message_state, @@ -244,6 +256,9 @@ export interface Storage extends SettingsStorageDefaults { legal_docs: z.infer; cached_contacts: Contacts; cached_communities: Communities; + ttp_url: string; + call_mute_range_start: number; + call_mute_range_end: number; } export const storageDefaults: Storage = { @@ -276,4 +291,32 @@ export const storageDefaults: Storage = { }, cached_contacts: [], cached_communities: [], + ttp_url: "https://tensamin.net:959", + call_mute_range_start: -55, + call_mute_range_end: -45, }; + +// User Status +export function getStatusColor( + status: z.infer, +) { + switch (status) { + case "user_online": + return "#22c55e"; + case "iota_online": + return "#22c55e"; + case "user_dnd": + return "#ef4444"; + case "user_idle": + return "#f59e0b"; + case "user_wc": + return "#3b82f6"; + case "user_borked": + case "iota_borked": + return "#6b7280"; + case "user_offline": + case "iota_offline": + default: + return "#9ca3af"; + } +} diff --git a/packages/shared/src/settings.ts b/packages/shared/src/settings.ts index 0099f64..aacc162 100644 --- a/packages/shared/src/settings.ts +++ b/packages/shared/src/settings.ts @@ -28,6 +28,21 @@ const settings = { type: "boolean", default: false, }, + read_confirmations: { + display: "Enable Read Confirmations", + type: "boolean", + default: true, + }, + receive_confirmations: { + display: "Enable Receive Confirmations", + type: "boolean", + default: true, + }, + show_start_of_last_message_in_sidebar: { + display: "Show Start of Last Message in Sidebar", + type: "boolean", + default: true, + }, }, }, application: { @@ -35,6 +50,7 @@ const settings = { }, } as const satisfies SettingsSchema; +// Assemble storage defaults export default settings; type BooleanSettingNames = { diff --git a/packages/storage/src/session.tsx b/packages/storage/src/session.tsx index 03b3826..d992a03 100644 --- a/packages/storage/src/session.tsx +++ b/packages/storage/src/session.tsx @@ -14,6 +14,7 @@ interface SessionContextType { communities: Communities; calls: Calls; moveUserIdToTop: (userId: number) => void; + insertContact: (userId: number) => void; } const SessionContext = createContext(undefined); @@ -69,9 +70,31 @@ export default function SessionProvider({ children }: { children: ReactNode }) { }); }; + const insertContact = (userId: number) => { + setContacts((prevContacts) => { + if (prevContacts.some((contact) => contact.user_id === userId)) { + return prevContacts; + } + + const newUser = { + user_id: userId, + last_message_at: new Date().getTime(), + messages: [], + } satisfies Contacts[0]; + + return [newUser, ...prevContacts]; + }); + }; + return ( {children} diff --git a/packages/ttp/src/context.tsx b/packages/ttp/src/context.tsx index f1c30aa..d33313d 100644 --- a/packages/ttp/src/context.tsx +++ b/packages/ttp/src/context.tsx @@ -24,7 +24,6 @@ import { RECONNECT_RESET, RECONNECT_TRIES, RETRY_INTERVAL, - TRANSPORT_URL, } from "./values"; import { type Calls, @@ -192,6 +191,15 @@ export function Provider(props: { typeof createTransportClient > | null>(null); const identificationStartedRef = useRef(false); + const identificationCancelRef = useRef(false); + + // Load ttp url + const [ttpUrl, setTtpUrl] = useState(null); + useEffect(() => { + load("ttp_url").then((url) => { + setTtpUrl(url); + }); + }, [load]); /** * Sends typed protocol messages through the active transport client. @@ -235,6 +243,23 @@ export function Provider(props: { return client.subscribePush(handler); }, []); + // Check for error_no_iota + useEffect(() => { + if (!connected) return; + + return subscribePush((message) => { + if (message.type !== "error_no_iota") return; + + identificationCancelRef.current = true; + setIdentified(false); + setIdentifying(false); + setError("We couldn't reach your Iota"); + setErrorDescription( + "You could try to restart your Iota, check for updates or check your network connection.", + ); + }); + }, [connected, subscribePush]); + useEffect(() => { if (!connected || !identified) { return; @@ -266,6 +291,10 @@ export function Provider(props: { }, [connected, identified, send]); useEffect(() => { + if (!ttpUrl) { + return; + } + let attempts = 0; let reconnectTimer: ReturnType | null = null; let reconnectResetTimer: ReturnType | null = null; @@ -343,7 +372,7 @@ export function Provider(props: { const transportClient = !props.blockConnection ? createTransportClient(schemas, { - url: TRANSPORT_URL, + url: ttpUrl, onReadyStateChange: (state) => { currentReadyState = state; setReadyState(state); @@ -352,6 +381,7 @@ export function Provider(props: { clearReconnectTimer(); scheduleReconnectReset(); identificationStartedRef.current = false; + identificationCancelRef.current = false; setConnected(true); setIdentified(false); setError(""); @@ -392,8 +422,12 @@ export function Provider(props: { return; } + if (!ttpUrl) { + return; + } + try { - await transportClient?.connect(TRANSPORT_URL); + await transportClient?.connect(ttpUrl); } catch (connectError) { if (disposed) { return; @@ -460,7 +494,7 @@ export function Provider(props: { setIdentifying(false); identificationStartedRef.current = false; }; - }, [props.blockConnection]); + }, [props.blockConnection, ttpUrl]); useEffect(() => { if (!connected) { @@ -468,6 +502,11 @@ export function Provider(props: { return; } + if (identificationCancelRef.current) { + identificationStartedRef.current = false; + return; + } + if (identificationStartedRef.current) { return; } @@ -536,10 +575,12 @@ export function Provider(props: { const finalResponse = await send("challenge_response", { challenge: decryptedChallenge, }).catch((error) => { - setError("Identification Failed"); - setErrorDescription( - "Unable to complete secure identification. Please verify your credentials and try again.", - ); + if (!identificationCancelRef.current) { + setError("Identification Failed"); + setErrorDescription( + "Unable to complete secure identification. Please verify your credentials and try again.", + ); + } throw error; }); @@ -547,7 +588,7 @@ export function Provider(props: { setFreshContacts(finalResponse.data.contacts); setFreshCommunities(finalResponse.data.communities); setFreshCalls(finalResponse.data.calls); - if (cancelled) { + if (cancelled || identificationCancelRef.current) { return; } @@ -559,6 +600,10 @@ export function Provider(props: { return; } + if (identificationCancelRef.current) { + return; + } + if (isStopSendingError(identificationError)) { setError("Connection closed"); setErrorDescription( @@ -589,7 +634,7 @@ export function Provider(props: { : "Unable to complete secure identification because the transport request failed.", ); } finally { - if (!cancelled) { + if (!cancelled && !identificationCancelRef.current) { setIdentifying(false); } } @@ -603,14 +648,19 @@ export function Provider(props: { }, [connected, decrypt, getSharedSecret, load, send]); const progress = useMemo(() => { + if (!ttpUrl) return 10; if (readyState === READY_STATE.CONNECTING) return 30; if (!connected) return 45; if (identifying) return 75; if (!identified) return 90; return 100; - }, [connected, identified, identifying, readyState]); + }, [connected, identified, identifying, readyState, ttpUrl]); const loadingTitle = useMemo(() => { + if (!ttpUrl) { + return "Looking up configuration"; + } + if (readyState === READY_STATE.CONNECTING || !connected) { return "Connecting to Tensamin"; } @@ -620,9 +670,13 @@ export function Provider(props: { } return "Loading"; - }, [connected, identified, identifying, readyState]); + }, [connected, identified, identifying, readyState, ttpUrl]); const loadingDescription = useMemo(() => { + if (!ttpUrl) { + return "Loading connection details"; + } + if (readyState === READY_STATE.CONNECTING || !connected) { return "Establishing transport channel"; } @@ -632,13 +686,13 @@ export function Provider(props: { } return undefined; - }, [connected, identified, identifying, readyState]); + }, [connected, identified, identifying, readyState, ttpUrl]); if (error !== "" && errorDescription !== "") { return ; } - if (!connected || !identified) { + if (!connected || !identified || !ttpUrl) { return (