Add plain text clipboard transfers and refine input feedback

This commit is contained in:
2026-10-13 14:07:03 +09:00
parent af004a2942
commit 8a8df417aa
32 changed files with 1263 additions and 197 deletions

View File

@@ -28,6 +28,7 @@ export const pendingPeers = ref([]);
let pendingTimer;
let deviceInfo = {};
export const nextCursor = ref(null);
export const clipboardTextLimitBytes = ref(262144);
export const spaceInviteCodeLength = ref(4);
export const locationSettings = ref({ enabled: false, radiusMeters: 100, refreshMs: 120000 });
export async function publishLocation(position) {
@@ -147,6 +148,7 @@ export const refresh = createRefreshQueue(async () => {
const snapshot = await api('/device/snapshot');
device.value = snapshot.device;
peers.value = snapshot.devices;
clipboardTextLimitBytes.value = snapshot.clipboardTextLimitBytes ?? 262144;
pendingPeers.value = pendingPeers.value.filter(
(id) => !snapshot.devices.some((peer) => peer.id === id),
);
@@ -182,7 +184,7 @@ export const refresh = createRefreshQueue(async () => {
}
});
export async function send(targetDeviceId, kind, values) {
const content = values.urls.join('\n');
const content = kind === 'text' ? values.text : values.urls.join('\n');
const { requestId } = await api(
'/transfer-requests',
'POST',
@@ -190,7 +192,7 @@ export async function send(targetDeviceId, kind, values) {
targetDeviceId,
kind,
byteSize: new TextEncoder().encode(content).length,
count: values.urls.length,
count: kind === 'text' ? 1 : values.urls.length,
},
crypto.randomUUID(),
);
@@ -204,7 +206,12 @@ async function deliver(id) {
if (!draft) return;
completing.add(id);
try {
await api(`/transfers/${id}/complete`, 'POST', { urls: draft.urls }, draft.key);
await api(
`/transfers/${id}/complete`,
'POST',
draft.text !== undefined ? { text: draft.text } : { urls: draft.urls },
draft.key,
);
drafts.delete(id);
await refresh();
return true;