diff --git a/android/app/src/main/java/me/teafry/voipmessages/ChatActivity.java b/android/app/src/main/java/me/teafry/voipmessages/ChatActivity.java index 882d13a..262d90b 100644 --- a/android/app/src/main/java/me/teafry/voipmessages/ChatActivity.java +++ b/android/app/src/main/java/me/teafry/voipmessages/ChatActivity.java @@ -123,23 +123,16 @@ public final class ChatActivity extends BaseActivity { /** * The R1 has 640 px of height and the keyboard takes about half: with a - * photo attached, the full-size composer would push the text box under - * it. So while it's up, the photos, text and padding all shrink and the - * subtitle goes, leaving the text box and a few messages in view. + * photo attached, the composer would push the text box under it. So + * while it's up, the photos shrink, the text box gives up a line and the + * subtitle goes, leaving the text box and a few messages in view. (The + * composer itself is always the small size: see composer().) */ private void setCompact(boolean on) { compact = on; header.setPadding(Ui.dp(this, 24), Ui.dp(this, on ? 4 : 10), Ui.dp(this, 24), Ui.dp(this, on ? 4 : 10)); subView.setVisibility(on || subView.getText().length() == 0 ? View.GONE : View.VISIBLE); - composerBox.setPadding(Ui.dp(this, 12), Ui.dp(this, on ? 4 : 10), Ui.dp(this, 12), Ui.dp(this, on ? 4 : 10)); - input.setTextSize(TypedValue.COMPLEX_UNIT_SP, on ? Ui.T_SMALL : Ui.T_BODY); - input.setPadding(Ui.dp(this, on ? 18 : 24), Ui.dp(this, on ? 8 : 14), Ui.dp(this, on ? 18 : 24), Ui.dp(this, on ? 8 : 14)); input.setMaxLines(on ? 3 : 4); - for (TextView b : new TextView[] {attach, send}) { - b.setMinWidth(Ui.dp(this, on ? 60 : 80)); - b.setMinHeight(Ui.dp(this, on ? 56 : 80)); - b.setTextSize(TypedValue.COMPLEX_UNIT_SP, on ? 28 : 34); - } for (int i = 0; i < tray.getChildCount(); i++) tray.getChildAt(i).setLayoutParams(thumbParams()); if (on) list.post(this::showLatest); } @@ -165,7 +158,9 @@ public final class ChatActivity extends BaseActivity { LinearLayout box = composerBox = new LinearLayout(this); box.setOrientation(LinearLayout.VERTICAL); box.setBackgroundColor(Ui.PANEL); - box.setPadding(Ui.dp(this, 12), Ui.dp(this, 10), Ui.dp(this, 12), Ui.dp(this, 10)); + // Always the compact size (it used to shrink only with the keyboard + // up): the big one's padding was wasted on a 640 px screen. + box.setPadding(Ui.dp(this, 12), Ui.dp(this, 4), Ui.dp(this, 12), Ui.dp(this, 4)); // From-number picker, only for a conversation with nothing in it yet. fromRow = new LinearLayout(this); @@ -189,15 +184,17 @@ public final class ChatActivity extends BaseActivity { row.setBaselineAligned(false); attach = Ui.headerButton(this, Glyph.Kind.ATTACH); attach.setOnTouchListener((v, e) -> attachTouch(e)); + compactButton(attach); input = new EditText(this); input.setHint("Message"); input.setHintTextColor(Ui.MUTED); input.setTextColor(Ui.TEXT); - input.setTextSize(TypedValue.COMPLEX_UNIT_SP, Ui.T_BODY); + input.setTextSize(TypedValue.COMPLEX_UNIT_SP, Ui.T_SMALL); input.setMaxLines(4); input.setBackground(Ui.input(this, 36)); - input.setPadding(Ui.dp(this, 24), Ui.dp(this, 14), Ui.dp(this, 24), Ui.dp(this, 14)); + input.setPadding(Ui.dp(this, 18), Ui.dp(this, 8), Ui.dp(this, 18), Ui.dp(this, 8)); send = Ui.headerButton(this, Glyph.Kind.SEND, Ui.ACCENT); + compactButton(send); send.setOnClickListener(v -> submit()); row.addView(attach); row.addView(input, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1)); @@ -226,6 +223,12 @@ public final class ChatActivity extends BaseActivity { return box; } + private void compactButton(TextView b) { + b.setMinWidth(Ui.dp(this, 60)); + b.setMinHeight(Ui.dp(this, 56)); + b.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28); + } + private android.content.SharedPreferences drafts() { return getSharedPreferences("drafts", MODE_PRIVATE); } diff --git a/android/build.py b/android/build.py index 4bfbbe0..099ca8f 100644 --- a/android/build.py +++ b/android/build.py @@ -26,8 +26,8 @@ import sys import zipfile from pathlib import Path -VERSION_NAME = "0.7.4" -VERSION_CODE = 12 +VERSION_NAME = "0.7.5" +VERSION_CODE = 13 PACKAGE = "me.teafry.voipmessages" DEV_PACKAGE = PACKAGE + ".dev" diff --git a/package.json b/package.json index 513cbe2..6b6ede2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "voipms-desktop", "productName": "bubble", - "version": "0.8.7", + "version": "0.8.8", "description": "Signal-style desktop SMS client for voip.ms", "author": "trav ", "private": true, diff --git a/resources/android/VoipMessages.apk b/resources/android/VoipMessages.apk index e156714..09ef9de 100644 Binary files a/resources/android/VoipMessages.apk and b/resources/android/VoipMessages.apk differ diff --git a/resources/android/VoipMessages.json b/resources/android/VoipMessages.json index 30d87e0..2263dd0 100644 --- a/resources/android/VoipMessages.json +++ b/resources/android/VoipMessages.json @@ -1 +1 @@ -{"version_name": "0.7.4", "version_code": 12, "package": "me.teafry.voipmessages"} +{"version_name": "0.7.5", "version_code": 13, "package": "me.teafry.voipmessages"} diff --git a/src/main/index.ts b/src/main/index.ts index 9cbc968..f59131f 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -239,13 +239,17 @@ async function servePhoto(req: Request): Promise { } } -// ---- MMS attachments: mms-media://m// ---- +// ---- MMS attachments: mms-media://m//[?thumb] ---- +// ?thumb: a smaller copy of a still picture, for the chat and Get info. async function serveMedia(req: Request): Promise { - const [id, index] = new URL(req.url).pathname.slice(1).split('/').map(Number) + const url = new URL(req.url) + const [id, index] = url.pathname.slice(1).split('/').map(Number) const ref = await media.resolve(id, index) if (!ref?.file) return new Response(null, { status: 404 }) - const headers = { 'content-type': ref.mime ?? guessMime(ref.file) ?? 'application/octet-stream' } - return new Response(fs.readFileSync(media.filePath(ref.file)), { headers }) + const thumb = url.searchParams.has('thumb') ? await media.thumb(ref).catch(() => undefined) : undefined + const file = thumb ?? media.filePath(ref.file) + const mime = thumb ? (thumb.endsWith('.png') ? 'image/png' : 'image/jpeg') : (ref.mime ?? guessMime(ref.file) ?? 'application/octet-stream') + return new Response(await fs.promises.readFile(file), { headers: { 'content-type': mime } }) } async function saveMediaAs(id: number, index: number): Promise { diff --git a/src/main/media.ts b/src/main/media.ts index bc6dab3..51e32bd 100644 --- a/src/main/media.ts +++ b/src/main/media.ts @@ -9,6 +9,9 @@ import { extFor, guessMime } from '@shared/mime' import type { MediaRef } from '@shared/types' import type { MessageDb, NewMessage } from './db' +// Long edge of a thumbnail: twice the chat's largest picture box, for HiDPI. +const THUMB_EDGE = 720 + export class MediaStore { private inflight = new Map>() @@ -23,6 +26,30 @@ export class MediaStore { return path.join(this.dir, path.basename(file)) } + // A smaller copy of a still picture for the chat and Get info, made once + // and kept in /thumbs (outside media/, so it never goes to the + // Rabbit or into backups as if it were an attachment). The chat shows + // pictures at most 300x360, so a phone's 4000 px photo was being decoded + // whole, again and again as rows scrolled in and out. Undefined = use the + // original: already small, animated (GIF), or a format nativeImage can't read. + async thumb(ref: MediaRef): Promise { + if (!ref.file) return undefined + const mime = ref.mime ?? guessMime(ref.file) ?? '' + if (!mime.startsWith('image/') || mime === 'image/gif') return undefined + const png = mime === 'image/png' || mime === 'image/webp' // may be see-through + const out = path.join(this.dir, '..', 'thumbs', `${path.basename(ref.file)}.${THUMB_EDGE}.${png ? 'png' : 'jpg'}`) + if (fs.existsSync(out)) return out + const img = nativeImage.createFromPath(this.filePath(ref.file)) + if (img.isEmpty()) return undefined + const { width, height } = img.getSize() + if (Math.max(width, height) <= THUMB_EDGE) return undefined + const scale = THUMB_EDGE / Math.max(width, height) + const small = img.resize({ width: Math.round(width * scale), height: Math.round(height * scale), quality: 'good' }) + await fs.promises.mkdir(path.dirname(out), { recursive: true }) + await fs.promises.writeFile(out, png ? small.toPNG() : small.toJPEG(85)) + return out + } + save(data: Uint8Array, mime: string): string { const file = `${crypto.createHash('sha1').update(data).digest('hex')}.${extFor(mime)}` fs.mkdirSync(this.dir, { recursive: true }) diff --git a/src/renderer/src/components/ConversationInfo.tsx b/src/renderer/src/components/ConversationInfo.tsx index 37fdbf5..5f6a802 100644 --- a/src/renderer/src/components/ConversationInfo.tsx +++ b/src/renderer/src/components/ConversationInfo.tsx @@ -8,7 +8,7 @@ import { CloseIcon } from './Icons' import { Via } from './Via' import { useAddContact } from './AddContact' import { conversationMedia, Lightbox, type MediaItem } from './Lightbox' -import { mediaSrc } from './MessageBubble' +import { mediaSrc, thumbSrc } from './MessageBubble' interface Props { conv: ConvKey @@ -67,7 +67,7 @@ function MediaGrid({ conv }: { conv: ConvKey }) { ) : ( - setBroken((b) => new Set(b).add(key(it)))} /> + setBroken((b) => new Set(b).add(key(it)))} /> )} ))} diff --git a/src/renderer/src/components/MessageBubble.tsx b/src/renderer/src/components/MessageBubble.tsx index d4f1d29..5b5e977 100644 --- a/src/renderer/src/components/MessageBubble.tsx +++ b/src/renderer/src/components/MessageBubble.tsx @@ -30,6 +30,8 @@ function renderText(text: string, highlight: string): ReactNode[] { } export const mediaSrc = (id: number, index: number): string => `mms-media://m/${id}/${index}` +// The smaller copy the chat and Get info show (the original if it's small already). +export const thumbSrc = (id: number, index: number): string => `${mediaSrc(id, index)}?thumb` // Display box for an image: fit within 300×360, keeping the aspect ratio when // we know it (so the list doesn't jump when the image arrives). @@ -41,8 +43,8 @@ function imageBox(ref: MediaRef): { width: number; height: number } | undefined function Attachment({ id, index, media, onOpen, onMenu, onLoad }: { id: number; index: number; media: MediaRef; onOpen: () => void; onMenu: (e: React.MouseEvent) => void; onLoad: () => void }) { const [broken, setBroken] = useState(false) - const src = mediaSrc(id, index) const kind = mediaKind(media) + const src = kind === 'image' ? thumbSrc(id, index) : mediaSrc(id, index) // Still on the Rabbit (relayed history): asked for, it arrives after the Rabbit's next check. if (broken && media.url?.startsWith('mmspart:') && !media.file) return
On the Rabbit — it'll appear after its next check
if (broken) return
Media unavailable
@@ -53,6 +55,7 @@ function Attachment({ id, index, media, onOpen, onMenu, onLoad }: { id: number; src={src} alt="" draggable={false} + decoding="async" style={imageBox(media) ?? { minHeight: 120, minWidth: 120 }} onClick={onOpen} onContextMenu={onMenu}