fix: open vault files externally
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { openPath, revealItemInDir } from '@tauri-apps/plugin-opener'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { revealItemInDir } from '@tauri-apps/plugin-opener'
|
||||
import {
|
||||
copyLocalPath,
|
||||
normalizeExternalUrl,
|
||||
@@ -8,6 +9,10 @@ import {
|
||||
revealLocalPath,
|
||||
} from './url'
|
||||
|
||||
vi.mock('@tauri-apps/api/core', () => ({
|
||||
invoke: vi.fn(),
|
||||
}))
|
||||
|
||||
const originalClipboard = navigator.clipboard
|
||||
|
||||
function setClipboard(writeText: (value: string) => Promise<void>) {
|
||||
@@ -55,12 +60,15 @@ describe('local file actions', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('opens local paths through the Tauri opener plugin', async () => {
|
||||
it('opens local paths through the vault-scoped backend command', async () => {
|
||||
vi.stubGlobal('isTauri', true)
|
||||
|
||||
await openLocalFile('/vault/attachments/report.pdf')
|
||||
await openLocalFile('/vault/attachments/report.pdf', '/vault')
|
||||
|
||||
expect(openPath).toHaveBeenCalledWith('/vault/attachments/report.pdf')
|
||||
expect(invoke).toHaveBeenCalledWith('open_vault_file_external', {
|
||||
path: '/vault/attachments/report.pdf',
|
||||
vaultPath: '/vault',
|
||||
})
|
||||
})
|
||||
|
||||
it('reveals local paths through the Tauri opener plugin', async () => {
|
||||
|
||||
@@ -50,10 +50,12 @@ export async function openExternalUrl(url: string): Promise<void> {
|
||||
}
|
||||
|
||||
/** Open a local file path with the system default app (e.g. TextEdit for .json). */
|
||||
export async function openLocalFile(absolutePath: string): Promise<void> {
|
||||
export async function openLocalFile(absolutePath: string, vaultPath?: string): Promise<void> {
|
||||
if (isTauri()) {
|
||||
const { openPath } = await import('@tauri-apps/plugin-opener')
|
||||
await openPath(absolutePath)
|
||||
const { invoke } = await import('@tauri-apps/api/core')
|
||||
const args: { path: string; vaultPath?: string } = { path: absolutePath }
|
||||
if (vaultPath) args.vaultPath = vaultPath
|
||||
await invoke('open_vault_file_external', args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user