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:
1 parent
9cf163c295
commit
6d58a697e3
6 files changed
+91
No files matched your search
@@ -23,6 +23,17 @@ watch([content, kind], () => {
|
|||||||
language.value = detectLanguage(content.value) ?? 'plaintext'
|
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> {
|
async function paste(): Promise<void> {
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { createRouter, createWebHistory } from 'vue-router'
|
|||||||
|
|
||||||
import { ApiError } from '@/api/client'
|
import { ApiError } from '@/api/client'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
import { useClipsStore } from '@/stores/clips'
|
||||||
|
import { sharedContent } from '@/utils/share'
|
||||||
import HomeView from '@/views/HomeView.vue'
|
import HomeView from '@/views/HomeView.vue'
|
||||||
|
|
||||||
declare module 'vue-router' {
|
declare module 'vue-router' {
|
||||||
@@ -34,6 +36,16 @@ const router = createRouter({
|
|||||||
component: () => import('@/views/AdminUsersView.vue'),
|
component: () => import('@/views/AdminUsersView.vue'),
|
||||||
meta: { admin: true },
|
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',
|
path: '/offline',
|
||||||
name: 'offline',
|
name: 'offline',
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export const useClipsStore = defineStore('clips', () => {
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
const loaded = ref(false)
|
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;
|
* 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
|
total.value = 0
|
||||||
error.value = null
|
error.value = null
|
||||||
loaded.value = false
|
loaded.value = false
|
||||||
|
draft.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeLocal(id: number): void {
|
function removeLocal(id: number): void {
|
||||||
@@ -117,6 +120,7 @@ export const useClipsStore = defineStore('clips', () => {
|
|||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
loaded,
|
loaded,
|
||||||
|
draft,
|
||||||
upsert,
|
upsert,
|
||||||
removeLocal,
|
removeLocal,
|
||||||
reset,
|
reset,
|
||||||
|
|||||||
@@ -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')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -23,6 +23,12 @@ export default defineConfig({
|
|||||||
display: 'standalone',
|
display: 'standalone',
|
||||||
background_color: '#0f1115',
|
background_color: '#0f1115',
|
||||||
theme_color: '#0f1115',
|
theme_color: '#0f1115',
|
||||||
|
// Android / Chrome: appear in the system share sheet; see src/utils/share.ts
|
||||||
|
share_target: {
|
||||||
|
action: '/share',
|
||||||
|
method: 'GET',
|
||||||
|
params: { title: 'title', text: 'text', url: 'url' },
|
||||||
|
},
|
||||||
icons: [
|
icons: [
|
||||||
{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
|
{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
|
||||||
{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
|
{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
|
||||||
|
|||||||
Reference in new issue
Block a user