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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,12 @@ if (getPlatform() == Platform.Android) {
- Android Home packs tighter, Desktop unchanged: card sides 8dp (`cardSidePadding`), Quick picks rows 56dp, no 8dp/5dp around Quick picks' own header, no 8dp spacer over each section title. Android's card floor is artwork + `cardTextBlockFloor()`, the tallest text block (two `titleSmall` lines plus the subtitle row) measured with `rememberTextMeasurer`: Desktop's fixed 70dp counts Poppins' line gap (Skia) and left ~10dp spare under every Android card. Keep the floor: without it a row takes the height of the cards on screen and Home jumps when a two-line title scrolls in. Titles stay two lines, as on Spotify's song cards; the spare line belongs under the subtitle, never between title and subtitle.
- `AppTheme {}` with no arguments is the app's default cyan dark theme, not the user's: anything drawn outside `App()` (Desktop's `LibrarySyncLoginPrompt`) must read theme mode, colour source and custom colour the way `App()` does. Force-dark `typo()` paints `headlineMedium`/`bodyMedium` in its #A8A8A8 body grey, so text on a scrim (the daily discover hero) names `onSurface`/`onSurfaceVariant`.

- **Listen Together: required-name feedback, room QR codes and a room link (2026-11-02)**: Create and Join no longer go grey over a missing name or code. They stay live, and a tap marks the field, says what is missing and moves focus to the name (`RoomFormProblem`, `roomFormProblems()` in `utils/ListenTogetherLink.kt`). The field is labelled Required throughout. A tap while disconnected connects first and then carries on (`whenConnected`), because `ListenTogetherSession.createRoom` drops its message with no error when the socket is down; only that wait disables the buttons.
- **QR**: the host's poster gains a button opening `RoomQrDialog`. `QrCodeImage` (`ui/component`, moved out of Login Sync's Desktop dialog) draws any text over `encodeQrMatrix` (expect/actual, since ZXing is a plain JVM artifact declared per platform). `RoomQrScanner` is expect/actual: Android uses the camera in a sheet built from Login Sync's pieces; Desktop has no camera API, so it reads the code from an image file through `showOpenFileDialog`.
- **The link is `simpmusic://listen-together?code=X`** (`listenTogetherLink`), handled by the router in `App.kt`, since both platforms already register the scheme. Not `https://simpmusic.org/app/…`: `simpmusic.org/.well-known/assetlinks.json` redirects to `www` (Android does not follow redirects for it) and `www` answers 404, and so does `/app/*`, so a camera app would land on a 404 page. `roomCodeFromText` and the router already accept the https form; once the site serves both, changing `listenTogetherLink` is the whole migration. iOS has no client.
- **A scanned code or a link only fills in the form, it never joins.** It came from outside the app, and joining shows the user's name to that room. `roomCodeFromText` returns only a validated 8-character code, so a QR code cannot open a page either. It also reads Metrolist's `https://metrolist.cc/listen?code=X`, since rooms are shared; a phone's camera cannot open that link in SimpMusic because the domain is not ours, but the in-app scanner and a paste into the code field can.
- A room exists on one server, so a code or QR code from a custom server means nothing to someone on the default one. Deliberately not carried in the link: a QR code could then point the app at any server.

## 🔄 CLAUDE.md Auto-Update Rule (MANDATORY)

After completing any of the following types of changes, the AI agent **MUST** update this CLAUDE.md file:
Expand Down
4 changes: 2 additions & 2 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ kotlin {
implementation(projects.castEmpty)
}

// Login sync QR scanner: CameraX + ZXing, not ML Kit, which F-Droid rejects as proprietary
// QR codes and their scanner: CameraX + ZXing, not ML Kit, which F-Droid rejects as proprietary
implementation(libs.camera.camera2)
implementation(libs.camera.lifecycle)
implementation(libs.camera.view)
Expand Down Expand Up @@ -202,7 +202,7 @@ kotlin {
implementation(projects.mediaJvmUi)
// macOS: hand window drags to the Window Server (ui/component/MacWindowDrag.kt)
implementation(libs.jna)
// Login sync QR code
// QR codes
implementation(libs.zxing.core)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.maxrave.simpmusic.expect.ui

import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType
import com.google.zxing.qrcode.QRCodeWriter
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel

actual fun encodeQrMatrix(text: String): QrMatrix {
val matrix =
QRCodeWriter().encode(
text,
BarcodeFormat.QR_CODE,
0,
0,
mapOf(EncodeHintType.MARGIN to 2, EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.M),
)
return QrMatrix(matrix.width, BooleanArray(matrix.width * matrix.width) { matrix[it % matrix.width, it / matrix.width] })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package com.maxrave.simpmusic.expect.ui

import android.Manifest
import android.content.pm.PackageManager
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.lifecycle.compose.LifecycleResumeEffect
import com.maxrave.simpmusic.extension.findActivity
import com.maxrave.simpmusic.ui.component.QrScanner
import com.maxrave.simpmusic.ui.component.rememberSurfaceDarkColors
import com.maxrave.simpmusic.ui.icon.Close
import com.maxrave.simpmusic.ui.icon.SimpIcons
import com.maxrave.simpmusic.ui.theme.typo
import com.maxrave.simpmusic.utils.roomCodeFromText
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.stringResource
import simpmusic.composeapp.generated.resources.Res
import simpmusic.composeapp.generated.resources.cancel
import simpmusic.composeapp.generated.resources.login_sync_allow_camera
import simpmusic.composeapp.generated.resources.login_sync_no_camera
import simpmusic.composeapp.generated.resources.login_sync_open_settings
import simpmusic.composeapp.generated.resources.lt_scan_camera_blocked
import simpmusic.composeapp.generated.resources.lt_scan_camera_needed
import simpmusic.composeapp.generated.resources.lt_scan_hint
import simpmusic.composeapp.generated.resources.lt_scan_not_a_room
import simpmusic.composeapp.generated.resources.lt_scan_qr

@OptIn(ExperimentalMaterial3Api::class)
@Composable
actual fun RoomQrScanner(
onRoomCode: (String) -> Unit,
onUnreadable: () -> Unit,
onDismiss: () -> Unit,
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val colors = rememberSurfaceDarkColors()

fun hasCamera() = ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED

var cameraAllowed by remember { mutableStateOf(hasCamera()) }
var cameraBlocked by remember { mutableStateOf(false) }
var cameraUnavailable by remember { mutableStateOf(false) }
var notARoom by remember { mutableStateOf(false) }
// The camera keeps reporting the same code until the sheet has finished sliding away.
var finished by remember { mutableStateOf(false) }

val permissionLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
cameraAllowed = granted
// Rationale is false after a denial only when the system will not ask again.
cameraBlocked = !granted && !context.findActivity().shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)
}

// Back from the system settings page with the camera now allowed.
LifecycleResumeEffect(Unit) {
if (hasCamera()) cameraAllowed = true
onPauseOrDispose { }
}

fun hideThen(action: () -> Unit) {
scope.launch { sheetState.hide() }.invokeOnCompletion { action() }
}

ModalBottomSheet(
onDismissRequest = onDismiss,
sheetState = sheetState,
containerColor = Color.Transparent,
contentColor = Color.Transparent,
dragHandle = null,
scrimColor = Color.Black.copy(alpha = .5f),
contentWindowInsets = { WindowInsets(0, 0, 0, 0) },
) {
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
colors = CardDefaults.cardColors().copy(containerColor = colors.container),
) {
Column(
modifier =
Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState())
.navigationBarsPadding()
.padding(bottom = 24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(Modifier.height(8.dp))
Box(
Modifier
.width(60.dp)
.height(4.dp)
.clip(RoundedCornerShape(50))
.background(colors.handle),
)
Row(
modifier = Modifier.fillMaxWidth().padding(start = 24.dp, end = 8.dp, top = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = stringResource(Res.string.lt_scan_qr),
style = typo().titleMedium,
color = colors.content,
modifier = Modifier.weight(1f),
)
IconButton(onClick = { hideThen(onDismiss) }) {
Icon(imageVector = SimpIcons.Close, contentDescription = stringResource(Res.string.cancel), tint = colors.content)
}
}
Text(
text = stringResource(if (notARoom) Res.string.lt_scan_not_a_room else Res.string.lt_scan_hint),
style = typo().bodySmall,
color = if (notARoom) MaterialTheme.colorScheme.error else colors.subtitle,
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp),
)
Spacer(Modifier.height(20.dp))
val scanning = cameraAllowed && !cameraUnavailable
Box(
modifier =
Modifier
.padding(horizontal = 24.dp)
// Square on a phone; capped so it still fits a phone held sideways.
.widthIn(max = 340.dp)
.fillMaxWidth()
.aspectRatio(1f)
.clip(RoundedCornerShape(24.dp))
.background(if (scanning) Color.Black else colors.disabled.copy(alpha = 0.15f)),
contentAlignment = Alignment.Center,
) {
when {
cameraUnavailable -> {
Status(stringResource(Res.string.login_sync_no_camera), progress = false)
}

cameraAllowed -> {
QrScanner(
onResult = { text ->
val code = roomCodeFromText(text)
if (code == null) {
notARoom = true
} else if (!finished) {
finished = true
hideThen { onRoomCode(code) }
}
},
onCameraUnavailable = { cameraUnavailable = true },
modifier = Modifier.fillMaxSize(),
)
ViewfinderCorners(Modifier.fillMaxSize().padding(20.dp))
}

cameraBlocked -> {
Status(stringResource(Res.string.lt_scan_camera_blocked), progress = false) {
SheetButton(stringResource(Res.string.login_sync_open_settings)) { context.openAppSettings() }
}
}

else -> {
Status(stringResource(Res.string.lt_scan_camera_needed), progress = false) {
SheetButton(stringResource(Res.string.login_sync_allow_camera)) {
permissionLauncher.launch(Manifest.permission.CAMERA)
}
}
}
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions composeApp/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,20 @@
<string name="lt_waiting_approval">Waiting for the host</string>
<string name="lt_waiting_approval_desc">They need to let you in. If the code is wrong you will get an error instead.</string>
<string name="lt_cancel_join">Cancel</string>
<string name="lt_required">Required</string>
<string name="lt_display_name_required">Enter a display name to create or join a room</string>
<string name="lt_room_code_incomplete">Enter the room code, %1$d letters and numbers</string>
<string name="lt_show_qr">Show QR code</string>
<string name="lt_qr_title">Scan to join</string>
<string name="lt_qr_desc">Scan it in SimpMusic, or with a phone's camera app if SimpMusic is installed there. Everyone has to be on the same server.</string>
<string name="lt_scan_qr">Scan QR code</string>
<string name="lt_scan_qr_image">Read QR code from an image</string>
<string name="lt_scan_hint">Point the camera at the room's QR code</string>
<string name="lt_scan_not_a_room">That QR code is not a Listen Together room</string>
<string name="lt_scan_unreadable">No Listen Together QR code found in that image</string>
<string name="lt_scan_camera_needed">SimpMusic uses the camera only to scan the room's QR code.</string>
<string name="lt_scan_camera_blocked">Camera access is turned off for SimpMusic. Turn it on in Settings to scan the code.</string>
<string name="lt_already_in_room">Leave this room before joining another one</string>
<string name="share_lyrics">Share lyrics</string>
<string name="share_lyrics_select_title">Select lines</string>
<string name="share_lyrics_selected_count">%1$d lines selected</string>
Expand Down
20 changes: 20 additions & 0 deletions composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import com.maxrave.simpmusic.ui.icon.ArrowForwardIos
import com.maxrave.simpmusic.ui.icon.SimpIcons
import com.maxrave.simpmusic.ui.navigation.destination.home.AnalyticsDestination
import com.maxrave.simpmusic.ui.navigation.destination.home.HomeDestination
import com.maxrave.simpmusic.ui.navigation.destination.home.ListenTogetherDestination
import com.maxrave.simpmusic.ui.navigation.destination.home.NotificationDestination
import com.maxrave.simpmusic.ui.navigation.destination.home.WrappedDestination
import com.maxrave.simpmusic.ui.navigation.destination.library.LibraryDestination
Expand All @@ -107,9 +108,11 @@ import com.maxrave.simpmusic.ui.theme.desktopWindowLight
import com.maxrave.simpmusic.ui.theme.fontFamily
import com.maxrave.simpmusic.ui.theme.parseThemeColorHex
import com.maxrave.simpmusic.ui.theme.typo
import com.maxrave.simpmusic.utils.LISTEN_TOGETHER_APP_PATH
import com.maxrave.simpmusic.utils.VersionManager
import com.maxrave.simpmusic.utils.isAppLinkAvailable
import com.maxrave.simpmusic.utils.libraryTabOf
import com.maxrave.simpmusic.utils.normalizedRoomCode
import com.maxrave.simpmusic.viewModel.SharedViewModel
import com.mikepenz.markdown.m3.Markdown
import com.mikepenz.markdown.m3.markdownTypography
Expand Down Expand Up @@ -232,6 +235,10 @@ fun App(
val data = intent.data
Logger.d("MainActivity", "onCreate: $data")
if (data != null) {
// A link that launched the app can get here before NavHost, composed further down, has
// set its graph, and navigating then throws. Wait here, before any setIntent(null):
// clearing the intent changes this effect's key and would cancel the wait.
navController.currentBackStackEntryFlow.first()
if (data.scheme == "simpmusic" && data.host == "notification") {
viewModel.setIntent(null)
navController.navigate(
Expand Down Expand Up @@ -366,6 +373,19 @@ fun App(
}
}

// simpmusic://listen-together?code=ROOMCODE — a room's QR code, read by the phone's
// camera app. It only fills in the form: joining a room stays the user's tap.
LISTEN_TOGETHER_APP_PATH -> {
val roomCode = normalizedRoomCode(data.getQueryParameter("code"))
if (roomCode != null) {
viewModel.requestListenTogetherRoom(roomCode)
// Single top: already on Listen Together, that screen takes the request.
navController.navigate(ListenTogetherDestination) { launchSingleTop = true }
} else {
viewModel.makeToast(getString(Res.string.this_link_is_not_supported))
}
}

// simpmusic://recognize — the Quick Settings tile (Android only): Search with the
// song recognition sheet open.
"recognize" -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.maxrave.simpmusic.expect.ui

/** A QR code's modules, including its quiet zone. `true` is a dark module. */
class QrMatrix(
val size: Int,
private val modules: BooleanArray,
) {
operator fun get(
x: Int,
y: Int,
): Boolean = modules[y * size + x]
}

/** ZXing is a plain JVM artifact, so each platform declares it and calls it itself. */
expect fun encodeQrMatrix(text: String): QrMatrix
Loading