feat: share target für android und desktop-chrome

- LAN-Clipboard erscheint im Teilen-Menü (GET /share mit title/text/url)
- geteilter Inhalt landet vorausgefüllt in der Schnell-Eingabe
- Link wird nicht doppelt übernommen, wenn er schon im Text steht

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dbildhauerandClaude Opus 5.5 committed 2026-10-25 11:47:30 +01:00
1 parent 9cf163c295
commit 6d58a697e3
6 files changed
+91

No files matched your search

+11
View File
@@ -23,6 +23,17 @@ watch([content, kind], () => {
language.value = detectLanguage(content.value) ?? 'plaintext'
})
// Content shared from another app (share target) arrives as a draft
watch(
() => store.draft,
(draft) => {
if (!draft) return
content.value = draft
store.draft = null
},
{ immediate: true },
)
async function paste(): Promise<void> {
error.value = null
try {
+12
View File
@@ -2,6 +2,8 @@ import { createRouter, createWebHistory } from 'vue-router'
import { ApiError } from '@/api/client'
import { useAuthStore } from '@/stores/auth'
import { useClipsStore } from '@/stores/clips'
import { sharedContent } from '@/utils/share'
import HomeView from '@/views/HomeView.vue'
declare module 'vue-router' {
@@ -34,6 +36,16 @@ const router = createRouter({
component: () => import('@/views/AdminUsersView.vue'),
meta: { admin: true },
},
{
// Web Share Target: hand the shared content to the quick-add form
path: '/share',
name: 'share',
component: HomeView,
beforeEnter: (to) => {
useClipsStore().draft = sharedContent(to.query)
return { name: 'home', replace: true }
},
},
{
path: '/offline',
name: 'offline',
+4
View File
@@ -25,6 +25,8 @@ export const useClipsStore = defineStore('clips', () => {
const loading = ref(false)
const error = ref<string | null>(null)
const loaded = ref(false)
/** Content handed over from the share target, picked up by the quick-add form. */
const draft = ref<string | null>(null)
/**
* Insert or replace a clip locally. Used for API responses and live-sync events;
@@ -49,6 +51,7 @@ export const useClipsStore = defineStore('clips', () => {
total.value = 0
error.value = null
loaded.value = false
draft.value = null
}
function removeLocal(id: number): void {
@@ -117,6 +120,7 @@ export const useClipsStore = defineStore('clips', () => {
loading,
error,
loaded,
draft,
upsert,
removeLocal,
reset,
+36
View File
@@ -0,0 +1,36 @@
import { describe, expect, it } from 'vitest'
import { sharedContent } from './share'
describe('sharedContent', () => {
it('combines text and url', () => {
expect(sharedContent({ text: 'Look at this', url: 'https://example.com' })).toBe(
'Look at this\nhttps://example.com',
)
})
it('does not repeat a url already contained in the text', () => {
expect(sharedContent({ text: 'see https://example.com', url: 'https://example.com' })).toBe(
'see https://example.com',
)
})
it('uses the url alone', () => {
expect(sharedContent({ title: 'Example', url: 'https://example.com' })).toBe(
'https://example.com',
)
})
it('falls back to the title', () => {
expect(sharedContent({ title: 'Only a title' })).toBe('Only a title')
})
it('returns null for empty shares', () => {
expect(sharedContent({})).toBeNull()
expect(sharedContent({ text: ' ', url: '' })).toBeNull()
})
it('takes the first value of repeated parameters', () => {
expect(sharedContent({ text: ['first', 'second'] })).toBe('first')
})
})
+22
View File
@@ -0,0 +1,22 @@
import type { LocationQuery } from 'vue-router'
function param(query: LocationQuery, name: string): string {
const value = query[name]
const first = Array.isArray(value) ? value[0] : value
return (first ?? '').trim()
}
/**
* Build clip content from Web Share Target parameters (title, text, url).
* Apps fill these inconsistently: the link may be in `text`, in `url`, or in both.
*/
export function sharedContent(query: LocationQuery): string | null {
const title = param(query, 'title')
const text = param(query, 'text')
const url = param(query, 'url')
const parts = [text]
if (url && !text.includes(url)) parts.push(url)
const content = parts.filter(Boolean).join('\n')
return content || title || null
}