Merge branch 'main' into fix/695-claude-codex-windows-spawn-shim
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { buildNoteWindowUrl, openNoteInNewWindow } from './openNoteWindow'
|
||||
import { buildNoteWindowUrl, buildRuntimeNoteWindowUrl, openNoteInNewWindow } from './openNoteWindow'
|
||||
import { isTauri } from '../mock-tauri'
|
||||
import { shouldUseLinuxWindowChrome } from './platform'
|
||||
|
||||
@@ -38,6 +38,14 @@ vi.mock('@tauri-apps/api/dpi', () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
function expectNoteWindowRoute(parsed: URL): void {
|
||||
expect(parsed.pathname).toBe('/')
|
||||
expect(parsed.searchParams.get('window')).toBe('note')
|
||||
expect(parsed.searchParams.get('path')).toBe('/vault/Folder/My Note.md')
|
||||
expect(parsed.searchParams.get('vault')).toBe('/Users/luca/Laputa Vault')
|
||||
expect(parsed.searchParams.get('title')).toBe('AI / ML')
|
||||
}
|
||||
|
||||
describe('openNoteWindow', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -52,11 +60,15 @@ describe('openNoteWindow', () => {
|
||||
const url = buildNoteWindowUrl('/vault/Folder/My Note.md', '/Users/luca/Laputa Vault', 'AI / ML')
|
||||
const parsed = new URL(url, 'https://tolaria.localhost')
|
||||
|
||||
expect(parsed.pathname).toBe('/')
|
||||
expect(parsed.searchParams.get('window')).toBe('note')
|
||||
expect(parsed.searchParams.get('path')).toBe('/vault/Folder/My Note.md')
|
||||
expect(parsed.searchParams.get('vault')).toBe('/Users/luca/Laputa Vault')
|
||||
expect(parsed.searchParams.get('title')).toBe('AI / ML')
|
||||
expectNoteWindowRoute(parsed)
|
||||
})
|
||||
|
||||
it('resolves the runtime route against the current app origin', () => {
|
||||
const url = buildRuntimeNoteWindowUrl('/vault/Folder/My Note.md', '/Users/luca/Laputa Vault', 'AI / ML')
|
||||
const parsed = new URL(url)
|
||||
|
||||
expect(parsed.origin).toBe(window.location.origin)
|
||||
expectNoteWindowRoute(parsed)
|
||||
})
|
||||
|
||||
it('does nothing outside Tauri', async () => {
|
||||
@@ -69,11 +81,12 @@ describe('openNoteWindow', () => {
|
||||
vi.mocked(isTauri).mockReturnValue(true)
|
||||
|
||||
await openNoteInNewWindow('/vault/Folder/My Note.md', '/Users/luca/Laputa Vault', 'AI / ML')
|
||||
const expectedUrl = `${window.location.origin}/?window=note&path=%2Fvault%2FFolder%2FMy+Note.md&vault=%2FUsers%2Fluca%2FLaputa+Vault&title=AI+%2F+ML&windowLabel=note-1776182400000`
|
||||
|
||||
expect(webviewWindowCalls).toHaveBeenCalledWith(
|
||||
'note-1776182400000',
|
||||
expect.objectContaining({
|
||||
url: '/?window=note&path=%2Fvault%2FFolder%2FMy+Note.md&vault=%2FUsers%2Fluca%2FLaputa+Vault&title=AI+%2F+ML&windowLabel=note-1776182400000',
|
||||
url: expectedUrl,
|
||||
title: 'AI / ML',
|
||||
width: 800,
|
||||
height: 700,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { shouldUseLinuxWindowChrome } from './platform'
|
||||
import { rememberNoteWindowParams } from './windowMode'
|
||||
|
||||
const MACOS_TRAFFIC_LIGHT_POSITION = { x: 18, y: 24 } as const
|
||||
const APP_ORIGIN_PROTOCOLS = new Set(['http:', 'https:'])
|
||||
|
||||
export function buildNoteWindowUrl(notePath: string, vaultPath: string, noteTitle: string, windowLabel?: string): string {
|
||||
const params = new URLSearchParams({
|
||||
@@ -19,6 +20,21 @@ export function buildNoteWindowUrl(notePath: string, vaultPath: string, noteTitl
|
||||
return `/?${params.toString()}`
|
||||
}
|
||||
|
||||
function resolveNoteWindowUrlForRuntime(route: string): string {
|
||||
if (!APP_ORIGIN_PROTOCOLS.has(window.location.protocol)) return route
|
||||
|
||||
return new URL(route, window.location.origin).toString()
|
||||
}
|
||||
|
||||
export function buildRuntimeNoteWindowUrl(
|
||||
notePath: string,
|
||||
vaultPath: string,
|
||||
noteTitle: string,
|
||||
windowLabel?: string,
|
||||
): string {
|
||||
return resolveNoteWindowUrlForRuntime(buildNoteWindowUrl(notePath, vaultPath, noteTitle, windowLabel))
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a note in a new Tauri window with a minimal editor-only layout.
|
||||
* In browser mode (non-Tauri), this is a no-op.
|
||||
@@ -32,7 +48,7 @@ export async function openNoteInNewWindow(notePath: string, vaultPath: string, n
|
||||
rememberNoteWindowParams(label, { notePath, vaultPath, noteTitle })
|
||||
|
||||
new WebviewWindow(label, {
|
||||
url: buildNoteWindowUrl(notePath, vaultPath, noteTitle, label),
|
||||
url: buildRuntimeNoteWindowUrl(notePath, vaultPath, noteTitle, label),
|
||||
title: noteTitle,
|
||||
width: 800,
|
||||
height: 700,
|
||||
|
||||
Reference in New Issue
Block a user