Skip to content

Commit feb2103

Browse files
Fix loading messages and remove mobile input focus
1 parent 4201ad9 commit feb2103

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

assets/js/chatmkAI.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class ChatMKAI {
6060
n_ctx: 2048, // Set context size during model loading
6161
n_ctx_per_seq: 2048, // Set per-sequence context during model loading
6262
progressCallback: ({ loaded, total }) => {
63-
// Check if cancelled
63+
// Check if cancelled - stop immediately
6464
if (this.downloadController?.signal.aborted) {
65-
throw new Error('Download cancelled by user');
65+
return; // Stop progress updates
6666
}
6767

6868
const percent = Math.round((loaded / total) * 100);
@@ -107,6 +107,8 @@ class ChatMKAI {
107107
if (this.downloadController) {
108108
this.downloadController.abort();
109109
console.log("ChatMK AI: Download cancelled");
110+
// Show cancellation message immediately
111+
this.showProgressInModal(0, 0, 150, 'Language model skipped → using search only');
110112
}
111113
}
112114

@@ -222,7 +224,7 @@ ${userMessage}
222224
? customMessage
223225
: percent === 100
224226
? `Language model loaded: SmolLM2-360M-Q8`
225-
: `Language model loading: ${percent}% (${mbLoaded}/${mbTotal} MB) <span onclick="window.chatMKAI.cancelDownload()" style="margin-left: 10px; font-size: 11px; color: var(--text-sub); cursor: pointer; text-decoration: underline;">skip magic</span>`;
227+
: `Language model loading: ${percent}% (${mbLoaded}/${mbTotal} MB) <span onclick="window.chatMKAI.cancelDownload()" style="margin-left: 10px; font-size: 11px; color: var(--text-sub); cursor: pointer; text-decoration: underline; white-space: nowrap;">skip magic</span>`;
226228

227229
// Check if there's already a progress message and update it
228230
const messages = document.getElementById("chatmk-messages");

assets/js/chatmkModal.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
* Handles the chat modal open/close functionality
44
*/
55

6+
/**
7+
* Check if user is on a mobile device
8+
*/
9+
function isMobileDevice() {
10+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||
11+
(window.innerWidth <= 768);
12+
}
13+
614
/**
715
* Open the ChatMK modal
816
*/
@@ -51,9 +59,9 @@ function openChatMKModal() {
5159
modal.style.display = 'block';
5260
modal.classList.add('is-active');
5361

54-
// Focus on the input field
62+
// Focus on the input field only on desktop
5563
const input = modal.querySelector('#chatmk-input');
56-
if (input) {
64+
if (input && !isMobileDevice()) {
5765
setTimeout(() => input.focus(), 100);
5866
}
5967

@@ -176,11 +184,13 @@ function newChatMKConversation() {
176184
messagesContainer.insertBefore(welcomeMessage, messagesContainer.firstChild);
177185
}
178186

179-
// Clear input and focus
187+
// Clear input and focus only on desktop
180188
const input = document.getElementById('chatmk-input');
181189
if (input) {
182190
input.value = '';
183-
input.focus();
191+
if (!isMobileDevice()) {
192+
input.focus();
193+
}
184194
}
185195
}
186196

assets/js/chatmkSearch.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ChatMKSearch {
8888
} else if (percent === 100) {
8989
content.innerHTML = `<p>Embedding model loaded: MiniLM-L6-v2</p>`;
9090
} else {
91-
content.innerHTML = `<p>Embedding model loading: ${percent}% (${mbLoaded}/${mbTotal} MB) <span onclick="window.chatMKSearch.cancelEmbeddingDownload()" style="margin-left: 10px; font-size: 11px; color: var(--text-sub); cursor: pointer; text-decoration: underline;">skip magic</span></p>`;
91+
content.innerHTML = `<p>Embedding model loading: ${percent}% (${mbLoaded}/${mbTotal} MB) <span onclick="window.chatMKSearch.cancelEmbeddingDownload()" style="margin-left: 10px; font-size: 11px; color: var(--text-sub); cursor: pointer; text-decoration: underline; white-space: nowrap;">skip magic</span></p>`;
9292
}
9393
}
9494
} else {
@@ -99,7 +99,7 @@ class ChatMKSearch {
9999
? `<p>${customMessage}</p>`
100100
: percent === 100
101101
? `<p>Embedding model loaded: MiniLM-L6-v2</p>`
102-
: `<p>Embedding model loading: ${percent}% (${mbLoaded}/${mbTotal} MB) <span onclick="window.chatMKSearch.cancelEmbeddingDownload()" style="margin-left: 10px; font-size: 11px; color: var(--text-sub); cursor: pointer; text-decoration: underline;">skip magic</span></p>`;
102+
: `<p>Embedding model loading: ${percent}% (${mbLoaded}/${mbTotal} MB) <span onclick="window.chatMKSearch.cancelEmbeddingDownload()" style="margin-left: 10px; font-size: 11px; color: var(--text-sub); cursor: pointer; text-decoration: underline; white-space: nowrap;">skip magic</span></p>`;
103103

104104
messageDiv.innerHTML = `
105105
<div class="message-content">
@@ -120,6 +120,8 @@ class ChatMKSearch {
120120
if (this.embeddingController) {
121121
this.embeddingController.abort();
122122
console.log("Embedding download cancelled");
123+
// Show cancellation message immediately
124+
this.showEmbeddingProgress(0, 0, 25, 'Embedding model skipped → this won\'t work');
123125
}
124126
}
125127

@@ -131,9 +133,9 @@ class ChatMKSearch {
131133

132134
// Simulate progress from 0% to 100%
133135
for (let percent = 0; percent <= 100; percent += 20) {
134-
// Check if cancelled
136+
// Check if cancelled - stop immediately
135137
if (this.embeddingController?.signal.aborted) {
136-
throw new Error('Embedding download cancelled by user');
138+
return; // Stop progress updates
137139
}
138140

139141
const mbLoaded = Math.round((percent / 100) * totalMB);

0 commit comments

Comments
 (0)