Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

update ui

Prateek Sunal6bfd3f6e7d23
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt
index 5330135f38..6ab0513355 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt
@@ -333,7 +333,9 @@ fun HomeView(
onOpenAttachment = { attachment ->
openAttachment(context, attachment)
},
- onStartDownload = { store.startModelDownload(userInitiated = true) }
+ onStartDownload = { userInitiated ->
+ store.startModelDownload(userInitiated = userInitiated)
+ }
)
}
composable(
@@ -419,9 +421,14 @@ fun HomeView(
deleteSessionTarget = session
},
onSync = {
- store.syncNow { message ->
- Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
- }
+ store.syncNow(
+ onSuccess = {
+ Toast.makeText(context, "Sync complete", Toast.LENGTH_SHORT).show()
+ },
+ onError = { message ->
+ Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
+ }
+ )
},
onOpenSettings = {
navController.navigate(HomeRoute.Settings)
@@ -492,20 +499,29 @@ fun HomeView(
Text(text = "Logs", style = EnsuTypography.h3Bold, color = EnsuColor.textPrimary())
Text(text = "Export or share logs for support.", style = EnsuTypography.body, color = EnsuColor.textMuted())
Row(horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)) {
- TextButton(onClick = {
- showLogShareDialog = false
- shareLogs()
- }) {
+ TextButton(
+ onClick = {
+ showLogShareDialog = false
+ shareLogs()
+ },
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
+ ) {
Text(text = "Share")
}
- TextButton(onClick = {
- showLogShareDialog = false
- exportLogs()
- }) {
+ TextButton(
+ onClick = {
+ showLogShareDialog = false
+ exportLogs()
+ },
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
+ ) {
Text(text = "Export")
}
Spacer(modifier = Modifier.weight(1f))
- TextButton(onClick = { showLogShareDialog = false }) {
+ TextButton(
+ onClick = { showLogShareDialog = false },
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textMuted())
+ ) {
Text(text = "Cancel")
}
}
@@ -534,7 +550,7 @@ fun HomeView(
navController.navigate(HomeRoute.DeveloperSettings)
scope.launch { drawerState.close() }
},
- colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.accent())
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
) {
Text(text = "Yes")
}
@@ -730,7 +746,10 @@ private fun AttachmentDownloadsDialog(
modifier = Modifier.padding(end = EnsuSpacing.xs.dp)
)
if (item.status == AttachmentDownloadStatus.Queued || item.status == AttachmentDownloadStatus.Downloading) {
- TextButton(onClick = { onCancel(item.id) }) {
+ TextButton(
+ onClick = { onCancel(item.id) },
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
+ ) {
Text(text = "Cancel", style = EnsuTypography.mini)
}
}
@@ -740,7 +759,10 @@ private fun AttachmentDownloadsDialog(
}
},
confirmButton = {
- TextButton(onClick = onDismiss) {
+ TextButton(
+ onClick = onDismiss,
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
+ ) {
Text(text = "Close", style = EnsuTypography.small)
}
}
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt
index c96d7b66d8..23805ffd91 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt
@@ -108,13 +108,12 @@ fun ChatView(
onCancelEdit: () -> Unit,
onBranchChange: (String, Int) -> Unit,
onOpenAttachment: (Attachment) -> Unit,
- onStartDownload: () -> Unit
+ onStartDownload: (Boolean) -> Unit
) {
val imePadding = WindowInsets.ime.asPaddingValues().calculateBottomPadding()
val showDownloadOnboarding = !chatState.isModelDownloaded &&
chatState.messages.isEmpty() &&
!chatState.isGenerating
- val hasMessages = chatState.messages.isNotEmpty()
var didAutoFocusInput by remember { mutableStateOf(false) }
val shouldAutoFocusInput = chatState.isModelDownloaded &&
@@ -129,15 +128,13 @@ fun ChatView(
}
}
- LaunchedEffect(hasMessages, chatState.isModelDownloaded, chatState.isDownloading, chatState.isGenerating) {
- if (hasMessages && !chatState.isModelDownloaded && !chatState.isDownloading && !chatState.isGenerating) {
- onStartDownload()
- }
- }
+ val shouldAutoDownload = chatState.hasRequestedModelDownload &&
+ !chatState.isDownloading &&
+ !chatState.isGenerating
- LaunchedEffect(chatState.isModelDownloaded) {
- if (chatState.isModelDownloaded && !chatState.isDownloading && !chatState.isGenerating) {
- onStartDownload()
+ LaunchedEffect(chatState.isModelDownloaded, shouldAutoDownload) {
+ if (!chatState.isModelDownloaded && shouldAutoDownload) {
+ onStartDownload(false)
}
}
@@ -233,7 +230,7 @@ private fun MessageList(
onRetryMessage: (ChatMessage) -> Unit,
onBranchChange: (String, Int) -> Unit,
onOpenAttachment: (Attachment) -> Unit,
- onStartDownload: () -> Unit
+ onStartDownload: (Boolean) -> Unit
) {
if (messages.isEmpty() && !isGenerating) {
if (!isModelDownloaded) {
@@ -243,7 +240,7 @@ private fun MessageList(
downloadPercent = downloadPercent,
downloadStatus = downloadStatus,
modelDownloadSizeBytes = modelDownloadSizeBytes,
- onDownload = onStartDownload
+ onDownload = { onStartDownload(true) }
)
} else {
EmptyState(
@@ -510,6 +507,8 @@ private fun UserMessageBubble(
var showMenu by remember { mutableStateOf(false) }
var pressOffset by remember { mutableStateOf(Offset.Zero) }
val bubbleShape = RoundedCornerShape(18.dp)
+ val bubbleFill = if (isSystemInDarkTheme()) EnsuColor.fillFaint() else EnsuColor.border().copy(alpha = 0.2f)
+ val bubbleFill = if (isSystemInDarkTheme()) EnsuColor.fillFaint() else EnsuColor.border().copy(alpha = 0.2f)
Column(
modifier = Modifier
@@ -517,10 +516,29 @@ private fun UserMessageBubble(
.padding(start = EnsuSpacing.messageBubbleInset.dp),
horizontalAlignment = Alignment.End
) {
+ if (message.attachments.isNotEmpty()) {
+ FlowRow(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp, Alignment.End),
+ verticalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)
+ ) {
+ message.attachments.forEach { attachment ->
+ io.ente.ensu.components.AttachmentChip(
+ name = attachment.name,
+ size = "${attachment.sizeBytes / 1024} KB",
+ iconRes = HugeIcons.Attachment01Icon,
+ isUploading = attachment.isUploading,
+ onClick = { onOpenAttachment(attachment) }
+ )
+ }
+ }
+ Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
+ }
+
Box {
Column(
modifier = Modifier
- .background(EnsuColor.border().copy(alpha = 0.2f), bubbleShape)
+ .background(bubbleFill, bubbleShape)
.pointerInput(Unit) {
detectTapGestures(
onLongPress = { offset ->
@@ -532,25 +550,6 @@ private fun UserMessageBubble(
}
.padding(EnsuSpacing.md.dp)
) {
- if (message.attachments.isNotEmpty()) {
- FlowRow(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp, Alignment.End),
- verticalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)
- ) {
- message.attachments.forEach { attachment ->
- io.ente.ensu.components.AttachmentChip(
- name = attachment.name,
- size = "${attachment.sizeBytes / 1024} KB",
- iconRes = HugeIcons.Attachment01Icon,
- isUploading = attachment.isUploading,
- onClick = { onOpenAttachment(attachment) }
- )
- }
- }
- Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
- }
-
Text(
text = message.text,
style = EnsuTypography.message,
@@ -657,6 +656,7 @@ private fun AssistantMessageBubble(
var showMenu by remember { mutableStateOf(false) }
var pressOffset by remember { mutableStateOf(Offset.Zero) }
val bubbleShape = RoundedCornerShape(18.dp)
+ val bubbleFill = if (isSystemInDarkTheme()) EnsuColor.fillFaint() else EnsuColor.border().copy(alpha = 0.2f)
Column(
modifier = Modifier
@@ -667,7 +667,7 @@ private fun AssistantMessageBubble(
Box {
Column(
modifier = Modifier
- .background(EnsuColor.border().copy(alpha = 0.2f), bubbleShape)
+ .background(bubbleFill, bubbleShape)
.pointerInput(Unit) {
detectTapGestures(
onLongPress = { offset ->
@@ -778,6 +778,7 @@ private fun AssistantMessageBubble(
@Composable
private fun StreamingMessageBubble(text: String) {
val bubbleShape = RoundedCornerShape(18.dp)
+ val bubbleFill = if (isSystemInDarkTheme()) EnsuColor.fillFaint() else EnsuColor.border().copy(alpha = 0.2f)
Column(
modifier = Modifier
@@ -787,7 +788,7 @@ private fun StreamingMessageBubble(text: String) {
) {
Column(
modifier = Modifier
- .background(EnsuColor.border().copy(alpha = 0.2f), bubbleShape)
+ .background(bubbleFill, bubbleShape)
.padding(EnsuSpacing.md.dp)
) {
if (text.isBlank()) {
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/SessionDrawer.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/SessionDrawer.kt
index 3a0bf139a8..5106feefe2 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/SessionDrawer.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/SessionDrawer.kt
@@ -128,7 +128,7 @@ private fun DrawerHeader(
) {
Box(
modifier = Modifier
- .clickable { onDeveloperTap() }
+ .clickable(enabled = !isLoggedIn) { onDeveloperTap() }
) {
EnsuLogo(height = 28.dp)
}
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/components/ChoiceDialog.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/components/ChoiceDialog.kt
index d48005bedb..d2743f1e44 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/components/ChoiceDialog.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/components/ChoiceDialog.kt
@@ -43,7 +43,10 @@ fun ChoiceDialog(
},
dismissButton = {
if (secondButtonLabel != null && onSecond != null) {
- TextButton(onClick = onSecond) {
+ TextButton(
+ onClick = onSecond,
+ colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textMuted())
+ ) {
Text(text = secondButtonLabel)
}
}
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/LogViewerScreen.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/LogViewerScreen.kt
index 0d7f092cec..bd92a02b6b 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/LogViewerScreen.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/LogViewerScreen.kt
@@ -13,12 +13,12 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.material3.AlertDialog
+import android.app.AlertDialog
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -27,6 +27,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import io.ente.ensu.data.logging.FileLogRepository
import io.ente.ensu.designsystem.EnsuColor
@@ -99,29 +100,42 @@ fun LogViewerScreen(
}
selectedLog?.let { log ->
- AlertDialog(
- onDismissRequest = { selectedLog = null },
- title = { Text(text = "Log details", style = EnsuTypography.h3) },
- text = {
- Column {
- Row(horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)) {
- Text(text = log.level.name, style = EnsuTypography.small, color = levelColor(log.level))
- log.tag?.let { tag ->
- Text(text = tag, style = EnsuTypography.small, color = EnsuColor.textMuted())
- }
- }
- Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
- Text(text = log.message, style = EnsuTypography.body)
- log.details?.let { details ->
- Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
- Text(text = details, style = EnsuTypography.small, color = EnsuColor.textMuted())
- }
+ NativeLogDetailsDialog(logEntry = log, onDismiss = { selectedLog = null })
+ }
+}
+
+@Composable
+private fun NativeLogDetailsDialog(logEntry: LogEntry, onDismiss: () -> Unit) {
+ val context = LocalContext.current
+ val message = remember(logEntry) {
+ buildString {
+ append("Level: ")
+ append(logEntry.level.name)
+ logEntry.tag?.let { tag ->
+ append("\nTag: ")
+ append(tag)
+ }
+ append("\n\n")
+ append(logEntry.message)
+ logEntry.details?.let { details ->
+ if (details.isNotBlank()) {
+ append("\n\nDetails:\n")
+ append(details)
}
- },
- confirmButton = {
- TextButton(onClick = { selectedLog = null }) { Text(text = "Close") }
}
- )
+ }
+ }
+
+ DisposableEffect(logEntry) {
+ val dialog = AlertDialog.Builder(context)
+ .setTitle("Log details")
+ .setMessage(message)
+ .setPositiveButton("Close") { _, _ -> onDismiss() }
+ .setOnDismissListener { onDismiss() }
+ .create()
+
+ dialog.show()
+ onDispose { dialog.dismiss() }
}
}
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
index 150f7e227d..790a3f15af 100644
--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
@@ -224,10 +224,17 @@ class FileLogRepository(
val levelValue = match.groupValues[2]
val timestampValue = match.groupValues[3]
val message = match.groupValues[4]
-
- val isDetail = message.trimStart().startsWith("⤷")
- if (isDetail && current != null) {
- details.add(message.replaceFirst("⤷", "").trim())
+ val trimmedMessage = message.trimStart()
+ val isDetail = isDetailLine(trimmedMessage)
+ if (isDetail) {
+ if (current != null) {
+ val cleaned = if (trimmedMessage.startsWith("⤷")) {
+ trimmedMessage.removePrefix("⤷").trim()
+ } else {
+ trimmedMessage
+ }
+ details.add(cleaned)
+ }
return@forEach
}
@@ -267,6 +274,15 @@ class FileLogRepository(
else -> null
}
+ private fun isDetailLine(message: String): Boolean {
+ val trimmed = message.trimStart()
+ return trimmed.startsWith("⤷") ||
+ trimmed.startsWith("at ") ||
+ trimmed.startsWith("...") ||
+ trimmed.startsWith("Caused by") ||
+ trimmed.startsWith("Suppressed:")
+ }
+
companion object {
private val logLineRegex = Regex("\\[(.+?)]\\[(.+?)] \\[(.+?)]\\] (.*)")
}
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
index 208787342f..408c68d7c0 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
@@ -60,6 +60,7 @@ class AppStore(
private var activeGenerationToken = 0L
private var pendingSyncRequested = false
private var pendingSyncErrorHandler: ((String) -> Unit)? = null
+ private var pendingSyncSuccessHandler: (() -> Unit)? = null
private val attachmentDownloads = mutableMapOf<String, AttachmentDownloadItem>()
private val attachmentDownloadQueue = ArrayDeque<String>()
@@ -95,7 +96,8 @@ class AppStore(
appState.copy(
chat = appState.chat.copy(
isModelDownloaded = isDownloaded,
- modelDownloadSizeBytes = if (isDownloaded) null else appState.chat.modelDownloadSizeBytes
+ modelDownloadSizeBytes = if (isDownloaded) null else appState.chat.modelDownloadSizeBytes,
+ hasRequestedModelDownload = appState.chat.hasRequestedModelDownload || isDownloaded
)
)
}
@@ -359,7 +361,9 @@ class AppStore(
fun startModelDownload(userInitiated: Boolean = true) {
val scope = scope ?: return
val currentState = _state.value
+ if (modelDownloadJob?.isActive == true) return
if (currentState.chat.isDownloading || currentState.chat.isGenerating) return
+ if (!userInitiated && !currentState.chat.hasRequestedModelDownload) return
val target = resolveTarget(currentState.modelSettings)
val isDownloaded = llmProvider.isModelDownloaded(target)
@@ -579,43 +583,61 @@ class AppStore(
logRepository.log(LogLevel.Info, "Signed out", tag = "Auth")
}
- fun syncNow(onError: ((String) -> Unit)? = null) {
- requestSync(onError)
+ fun syncNow(
+ onSuccess: (() -> Unit)? = null,
+ onError: ((String) -> Unit)? = null
+ ) {
+ requestSync(onSuccess, onError)
}
- private fun requestSync(onError: ((String) -> Unit)? = null) {
+ private fun requestSync(
+ onSuccess: (() -> Unit)? = null,
+ onError: ((String) -> Unit)? = null
+ ) {
if (_state.value.chat.isGenerating) {
pendingSyncRequested = true
if (onError != null) {
pendingSyncErrorHandler = onError
}
+ if (onSuccess != null) {
+ pendingSyncSuccessHandler = onSuccess
+ }
return
}
val handler = pendingSyncErrorHandler ?: onError
+ val successHandler = pendingSyncSuccessHandler ?: onSuccess
pendingSyncRequested = false
pendingSyncErrorHandler = null
- performSync(handler)
+ pendingSyncSuccessHandler = null
+ performSync(handler, successHandler)
}
private fun syncAfterGeneration() {
val handler = pendingSyncErrorHandler
+ val successHandler = pendingSyncSuccessHandler
val shouldAutoSync = _state.value.auth.isLoggedIn
if (!pendingSyncRequested && !shouldAutoSync) {
pendingSyncErrorHandler = null
+ pendingSyncSuccessHandler = null
return
}
- if (!shouldAutoSync && handler == null) {
+ if (!shouldAutoSync && handler == null && successHandler == null) {
pendingSyncRequested = false
pendingSyncErrorHandler = null
+ pendingSyncSuccessHandler = null
return
}
pendingSyncRequested = false
pendingSyncErrorHandler = null
- performSync(handler)
+ pendingSyncSuccessHandler = null
+ performSync(handler, successHandler)
}
- private fun performSync(onError: ((String) -> Unit)? = null) {
+ private fun performSync(
+ onError: ((String) -> Unit)? = null,
+ onSuccess: (() -> Unit)? = null
+ ) {
val scope = scope ?: return
scope.launch {
try {
@@ -625,6 +647,11 @@ class AppStore(
}
loadSessionsFromDb()
logRepository.log(LogLevel.Info, "Sync success", tag = "Sync")
+ if (onSuccess != null) {
+ withContext(Dispatchers.Main) {
+ onSuccess()
+ }
+ }
} catch (err: Throwable) {
val message = syncErrorMessage(err)
logRepository.log(
@@ -833,7 +860,8 @@ class AppStore(
streamingResponse = "",
streamingParentId = userMessage.id,
downloadPercent = null,
- downloadStatus = null
+ downloadStatus = null,
+ hasRequestedModelDownload = true
)
)
}
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift
index c6f53de25b..57b257a9e9 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift
@@ -73,6 +73,11 @@ struct ChatView: View {
showToast(message, duration: 2)
viewModel.syncErrorMessage = nil
}
+ .onChange(of: viewModel.syncSuccessMessage) { message in
+ guard let message else { return }
+ showToast(message, duration: 2)
+ viewModel.syncSuccessMessage = nil
+ }
.onChange(of: modelSettings.useCustomModel) { _ in
viewModel.refreshModelDownloadInfo()
}
@@ -185,7 +190,7 @@ struct ChatView: View {
totalBytes: viewModel.modelDownloadSizeBytes,
sizeText: viewModel.modelDownloadSizeText,
onDownload: {
- viewModel.startModelDownload()
+ viewModel.startModelDownload(userInitiated: true)
}
)
} else {
@@ -292,7 +297,7 @@ struct ChatView: View {
deleteSession = session
},
onSync: {
- viewModel.syncNow()
+ viewModel.syncNow(showErrors: true, showSuccess: true)
},
onOpenSettings: {
isDrawerOpen = false
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
index 5e3df541a3..65115aeaaf 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
@@ -455,9 +455,11 @@ final class ChatViewModel: ObservableObject {
@Published var downloadToast: DownloadToastState?
@Published var isModelDownloaded: Bool = false
@Published var modelDownloadSizeBytes: Int64?
+ @Published var hasRequestedModelDownload: Bool = false
@Published var attachmentDownloads: [AttachmentDownloadItem] = []
@Published var currentSessionMissingAttachments: [AttachmentDownloadItem] = []
@Published var syncErrorMessage: String?
+ @Published var syncSuccessMessage: String?
private let provider: InferenceRsProvider
private let chatDb: LlmChatDb
@@ -477,6 +479,7 @@ final class ChatViewModel: ObservableObject {
private var activeGenerationSessionId: UUID?
private var pendingSyncRequested = false
private var pendingSyncShowErrors = false
+ private var pendingSyncShowSuccess = false
private var modelDownloadLoggedStart = false
private var attachmentDownloadQueue: [String] = []
@@ -687,22 +690,25 @@ final class ChatViewModel: ObservableObject {
syncNow()
}
- func syncNow(showErrors: Bool = true) {
+ func syncNow(showErrors: Bool = true, showSuccess: Bool = false) {
if isGenerating {
pendingSyncRequested = true
pendingSyncShowErrors = pendingSyncShowErrors || showErrors
+ pendingSyncShowSuccess = pendingSyncShowSuccess || showSuccess
return
}
- let shouldSync = pendingSyncRequested || showErrors
+ let shouldSync = pendingSyncRequested || showErrors || showSuccess
let shouldShowErrors = pendingSyncShowErrors || showErrors
+ let shouldShowSuccess = pendingSyncShowSuccess || showSuccess
pendingSyncRequested = false
pendingSyncShowErrors = false
+ pendingSyncShowSuccess = false
guard shouldSync else { return }
- performSync(showErrors: shouldShowErrors)
+ performSync(showErrors: shouldShowErrors, showSuccess: shouldShowSuccess)
}
- private func performSync(showErrors: Bool) {
+ private func performSync(showErrors: Bool, showSuccess: Bool) {
let log = logger
guard let auth = buildSyncAuth() else {
log.warning("Sync skipped", details: "not logged in")
@@ -721,6 +727,9 @@ final class ChatViewModel: ObservableObject {
log.info("Sync success")
await MainActor.run {
self.reloadFromDb()
+ if showSuccess {
+ self.syncSuccessMessage = "Sync complete"
+ }
}
} catch {
let message = syncErrorMessage(from: error)
@@ -899,18 +908,24 @@ final class ChatViewModel: ObservableObject {
}
}
- func startModelDownload() {
+ func startModelDownload(userInitiated: Bool = true) {
guard !isDownloading && !isGenerating else { return }
+ if userInitiated {
+ hasRequestedModelDownload = true
+ }
+
let target = modelSettings.currentTarget()
let isDownloaded = provider.isModelDownloaded(target: target)
if isDownloaded {
isModelDownloaded = true
modelDownloadSizeBytes = nil
- } else {
- modelDownloadLoggedStart = true
- logger.info("Model download started", details: "model=\(target.id)")
+ return
}
+ isDownloading = true
+ modelDownloadLoggedStart = true
+ logger.info("Model download started", details: "model=\(target.id)")
+
modelDownloadTask?.cancel()
modelDownloadTask = Task {
do {
@@ -943,13 +958,12 @@ final class ChatViewModel: ObservableObject {
}
func autoStartModelDownloadIfNeeded() {
+ guard hasRequestedModelDownload else { return }
guard !isDownloading && !isGenerating else { return }
if isModelDownloaded {
- startModelDownload()
return
}
- guard !messages.isEmpty else { return }
- startModelDownload()
+ startModelDownload(userInitiated: false)
}
func cancelDownload() {
@@ -966,6 +980,7 @@ final class ChatViewModel: ObservableObject {
activeGenerationSessionId = nil
isGenerating = false
isDownloading = false
+ hasRequestedModelDownload = false
streamingResponse = ""
streamingParentId = nil
downloadToast = nil
@@ -973,29 +988,7 @@ final class ChatViewModel: ObservableObject {
}
func retryDownload() {
- let target = modelSettings.currentTarget()
- modelDownloadTask?.cancel()
- modelDownloadTask = Task {
- do {
- try await provider.ensureModelReady(target: target) { progress in
- Task { @MainActor in
- self.handleProgress(progress)
- }
- }
- } catch {
- if isCancellation(error) {
- return
- }
- await MainActor.run {
- self.downloadToast = DownloadToastState(
- phase: .errorDownload,
- percent: -1,
- status: error.localizedDescription,
- offerRetryDownload: true
- )
- }
- }
- }
+ startModelDownload(userInitiated: true)
}
func retryAssistantResponse(_ message: ChatMessage) {
@@ -1052,6 +1045,7 @@ final class ChatViewModel: ObservableObject {
activeGenerationSessionId = userNode.sessionId
isGenerating = true
isDownloading = false
+ hasRequestedModelDownload = true
streamingResponse = ""
streamingParentId = userNode.id
downloadToast = nil
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
index 267366ec91..45ecb60302 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
@@ -245,32 +245,35 @@ private struct UserMessageBubbleView: View {
let onBranchChange: (Int) -> Void
let onOpenAttachment: (ChatAttachment) -> Void
+ @Environment(\.colorScheme) private var colorScheme
+
var body: some View {
let bubbleShape = RoundedRectangle(cornerRadius: 18, style: .continuous)
+ let bubbleFill = colorScheme == .dark ? EnsuColor.fillFaint : EnsuColor.border.opacity(0.2)
HStack(alignment: .bottom) {
Spacer(minLength: EnsuSpacing.messageBubbleInset)
VStack(alignment: .trailing, spacing: EnsuSpacing.sm) {
- VStack(alignment: .trailing, spacing: EnsuSpacing.sm) {
- if !message.attachments.isEmpty {
- FlowLayout(spacing: EnsuSpacing.sm) {
- ForEach(message.attachments) { attachment in
- AttachmentChip(
- name: attachment.name,
- size: attachment.formattedSize,
- icon: attachment.iconName,
- isUploading: attachment.isUploading
- )
- .onTapGesture {
- hapticTap()
- onOpenAttachment(attachment)
- }
+ if !message.attachments.isEmpty {
+ FlowLayout(spacing: EnsuSpacing.sm) {
+ ForEach(message.attachments) { attachment in
+ AttachmentChip(
+ name: attachment.name,
+ size: attachment.formattedSize,
+ icon: attachment.iconName,
+ isUploading: attachment.isUploading
+ )
+ .onTapGesture {
+ hapticTap()
+ onOpenAttachment(attachment)
}
}
- .frame(maxWidth: .infinity, alignment: .trailing)
}
+ .frame(maxWidth: .infinity, alignment: .trailing)
+ }
+ VStack(alignment: .trailing, spacing: EnsuSpacing.sm) {
Text(message.text)
.font(EnsuTypography.message)
.foregroundStyle(EnsuColor.userMessageText)
@@ -279,7 +282,7 @@ private struct UserMessageBubbleView: View {
.textSelection(.enabled)
}
.padding(EnsuSpacing.md)
- .background(EnsuColor.border.opacity(0.2))
+ .background(bubbleFill)
.clipShape(bubbleShape)
#if os(iOS)
.contextMenu {
@@ -318,8 +321,11 @@ private struct AssistantMessageBubbleView: View {
let onBranchChange: (Int) -> Void
let onOpenAttachment: (ChatAttachment) -> Void
+ @Environment(\.colorScheme) private var colorScheme
+
var body: some View {
let bubbleShape = RoundedRectangle(cornerRadius: 18, style: .continuous)
+ let bubbleFill = colorScheme == .dark ? EnsuColor.fillFaint : EnsuColor.border.opacity(0.2)
HStack(alignment: .bottom) {
VStack(alignment: .leading, spacing: EnsuSpacing.sm) {
@@ -334,7 +340,7 @@ private struct AssistantMessageBubbleView: View {
}
}
.padding(EnsuSpacing.md)
- .background(EnsuColor.border.opacity(0.2))
+ .background(bubbleFill)
.clipShape(bubbleShape)
#if os(iOS)
.contextMenu {
@@ -371,9 +377,11 @@ private struct StreamingBubbleView: View {
let text: String
@State private var cursorOpacity: Double = 1
+ @Environment(\.colorScheme) private var colorScheme
var body: some View {
let bubbleShape = RoundedRectangle(cornerRadius: 18, style: .continuous)
+ let bubbleFill = colorScheme == .dark ? EnsuColor.fillFaint : EnsuColor.border.opacity(0.2)
HStack(alignment: .bottom) {
VStack(alignment: .leading, spacing: EnsuSpacing.sm) {
@@ -396,7 +404,7 @@ private struct StreamingBubbleView: View {
}
}
.padding(EnsuSpacing.md)
- .background(EnsuColor.border.opacity(0.2))
+ .background(bubbleFill)
.clipShape(bubbleShape)
}
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/SessionDrawerView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/SessionDrawerView.swift
index db71c951cf..64792c8a86 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/SessionDrawerView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/SessionDrawerView.swift
@@ -52,11 +52,15 @@ struct SessionDrawerView: View {
private var drawerHeader: some View {
VStack(alignment: .leading, spacing: EnsuSpacing.md) {
HStack {
- EnsuLogo(height: 28)
- .contentShape(Rectangle())
- .onTapGesture {
- onDeveloperTap()
- }
+ if isLoggedIn {
+ EnsuLogo(height: 28)
+ } else {
+ EnsuLogo(height: 28)
+ .contentShape(Rectangle())
+ .onTapGesture {
+ onDeveloperTap()
+ }
+ }
Spacer()