Files
tolaria/src/utils/openNoteWindow.ts

62 lines
2.0 KiB
TypeScript
Raw Normal View History

import { isTauri } from '../mock-tauri'
2026-05-23 23:36:22 +02:00
import { shouldUseCustomWindowChrome } from './platform'
import { rememberNoteWindowParams } from './windowMode'
2026-05-02 00:02:48 +02:00
const MACOS_TRAFFIC_LIGHT_POSITION = { x: 18, y: 24 } as const
2026-05-21 10:19:49 +02:00
const APP_ORIGIN_PROTOCOLS = new Set(['http:', 'https:'])
2026-05-02 00:02:48 +02:00
export function buildNoteWindowUrl(notePath: string, vaultPath: string, noteTitle: string, windowLabel?: string): string {
const params = new URLSearchParams({
window: 'note',
path: notePath,
vault: vaultPath,
title: noteTitle,
})
if (windowLabel) {
params.set('windowLabel', windowLabel)
}
return `/?${params.toString()}`
}
2026-05-21 10:19:49 +02:00
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))
}
/**
2026-05-25 12:07:25 +02:00
* Opens a note in a new Tauri window that starts in an editor-only layout.
* In browser mode (non-Tauri), this is a no-op.
*/
export async function openNoteInNewWindow(notePath: string, vaultPath: string, noteTitle: string): Promise<void> {
if (!isTauri()) return
2026-05-02 00:02:48 +02:00
const { LogicalPosition } = await import('@tauri-apps/api/dpi')
const { WebviewWindow } = await import('@tauri-apps/api/webviewWindow')
const label = `note-${Date.now()}`
rememberNoteWindowParams(label, { notePath, vaultPath, noteTitle })
new WebviewWindow(label, {
2026-05-21 10:19:49 +02:00
url: buildRuntimeNoteWindowUrl(notePath, vaultPath, noteTitle, label),
title: noteTitle,
width: 800,
height: 700,
resizable: true,
titleBarStyle: 'overlay',
2026-05-02 00:02:48 +02:00
trafficLightPosition: new LogicalPosition(MACOS_TRAFFIC_LIGHT_POSITION.x, MACOS_TRAFFIC_LIGHT_POSITION.y),
hiddenTitle: true,
2026-05-23 23:36:22 +02:00
decorations: !shouldUseCustomWindowChrome(),
})
}