refactor(tauri): clean up external link helper

- Move use-external-link.ts → utils/external-link.ts (plain function, not a composable)
- Remove non-null assertions on providerDef.keyURL (v-if already guards)
- Remove test scaffolding from production global.d.ts
This commit is contained in:
Danila Poyarkov 2026-04-15 11:03:31 +03:00
parent 7b5a5bdeef
commit 82c390c2d2
5 changed files with 6 additions and 7 deletions

View file

@ -16,7 +16,7 @@ import ProviderSelectField from '@/components/chat/ProviderSelectField.vue'
import { useInputUI } from '@/components/ui/input'
import { usePopoverUI } from '@/components/ui/popover'
import { useAIChat } from '@/composables/use-chat'
import { openExternalLink } from '@/composables/use-external-link'
import { openExternalLink } from '@/utils/external-link'
const cls = usePopoverUI({ content: 'isolate z-[51] w-64 p-3' })
@ -298,7 +298,7 @@ function clearUnsplashKey() {
v-if="providerDef.keyURL"
type="button"
class="cursor-pointer text-[9px] text-muted underline hover:text-surface"
@click="openExternalLink(providerDef.keyURL!)"
@click="openExternalLink(providerDef.keyURL as string)"
>
Get API key →
</button>

View file

@ -5,7 +5,7 @@ import ProviderSelectField from '@/components/chat/ProviderSelectField.vue'
import { useInputUI } from '@/components/ui/input'
import { useAIChat } from '@/composables/use-chat'
import { ACP_AGENTS } from '@open-pencil/core'
import { openExternalLink } from '@/composables/use-external-link'
import { openExternalLink } from '@/utils/external-link'
import { useI18n } from '@open-pencil/vue'
const { providerID, providerDef, setAPIKey, customBaseURL, customModelID } = useAIChat()
@ -110,7 +110,7 @@ function save() {
type="button"
data-test-id="api-key-get-link"
class="mt-2.5 cursor-pointer text-[10px] text-muted underline hover:text-surface"
@click="openExternalLink(providerDef.keyURL!)"
@click="openExternalLink(providerDef.keyURL as string)"
>
{{ dialogs.getAPIKey({ provider: providerDef.name }) }}
</button>

1
src/global.d.ts vendored
View file

@ -41,5 +41,4 @@ interface Window {
// The assignment in EditorView.vue is type-safe; test code uses `!` assertion.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
__OPEN_PENCIL_STORE__?: any
__mocked_window_open?: (url?: string | URL, target?: string) => Window | null
}

View file

@ -232,7 +232,7 @@ test('"Get API key" link opens external URL via window.open', async () => {
const openedUrls: string[] = []
await page.exposeFunction('mockWindowOpen', (url: string) => openedUrls.push(url))
await page.evaluate(() => {
window.__mocked_window_open = window.open
;(window as any).__savedOpen = window.open
window.open = (url: string | URL) => {
;(window as any).mockWindowOpen(String(url))
return null
@ -248,6 +248,6 @@ test('"Get API key" link opens external URL via window.open', async () => {
// Restore
await page.evaluate(() => {
window.open = window.__mocked_window_open
window.open = (window as any).__savedOpen
})
})