Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prism",
"version": "0.117.5",
"version": "0.117.6",
"description": "A fast, universal media viewer for Windows.",
"author": "Max",
"license": "MIT",
Expand Down
29 changes: 28 additions & 1 deletion src/main/browse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mkdtempSync, mkdirSync, rmSync, symlinkSync, writeFileSync } from 'fs'
import { join } from 'path'
import { tmpdir } from 'os'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { browseDirectory } from './browse'
import { browseDirectory, browseLocations } from './browse'
import {
grantDesktopDirectory,
insideDesktop,
Expand Down Expand Up @@ -190,3 +190,30 @@ it('preserves terminal pin slots for remapping and refuses nonexistent slots', (
{ id: 'terminal', path: 'term:slot-1', dir: 'left', termSlot: 1 }
])
})

describe('browseLocations', () => {
const getPath = (key: string): string => `C:\\Users\\me\\${key}`
const dir = { isDirectory: () => true }

it('a hung drive is left out after its time limit, not waited on (2026-10-16)', async () => {
const hung = new Promise<never>(() => {})
const probe = (p: string): Promise<{ isDirectory(): boolean }> =>
p === 'Z:\\' || p.endsWith('desktop') ? hung : Promise.resolve(dir)
const t = Date.now()
const places = await browseLocations(getPath, probe, 50)
expect(Date.now() - t).toBeLessThan(1000)
expect(places.some((p) => p.path === 'Z:\\' || p.known === 'desktop')).toBe(false)
expect(places.find((p) => p.known === 'downloads')?.path).toBe('C:\\Users\\me\\downloads')
})

it('gives Home without asking the disk', async () => {
const asked: string[] = []
const probe = (p: string): Promise<{ isDirectory(): boolean }> => {
asked.push(p)
return Promise.reject(new Error('ENOENT'))
}
const places = await browseLocations(getPath, probe, 50)
expect(places.map((p) => p.name)).toEqual(['Home'])
expect(asked).not.toContain('C:\\Users\\me\\home')
})
})
39 changes: 33 additions & 6 deletions src/main/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,36 @@ export async function browseDirectory(

type CommonPath = 'home' | 'desktop' | 'downloads' | 'documents' | 'pictures' | 'music' | 'videos'

/** How long one place may take to answer before it is left out. */
const PLACE_STAT_MS = 1500

/** A stat that gives up: a hung mapped or network drive never answers in time. */
function within<T>(work: Promise<T>, ms: number): Promise<T | null> {
return new Promise((done) => {
const timer = setTimeout(() => done(null), ms)
work.then(
(value) => {
clearTimeout(timer)
done(value)
},
() => {
clearTimeout(timer)
done(null)
}
)
})
}

/**
* The Places list. Each place is probed with its own time limit, and Home is
* given without one (2026-10-16): all 26 drive letters were stat'ed with no
* limit, so one hung mapped or network drive held Places, and New Tab (which
* asks only to find Home), for as long as the SMB timeout.
*/
export async function browseLocations(
getPath: (key: CommonPath) => string
getPath: (key: CommonPath) => string,
probe: (path: string) => Promise<{ isDirectory(): boolean }> = (p) => stat(p),
ms = PLACE_STAT_MS
): Promise<BrowseShortcut[]> {
const common: Array<[CommonPath, string]> = [
['home', 'Home'],
Expand Down Expand Up @@ -116,11 +144,10 @@ export async function browseLocations(
}
const found = await Promise.all(
shortcuts.map(async (entry) => {
try {
return (await stat(entry.path)).isDirectory() ? entry : null
} catch {
return null
}
// The user's own folder exists; it is what New Tab waits for.
if (entry.known === 'home') return entry
const info = await within(probe(entry.path), ms)
return info?.isDirectory() ? entry : null
})
)
return found.filter((entry): entry is BrowseShortcut => entry !== null)
Expand Down
23 changes: 23 additions & 0 deletions src/main/fileClipboard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it, vi } from 'vitest'

const execFile = vi.fn()
vi.mock('child_process', () => ({ execFile }))

const { hasWindowsFiles } = await import('./fileClipboard')

describe('hasWindowsFiles', () => {
it('answers from the format list and spawns nothing (2026-10-16: a PowerShell per right-click)', () => {
expect(hasWindowsFiles(() => ['text/plain', 'text/uri-list'])).toBe(true)
expect(hasWindowsFiles(() => ['text/plain', 'image/png'])).toBe(false)
expect(hasWindowsFiles(() => [])).toBe(false)
expect(execFile).not.toHaveBeenCalled()
})

it('a clipboard that will not answer has no files', () => {
expect(
hasWindowsFiles(() => {
throw new Error('clipboard busy')
})
).toBe(false)
})
})
17 changes: 17 additions & 0 deletions src/main/fileClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ interface WindowsFileClipboard {
cut: boolean | null
}

/**
* Are there files on the clipboard? Asked every time a menu OPENS, to decide
* whether to draw Paste. It used to go through `readWindowsFiles` - a
* PowerShell with WinForms per right-click, so the Paste row arrived hundreds
* of ms late and shifted the menu, and fast clicks stacked processes
* (2026-10-16). Presence needs no list: Chromium reports CF_HDROP as
* 'text/uri-list' in `availableFormats()` (and the e2e fake does the same).
* PowerShell stays for the paste itself, which needs every path.
*/
export function hasWindowsFiles(availableFormats: () => string[]): boolean {
try {
return availableFormats().includes('text/uri-list')
} catch {
return false
}
}

/** Native copy/cut metadata takes precedence over Prism's legacy cut mark. */
export function readWindowsFiles(): Promise<WindowsFileClipboard> {
if (E2E) {
Expand Down
55 changes: 54 additions & 1 deletion src/main/folderSizeCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { tmpdir } from 'os'
import { join } from 'path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { FolderSizeResult } from '@shared/folderSize'
import { FolderSizeCache } from './folderSizeCache'
import { existsSync, readdirSync } from 'fs'
import { FolderSizeCache, outermostKeys } from './folderSizeCache'

vi.mock('fs/promises', async (importOriginal) => ({
...(await importOriginal<typeof import('fs/promises')>())
Expand Down Expand Up @@ -360,3 +361,55 @@ describe('persistent folder size cache', () => {
expect((await readdir(directory)).filter((name) => name.endsWith('.json'))).toHaveLength(2)
})
})

describe('the invalidation journal (2026-10-16: re-read per lookup, written per folder)', () => {
it('collapses changed folders to the outermost ones', () => {
const k = (...parts: string[]): string => join(...parts).toLowerCase()
const a = k(box, 'a')
expect(outermostKeys([k(a, 'x', 'y'), a, k(a, 'x'), k(box, 'ab'), a]).sort()).toEqual(
[a, k(box, 'ab')].sort()
)
const drive = join(box.slice(0, 3)).toLowerCase()
expect(outermostKeys([drive, a])).toEqual([drive])
})

it('writes one marker for a burst inside one changed folder', async () => {
const cache = new FolderSizeCache({ directory })
const real = await fs.realpath(root)
await cache.invalidate([
real,
...Array.from({ length: 300 }, (_, i) => join(real, 'node_modules', `pkg-${i}`, 'lib'))
])
expect(await readdir(join(directory, 'invalidations'))).toHaveLength(1)
expect(await fs.readFile(join(directory, 'generation'), 'utf8').catch(() => '')).toBe('')
})

it('reads the marker files once, not once per lookup', async () => {
const cache = new FolderSizeCache({ directory })
await cache.get(root, controller().signal)
await new FolderSizeCache({ directory }).invalidate([join(box, 'elsewhere')])
// A journal changed in the last clock ticks is never kept; let it settle.
await new Promise((settle) => setTimeout(settle, 150))
await cache.readCached([root])
const readFile = vi.spyOn(fs, 'readFile')
await cache.readCached([root])
await cache.readCached([root])
const markerReads = readFile.mock.calls.filter(([path]) => String(path).includes('invalidations'))
expect(markerReads).toHaveLength(0)
})

it('answers with a change before its marker is on disk', async () => {
const cache = new FolderSizeCache({ directory })
await cache.get(root, controller().signal)
let early: Promise<Record<string, FolderSizeResult>> | null = null
let onDisk: string[] | null = null
await cache.invalidate([join(await fs.realpath(root), 'data')], () => {
onDisk = existsSync(join(directory, 'invalidations'))
? readdirSync(join(directory, 'invalidations'))
: []
early = cache.readCached([root])
})
expect(onDisk).toEqual([])
expect((await early!)[root].stale).toBe(true)
})
})
Loading
Loading