Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

perf: lower idle and interaction cost; consistent hover pill on image cards

Deepender25151a20c3ef16
diff --git a/electron.vite.config.ts b/electron.vite.config.ts
index 639060a..b761e2c 100644
--- a/electron.vite.config.ts
+++ b/electron.vite.config.ts
@@ -33,6 +33,9 @@ export default defineConfig({
}
},
build: {
+ // electron-vite leaves the renderer unminified by default; Chromium keeps
+ // every loaded script's source in memory, and parses it at startup.
+ minify: 'esbuild',
rollupOptions: {
input: { index: resolve(__dirname, 'index.html') }
}
diff --git a/electron/main/drag.ts b/electron/main/drag.ts
index bca6e09..5408c17 100644
--- a/electron/main/drag.ts
+++ b/electron/main/drag.ts
@@ -20,7 +20,7 @@ import { join, extname } from 'node:path'
import { getUnpackagedTempDir, toUnpackagedFilePaths } from '../store/paths'
import type { DragRequest, ItemData } from '../../shared/types'
import { getStore } from './state'
-import { getFileKind } from '../../src/lib/fileType'
+import { fileKindOf } from '../../src/lib/fileKind'
import { recordStagedFiles } from './stagedTemp'
function stampForFilename(capturedAt?: number): string {
@@ -390,7 +390,7 @@ function createFileStackDragIcon(paths: string[], entries?: Array<{ isDirectory?
}
} catch {}
}
- return getFileKind(p, isDir).kind
+ return fileKindOf(p, isDir)
})
const cacheKey = `stack|svg|${kinds.join('-')}|${count}`
const cached = iconCache.get(cacheKey)
diff --git a/electron/main/fileSvg.ts b/electron/main/fileSvg.ts
index d03ee92..ac5bed5 100644
--- a/electron/main/fileSvg.ts
+++ b/electron/main/fileSvg.ts
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { app } from 'electron'
-import type { FileKind } from '../../src/lib/fileType'
+import type { FileKind } from '../../src/lib/fileKind'
/**
* Drag-ghost artwork from the file-kind SVG set (resources/file-icons, one
diff --git a/src/components/ClipboardItem.tsx b/src/components/ClipboardItem.tsx
index fcc3c20..6782134 100644
--- a/src/components/ClipboardItem.tsx
+++ b/src/components/ClipboardItem.tsx
@@ -70,20 +70,20 @@ const ClipboardItemBase = forwardRef<HTMLDivElement, Props>(({ item }, ref) => {
const startDrag = useDragOut()
const [copied, setCopied] = useState(false)
- const settings = useStore((s) => s.settings)
- const isHorizontal = settings.stickPosition === 'top'
+ // Narrow subscriptions: a card re-renders only when what it shows changes
+ // (not on every settings write, or when another card previews / expands).
+ const isHorizontal = useStore((s) => s.settings.stickPosition === 'top')
const colorInfo = item.data.kind === 'text' ? parseColor(item.data.text) : null
// Accordion expansion: ONE stack open at a time, coordinated store-wide
// (expanding another stack collapses this one; Escape / outside click /
// filter or settings switches collapse via the same store field).
- const expandedStackId = useStore((s) => s.expandedStackId)
- const expanded = expandedStackId === item.id
+ const expanded = useStore((s) => s.expandedStackId === item.id)
const setExpandedFlag = useCallback((v: boolean) => {
useStore.getState().setExpandedStackId(v ? item.id : null)
}, [item.id])
- const isPreviewing = useStore((s) => s.previewItemId) === item.id
+ const isPreviewing = useStore((s) => s.previewItemId === item.id)
const isMenuTarget = useStore((s) => s.cardMenu?.itemId === item.id)
const isBundle = (item.data.kind === 'files' && item.data.paths.length > 1) || item.data.kind === 'image-collection'
const isSingleImage = item.data.kind === 'image' || (
@@ -716,7 +716,7 @@ function HorizontalBundleExpanded({
onDragStart: (e: React.DragEvent, req: DragRequest) => void
}) {
const { t } = useTranslation()
- const isPreviewing = useStore((s) => s.previewItemId) === item.id
+ const isPreviewing = useStore((s) => s.previewItemId === item.id)
const isImageCollection = item.data.kind === 'image-collection'
const isFiles = item.data.kind === 'files'
const images = item.data.kind === 'image-collection' ? item.data.images : []
diff --git a/src/components/EmojiPicker.tsx b/src/components/EmojiPicker.tsx
index 410255c..3a03ba7 100644
--- a/src/components/EmojiPicker.tsx
+++ b/src/components/EmojiPicker.tsx
@@ -13,7 +13,7 @@ import {
type EmojiEntry
} from '../lib/emoji/catalog'
import { glyphSrc, glyphsVersion, loadGlyphs, setScreenGlyphCount, subscribeGlyphs } from '../lib/emoji/glyphCache'
-import { loadEmojiCatalog } from '../lib/emoji/load'
+import { loadEmojiCatalog, peekEmojiCatalog } from '../lib/emoji/load'
import { loadRecents, saveRecents } from '../lib/emoji/prefs'
import { useStore } from '../store/appStore'
import { playButtonClickSound } from '../lib/soundEffects'
@@ -27,6 +27,14 @@ const PASTE_GAP_MS = 180
const TONE_POP_W = 216
const TONE_POP_H = 44
+/**
+ * The grid's last measured size. The picker is unmounted once the shelf has
+ * closed (Panel) and mounts again on the next open; starting from the last
+ * size (and the already-loaded catalog) makes that first frame identical to
+ * re-showing a kept picker: no skeleton flash, no wrong column count.
+ */
+const lastView = { w: 0, h: 320 }
+
interface TonePopup {
entry: EmojiEntry
left: number
@@ -67,13 +75,13 @@ export function EmojiPicker({
const pasteEmoji = useStore((s) => s.pasteEmoji)
const category = useStore((s) => s.emojiCategory)
const setCategory = useStore((s) => s.setEmojiCategory)
- const [catalog, setCatalog] = useState<EmojiCatalog | null>(null)
+ const [catalog, setCatalog] = useState<EmojiCatalog | null>(peekEmojiCatalog)
const [roomy, setRoomy] = useState(false)
const [failed, setFailed] = useState(false)
const [recents, setRecents] = useState<string[]>(loadRecents)
const [scrollTop, setScrollTop] = useState(0)
- const [viewW, setViewW] = useState(0)
- const [viewH, setViewH] = useState(320)
+ const [viewW, setViewW] = useState(lastView.w)
+ const [viewH, setViewH] = useState(lastView.h)
const [tonePop, setTonePop] = useState<TonePopup | null>(null)
const scrollerRef = useRef<HTMLDivElement>(null)
const pickerRef = useRef<HTMLDivElement>(null)
@@ -146,8 +154,14 @@ export function EmojiPicker({
const apply = () => {
const h = el.clientHeight
const w = el.clientWidth
- if (h > 0) setViewH(h)
- if (w > 0) setViewW(w)
+ if (h > 0) {
+ lastView.h = h
+ setViewH(h)
+ }
+ if (w > 0) {
+ lastView.w = w
+ setViewW(w)
+ }
}
const ro = new ResizeObserver(apply)
ro.observe(el)
diff --git a/src/components/ItemList.tsx b/src/components/ItemList.tsx
index 5352f4e..c0145a8 100644
--- a/src/components/ItemList.tsx
+++ b/src/components/ItemList.tsx
@@ -29,8 +29,9 @@ export function ItemList() {
const total = pinned.length + recent.length
const isDraggingAny = useStore((s) => !!s.dragActive || !!s.internalDragReq)
- const settings = useStore((s) => s.settings)
- const isHorizontal = settings.stickPosition === 'top'
+ const stickPosition = useStore((s) => s.settings.stickPosition)
+ const reduceMotion = useStore((s) => !!s.settings.reduceMotion)
+ const isHorizontal = stickPosition === 'top'
const typeFilter = useStore((s) => s.typeFilter) || 'all'
const filterScrollMap = useRef<Record<string, { top: number; left: number }>>({})
@@ -187,17 +188,17 @@ export function ItemList() {
}, [query, isHorizontal])
// Reset scroll map when switching dock position
- const prevStickPos = useRef(settings.stickPosition)
+ const prevStickPos = useRef(stickPosition)
useLayoutEffect(() => {
- if (prevStickPos.current !== settings.stickPosition) {
- prevStickPos.current = settings.stickPosition
+ if (prevStickPos.current !== stickPosition) {
+ prevStickPos.current = stickPosition
filterScrollMap.current = {}
if (listRef.current) {
listRef.current.scrollTop = 0
listRef.current.scrollLeft = 0
}
}
- }, [settings.stickPosition])
+ }, [stickPosition])
useEffect(() => {
if (!isDraggingAny) {
@@ -337,7 +338,18 @@ export function ItemList() {
stopScrolling()
}
+ // A filter or search change replays the list's short fade-in. The list used
+ // to be keyed on this for that, which destroyed and rebuilt every card on
+ // each keystroke; keeping it lets unchanged cards stay and replays the same
+ // fade (started before paint, so the first frame is already at 0.45).
const filterKey = `${typeFilter}:${query}`
+ const stackRef = useRef<HTMLDivElement>(null)
+ const hasStack = total > 0
+ useLayoutEffect(() => {
+ const el = stackRef.current
+ if (!el || typeof el.animate !== 'function') return
+ el.animate([{ opacity: 0.45 }, { opacity: 1 }], { duration: 120, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' })
+ }, [filterKey, hasStack])
return (
<div
@@ -351,13 +363,7 @@ export function ItemList() {
{total === 0 ? (
<EmptyState filtered={query.trim().length > 0} />
) : (
- <motion.div
- key={filterKey}
- className="list-stack"
- initial={{ opacity: 0.45 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.12, ease: [0.22, 1, 0.36, 1] }}
- >
+ <div ref={stackRef} className="list-stack">
{pinned.length > 0 && (
<section className="pinned-section">
<div
@@ -413,7 +419,7 @@ export function ItemList() {
))}
</section>
)}
- </motion.div>
+ </div>
)}
<AnimatePresence>
@@ -422,7 +428,7 @@ export function ItemList() {
initial={{ opacity: 0, scale: 0.85 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.85 }}
- transition={{ duration: settings.reduceMotion ? 0.01 : 0.14, ease: 'easeOut' }}
+ transition={{ duration: reduceMotion ? 0.01 : 0.14, ease: 'easeOut' }}
className={`scroll-top-btn${isHorizontal ? ' horizontal' : ''}`}
onClick={scrollToTop}
title={t('item.scrollToTop')}
diff --git a/src/components/Panel.tsx b/src/components/Panel.tsx
index 3074861..ec4ecb1 100644
--- a/src/components/Panel.tsx
+++ b/src/components/Panel.tsx
@@ -68,10 +68,15 @@ export function Panel() {
const setQuery = useStore((s) => s.setQuery)
const emojiOpen = useStore((s) => s.emojiOpen)
const setEmojiOpen = useStore((s) => s.setEmojiOpen)
- // Mount the picker on first open, then keep it. Tearing it (and ItemList)
- // down on every smile click is what made the switch hitch.
+ // Mount the picker on first open and keep it while the shelf stays open.
+ // Tearing it (and ItemList) down on every smile click is what made the
+ // switch hitch. Once the shelf has closed and the picker is no longer shown
+ // it is freed: its grid, images and glyph state would otherwise stay in
+ // memory for the rest of the session. Every open lands on the first page
+ // anyway, so the next mount looks the same.
const emojiMountedRef = useRef(false)
if (emojiOpen) emojiMountedRef.current = true
+ else if (!open) emojiMountedRef.current = false
const emojiMounted = emojiMountedRef.current
const edgeHintActive = useStore((s) => s.edgeHintActive)
const edgeTransition = useStore((s) => s.edgeTransition)
diff --git a/src/components/StackItems.tsx b/src/components/StackItems.tsx
index b1f5771..17015da 100644
--- a/src/components/StackItems.tsx
+++ b/src/components/StackItems.tsx
@@ -247,7 +247,7 @@ export function StackHeader({
onRemove?: () => void
}) {
const { t } = useTranslation()
- const isPreviewing = useStore((s) => s.previewItemId) === item.id
+ const isPreviewing = useStore((s) => s.previewItemId === item.id)
const total = stackTotalSize(item)
return (
<div
diff --git a/src/lib/fileKind.ts b/src/lib/fileKind.ts
new file mode 100644
index 0000000..e760c6d
--- /dev/null
+++ b/src/lib/fileKind.ts
@@ -0,0 +1,89 @@
+/**
+ * File kind by extension: the pure, dependency-free part of fileType.ts.
+ *
+ * Kept separate because the main process needs the kind (drag icons) and
+ * nothing else; fileType.ts adds translated labels, and importing it would
+ * pull the i18n module and with it the renderer's whole store (and sound,
+ * emoji, ...) into the main-process bundle.
+ */
+
+/** Semantic category a file falls into for display purposes. */
+export type FileKind =
+ | 'pdf'
+ | 'word'
+ | 'excel'
+ | 'powerpoint'
+ | 'archive'
+ | 'text'
+ | 'code'
+ | 'audio'
+ | 'video'
+ | 'image'
+ | 'executable'
+ | 'folder'
+ | 'file' // generic fallback
+
+export interface FileKindInfo {
+ kind: FileKind
+ /** Short human label, e.g. "PDF", "Word". */
+ label: string
+ /** Hex color used to tint the file icon / badge. */
+ color: string
+}
+
+/** Extension sets per category. Compared case-insensitively. */
+export const EXT_MAP: Record<string, FileKind> = {
+ pdf: 'pdf',
+ doc: 'word', docx: 'word', docm: 'word', odt: 'word', rtf: 'word', pages: 'word',
+ xls: 'excel', xlsx: 'excel', xlsm: 'excel', csv: 'excel', ods: 'excel', numbers: 'excel',
+ ppt: 'powerpoint', pptx: 'powerpoint', pptm: 'powerpoint', odp: 'powerpoint', key: 'powerpoint',
+ zip: 'archive', rar: 'archive', '7z': 'archive', tar: 'archive', gz: 'archive', bz2: 'archive', xz: 'archive', iso: 'archive',
+ txt: 'text', md: 'text', markdown: 'text', log: 'text', rtf2: 'text',
+ js: 'code', ts: 'code', jsx: 'code', tsx: 'code', json: 'code', html: 'code', css: 'code', scss: 'code',
+ py: 'code', java: 'code', c: 'code', cpp: 'code', cs: 'code', go: 'code', rs: 'code', rb: 'code',
+ php: 'code', sh: 'code', yml: 'code', yaml: 'code', xml: 'code', sql: 'code', vue: 'code', svelte: 'code',
+ mp3: 'audio', wav: 'audio', flac: 'audio', aac: 'audio', ogg: 'audio', m4a: 'audio', wma: 'audio',
+ mp4: 'video', mkv: 'video', avi: 'video', mov: 'video', wmv: 'video', flv: 'video', webm: 'video', m4v: 'video',
+ png: 'image', jpg: 'image', jpeg: 'image', gif: 'image', webp: 'image', bmp: 'image', svg: 'image', avif: 'image', ico: 'image',
+ tif: 'image', tiff: 'image', jfif: 'image', pjpeg: 'image', pjp: 'image',
+ exe: 'executable', msi: 'executable', bat: 'executable', cmd: 'executable', ps1: 'executable', apk: 'executable', app: 'executable', dll: 'executable', dmg: 'executable', pkg: 'executable', deb: 'executable', rpm: 'executable', appx: 'executable', msix: 'executable', appinstaller: 'executable',
+ folder: 'folder'
+}
+
+export const KIND_INFO: Record<FileKind, FileKindInfo> = {
+ pdf: { kind: 'pdf', label: 'PDF', color: '#EF4444' },
+ word: { kind: 'word', label: 'Word', color: '#3B9CFF' },
+ excel: { kind: 'excel', label: 'Excel', color: '#10B981' },
+ powerpoint: { kind: 'powerpoint', label: 'Slides', color: '#FF6B35' },
+ archive: { kind: 'archive', label: 'Archive', color: '#F59E0B' },
+ text: { kind: 'text', label: 'Text', color: '#94A3B8' },
+ code: { kind: 'code', label: 'Code', color: '#818CF8' },
+ audio: { kind: 'audio', label: 'Audio', color: '#F43F5E' },
+ video: { kind: 'video', label: 'Video', color: '#A855F7' },
+ image: { kind: 'image', label: 'Image', color: '#06B6D4' },
+ executable: { kind: 'executable', label: 'Installer', color: '#F59E0B' },
+ folder: { kind: 'folder', label: 'Folder', color: '#FFDA44' },
+ file: { kind: 'file', label: 'File', color: '#CBD5E1' }
+}
+
+/** Extract the lowercase extension (no dot) from a path. */
+export function extOf(path: string): string {
+ const dot = path.lastIndexOf('.')
+ if (dot < 0) return ''
+ // Guard against directory-ish trailing dots and keep it lowercase.
+ return path.slice(dot + 1).toLowerCase()
+}
+
+/** The kind alone (same answer as `getFileKind(path, isDirectory).kind`). */
+export function fileKindOf(path: string, isDirectory?: boolean): FileKind {
+ if (isDirectory) return 'folder'
+ return EXT_MAP[extOf(path)] ?? 'file'
+}
+
+/**
+ * edgelocal:// URL for a file-kind folder icon (SVG, see resources/file-icons).
+ * Same hardcoded-scheme convention as the emoji catalog (`edgelocal://emoji/…`).
+ */
+export function fileIconUrl(kind: FileKind): string {
+ return `edgelocal://icon/${kind}.svg`
+}
diff --git a/src/lib/fileType.ts b/src/lib/fileType.ts
index a94d7d3..ada9820 100644
--- a/src/lib/fileType.ts
+++ b/src/lib/fileType.ts
@@ -2,78 +2,15 @@
* File-type awareness for non-image files.
*
* Maps a file path (by extension) to a stable category used for icon tinting,
- * labels, and kind badges. Kept dependency-free: one small lookup table plus a
- * tinted-file-icon renderer, no per-format rendering libs.
+ * labels, and kind badges, with the labels translated. The kind tables live in
+ * fileKind.ts (no i18n), which the main process imports directly.
*/
-/** Semantic category a file falls into for display purposes. */
-export type FileKind =
- | 'pdf'
- | 'word'
- | 'excel'
- | 'powerpoint'
- | 'archive'
- | 'text'
- | 'code'
- | 'audio'
- | 'video'
- | 'image'
- | 'executable'
- | 'folder'
- | 'file' // generic fallback
-
-export interface FileKindInfo {
- kind: FileKind
- /** Short human label, e.g. "PDF", "Word". */
- label: string
- /** Hex color used to tint the file icon / badge. */
- color: string
-}
-
-/** Extension sets per category. Compared case-insensitively. */
-const EXT_MAP: Record<string, FileKind> = {
- pdf: 'pdf',
- doc: 'word', docx: 'word', docm: 'word', odt: 'word', rtf: 'word', pages: 'word',
- xls: 'excel', xlsx: 'excel', xlsm: 'excel', csv: 'excel', ods: 'excel', numbers: 'excel',
- ppt: 'powerpoint', pptx: 'powerpoint', pptm: 'powerpoint', odp: 'powerpoint', key: 'powerpoint',
- zip: 'archive', rar: 'archive', '7z': 'archive', tar: 'archive', gz: 'archive', bz2: 'archive', xz: 'archive', iso: 'archive',
- txt: 'text', md: 'text', markdown: 'text', log: 'text', rtf2: 'text',
- js: 'code', ts: 'code', jsx: 'code', tsx: 'code', json: 'code', html: 'code', css: 'code', scss: 'code',
- py: 'code', java: 'code', c: 'code', cpp: 'code', cs: 'code', go: 'code', rs: 'code', rb: 'code',
- php: 'code', sh: 'code', yml: 'code', yaml: 'code', xml: 'code', sql: 'code', vue: 'code', svelte: 'code',
- mp3: 'audio', wav: 'audio', flac: 'audio', aac: 'audio', ogg: 'audio', m4a: 'audio', wma: 'audio',
- mp4: 'video', mkv: 'video', avi: 'video', mov: 'video', wmv: 'video', flv: 'video', webm: 'video', m4v: 'video',
- png: 'image', jpg: 'image', jpeg: 'image', gif: 'image', webp: 'image', bmp: 'image', svg: 'image', avif: 'image', ico: 'image',
- tif: 'image', tiff: 'image', jfif: 'image', pjpeg: 'image', pjp: 'image',
- exe: 'executable', msi: 'executable', bat: 'executable', cmd: 'executable', ps1: 'executable', apk: 'executable', app: 'executable', dll: 'executable', dmg: 'executable', pkg: 'executable', deb: 'executable', rpm: 'executable', appx: 'executable', msix: 'executable', appinstaller: 'executable',
- folder: 'folder'
-}
-
-const KIND_INFO: Record<FileKind, FileKindInfo> = {
- pdf: { kind: 'pdf', label: 'PDF', color: '#EF4444' },
- word: { kind: 'word', label: 'Word', color: '#3B9CFF' },
- excel: { kind: 'excel', label: 'Excel', color: '#10B981' },
- powerpoint: { kind: 'powerpoint', label: 'Slides', color: '#FF6B35' },
- archive: { kind: 'archive', label: 'Archive', color: '#F59E0B' },
- text: { kind: 'text', label: 'Text', color: '#94A3B8' },
- code: { kind: 'code', label: 'Code', color: '#818CF8' },
- audio: { kind: 'audio', label: 'Audio', color: '#F43F5E' },
- video: { kind: 'video', label: 'Video', color: '#A855F7' },
- image: { kind: 'image', label: 'Image', color: '#06B6D4' },
- executable: { kind: 'executable', label: 'Installer', color: '#F59E0B' },
- folder: { kind: 'folder', label: 'Folder', color: '#FFDA44' },
- file: { kind: 'file', label: 'File', color: '#CBD5E1' }
-}
-
-/** Extract the lowercase extension (no dot) from a path. */
-export function extOf(path: string): string {
- const dot = path.lastIndexOf('.')
- if (dot < 0) return ''
- // Guard against directory-ish trailing dots and keep it lowercase.
- return path.slice(dot + 1).toLowerCase()
-}
-
import { t } from '../i18n'
+import { EXT_MAP, KIND_INFO, fileKindOf, type FileKind, type FileKindInfo } from './fileKind'
+
+export { extOf, fileIconUrl, fileKindOf } from './fileKind'
+export type { FileKind, FileKindInfo } from './fileKind'
const KEY_MAP: Record<FileKind, any> = {
pdf: 'fileKinds.pdf',
@@ -106,8 +43,7 @@ export function getFileKind(path: string, isDirectory?: boolean): FileKindInfo {
label: translateKind('fileKinds.folder', base.label)
}
}
- const ext = extOf(path)
- const kind = EXT_MAP[ext] ?? 'file'
+ const kind = fileKindOf(path)
const base = KIND_INFO[kind]
return {
...base,
@@ -131,11 +67,3 @@ export function getFileKindByExt(ext: string, isDirectory?: boolean): FileKindIn
label: translateKind(KEY_MAP[kind], base.label)
}
}
-
-/**
- * edgelocal:// URL for a file-kind folder icon (SVG, see resources/file-icons).
- * Same hardcoded-scheme convention as the emoji catalog (`edgelocal://emoji/…`).
- */
-export function fileIconUrl(kind: FileKind): string {
- return `edgelocal://icon/${kind}.svg`
-}
diff --git a/src/lib/format.ts b/src/lib/format.ts
index fdeab1d..3b384d1 100644
--- a/src/lib/format.ts
+++ b/src/lib/format.ts
@@ -19,6 +19,31 @@ export function formatBytes(bytes: number): string {
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
}
+// Every card shows a relative time, so the list formats hundreds at once.
+// Building an Intl formatter is far costlier than using one; reuse them.
+const relativeFormats = new Map<string, Intl.RelativeTimeFormat>()
+const dateFormats = new Map<string, Intl.DateTimeFormat>()
+
+function relativeFormat(lang: string, style: 'narrow' | 'short'): Intl.RelativeTimeFormat {
+ const key = `${lang}|${style}`
+ let f = relativeFormats.get(key)
+ if (!f) {
+ f = new Intl.RelativeTimeFormat(lang, { numeric: 'always', style })
+ relativeFormats.set(key, f)
+ }
+ return f
+}
+
+/** Same output as `date.toLocaleDateString(lang)` (numeric year, month, day). */
+function dateFormat(lang: string): Intl.DateTimeFormat {
+ let f = dateFormats.get(lang)
+ if (!f) {
+ f = new Intl.DateTimeFormat(lang, { year: 'numeric', month: 'numeric', day: 'numeric' })
+ dateFormats.set(lang, f)
+ }
+ return f
+}
+
/** Relative time formatted with native Intl locale rules (e.g. "2 дня назад", "3 hours ago"). */
export function relativeTime(ts: number): string {
const diff = Date.now() - ts
@@ -28,18 +53,18 @@ export function relativeTime(ts: number): string {
const lang = getResolvedLanguage()
try {
- const rtf = new Intl.RelativeTimeFormat(lang, { numeric: 'always', style: 'narrow' })
+ const rtf = relativeFormat(lang, 'narrow')
let res: string
if (s < 60) res = rtf.format(-s, 'second')
else if (s < 3600) res = rtf.format(-Math.round(s / 60), 'minute')
else if (s < 86400) res = rtf.format(-Math.round(s / 3600), 'hour')
else if (s < 604800) res = rtf.format(-Math.round(s / 86400), 'day')
- else return new Date(ts).toLocaleDateString(lang)
+ else return dateFormat(lang).format(new Date(ts))
// In locales where narrow style outputs leading '-' without past indicator (e.g. French "-30 s", Russian "-30 с"),
// fallback to short style which provides abbreviated units with proper past tense ("il y a 30 s", "30 сек. назад").
if (res.startsWith('-')) {
- const rtfShort = new Intl.RelativeTimeFormat(lang, { numeric: 'always', style: 'short' })
+ const rtfShort = relativeFormat(lang, 'short')
if (s < 60) return rtfShort.format(-s, 'second')
if (s < 3600) return rtfShort.format(-Math.round(s / 60), 'minute')
if (s < 86400) return rtfShort.format(-Math.round(s / 3600), 'hour')
diff --git a/src/lib/soundEffects.ts b/src/lib/soundEffects.ts
index bdb1164..6d6b58c 100644
--- a/src/lib/soundEffects.ts
+++ b/src/lib/soundEffects.ts
@@ -29,6 +29,22 @@ function isSoundEnabled(): boolean {
}
}
+/**
+ * A running AudioContext keeps the audio device stream open and wakes the CPU
+ * ~200 times a second even in silence. Pause it this long after it was last
+ * needed; every sound is far shorter, so none is ever cut off.
+ */
+const IDLE_SUSPEND_MS = 2000
+let idleTimer: ReturnType<typeof setTimeout> | undefined
+
+function armIdleSuspend(): void {
+ if (idleTimer !== undefined) clearTimeout(idleTimer)
+ idleTimer = setTimeout(() => {
+ idleTimer = undefined
+ if (audioCtx && audioCtx.state === 'running') audioCtx.suspend().catch(() => {})
+ }, IDLE_SUSPEND_MS)
+}
+
function getAudioContext(): any | null {
if (!isSoundEnabled()) return null
const win = typeof globalThis !== 'undefined' ? (globalThis as any).window : undefined
@@ -42,6 +58,7 @@ function getAudioContext(): any | null {
if (audioCtx && audioCtx.state === 'suspended') {
audioCtx.resume().catch(() => {})
}
+ if (audioCtx) armIdleSuspend()
return audioCtx
}
@@ -61,24 +78,20 @@ export function warmAudioContext(): void {
}
}
-// Global auto-unlock listener: resumes AudioContext on first pointerdown/mouseenter/keydown
+// Wake the context on every press. A click's sound plays when the click ends,
+// 50-100ms after the press, and resuming takes ~8ms, so sounds are never
+// delayed by the idle pause (and the first press also unlocks audio).
const win = typeof globalThis !== 'undefined' ? (globalThis as any).window : undefined
if (win && win.addEventListener) {
- const unlockAudio = () => {
- const ctx = getAudioContext()
- if (ctx && ctx.state === 'suspended') {
- ctx.resume().then(() => {
- if (ctx.state === 'running') {
- win.removeEventListener('pointerdown', unlockAudio, true)
- win.removeEventListener('mouseenter', unlockAudio, true)
- win.removeEventListener('keydown', unlockAudio, true)
- }
- }).catch(() => {})
+ const wake = () => {
+ try {
+ getAudioContext()
+ } catch {
+ /* ignore Web Audio API restrictions */
}
}
- win.addEventListener('pointerdown', unlockAudio, true)
- win.addEventListener('mouseenter', unlockAudio, true)
- win.addEventListener('keydown', unlockAudio, true)
+ win.addEventListener('pointerdown', wake, true)
+ win.addEventListener('keydown', wake, true)
}
// ── Scale ──────────────────────────────────────────────────────────────────
@@ -213,14 +226,16 @@ function play(key: string, minGap: number, level: number, voice: (b: Bus, at: nu
const ctx = getAudioContext()
if (!ctx) return
const go = () => {
- const now = ctx.currentTime
- if (now - (lastPlayed[key] ?? -1) < minGap) return
- lastPlayed[key] = now
+ // repeat guard in wall-clock seconds: the context's own clock stops while
+ // it is paused; sounds are still scheduled on the context's clock
+ const wall = performance.now() / 1000
+ if (wall - (lastPlayed[key] ?? -Infinity) < minGap) return
+ lastPlayed[key] = wall
const main = busFor(ctx)
const gain = ctx.createGain()
gain.gain.value = level
gain.connect(main.out)
- voice({ ...main, out: gain }, now + 0.004)
+ voice({ ...main, out: gain }, ctx.currentTime + 0.004)
}
if (ctx.state === 'suspended') {
ctx.resume().then(go).catch(() => {})
diff --git a/src/store/appStore.ts b/src/store/appStore.ts
index c1e79fd..5b4ca2f 100644
--- a/src/store/appStore.ts
+++ b/src/store/appStore.ts
@@ -286,7 +286,11 @@ export const useStore = create<AppState>((set, get) => ({
sliderReleasedTime: active ? 0 : Date.now()
}),
notifyPositionChanged: () => set({ sliderReleasedTime: Date.now() }),
- resetPositionChangedTime: () => set({ sliderReleasedTime: 0 }),
+ // Called on every cursor message while the shelf is open (~60/s); writing an
+ // unchanged value would still notify every store subscriber.
+ resetPositionChangedTime: () => {
+ if (get().sliderReleasedTime !== 0) set({ sliderReleasedTime: 0 })
+ },
edgeHintActive: false,
setEdgeHintActive: (active) => set({ edgeHintActive: active }),
styleFlyoutOpen: false,
diff --git a/src/styles/item.css b/src/styles/item.css
index 58361ec..d861582 100644
--- a/src/styles/item.css
+++ b/src/styles/item.css
@@ -639,20 +639,21 @@ html[data-motion='reduce'] .fko-layers > .fil {
transition: none;
}
-/* Cards showing an opening folder icon keep the same horizontal hover pill,
- but dock it on the label flap's shoulder (right of the raised tab, between
- the folder and the name) instead of the top corner, where the opening
- papers rise. Measured clear of the open folder and of the text.
+/* Folder-style cards (files, folders, photos, stacks) keep the same
+ horizontal hover pill, but dock it on the label flap's shoulder (right of
+ the raised tab, between the art and the name) instead of the top corner:
+ the art sits above it, clear of it (see the file / photo art rules below),
+ so the pill is in one place on every one of these cards.
(`top: auto` sits in each dock's own rule: those outrank the top dock's
`.list.horizontal` pill offsets.) */
-.item.is-image-folder-card .item-main:has(.file-kind-opening) > .actions {
+.item.is-image-folder-card .item-main > .actions {
transform-origin: bottom right;
}
-.item.is-image-folder-card .item-main:has(.file-kind-opening) > .actions {
+.item.is-image-folder-card .item-main > .actions {
top: auto;
bottom: 37px;
}
-.list.horizontal .item.is-image-folder-card .item-main:has(.file-kind-opening) > .actions {
+.list.horizontal .item.is-image-folder-card .item-main > .actions {
top: auto;
bottom: 28px;
}
@@ -680,6 +681,39 @@ html[data-motion='reduce'] .fko-layers > .fil {
padding-bottom: 34px;
}
+/* Photos and photo stacks sit the same way: the frame keeps a strip at the
+ bottom for the pill, so the photo (shown whole, any shape) rests above it.
+ Measured on hover with landscape, portrait, square, panorama and tiny
+ images: >= 6px from the pill and >= 5px from the frame's top in both docks
+ (top-dock 4-photo stacks overhang the top edge as they always have). */
+.image-folder-viewport:has(> .image-folder-thumb) {
+ padding-bottom: 36px;
+ box-sizing: border-box;
+}
+.list.horizontal .image-folder-viewport:has(> .image-folder-thumb) {
+ padding-bottom: 34px;
+}
+.list.horizontal .image-folder-viewport > .image-folder-thumb {
+ max-height: calc(100% - 14px);
+}
+.image-folder-viewport .image-folder-stack-deck:not(.is-file-deck) {
+ margin-top: 0;
+ padding-bottom: 32px;
+ box-sizing: border-box;
+}
+.list.horizontal .image-folder-viewport .image-folder-stack-deck:not(.is-file-deck) {
+ margin-top: 0;
+ padding-bottom: 30px;
+}
+.image-folder-stack-deck:not(.is-file-deck) .image-folder-stack-item {
+ width: 128px;
+ height: 86px;
+}
+.list.horizontal .image-folder-stack-deck:not(.is-file-deck) .image-folder-stack-item {
+ width: 86px;
+ height: 56px;
+}
+
/* Single Image Folder Card (Framed image in folder card + borderless folder flap) */
/* The hover background switches in one step (no fade): the textured viewport
paints with the card, so a fade redrew its grain and glow on every frame. */
diff --git a/tests/fileIconOpening.test.ts b/tests/fileIconOpening.test.ts
index 3281400..2f7a942 100644
--- a/tests/fileIconOpening.test.ts
+++ b/tests/fileIconOpening.test.ts
@@ -92,13 +92,19 @@ describe('folder icons open on hover', () => {
it('hover buttons stay a horizontal pill, docked off the opening folder', () => {
// never turned into a column: same pill as every other card
expect(css).not.toMatch(/actions[^{]*\{[^}]*flex-direction: column/)
- // shelf and expanded-stack folder cards: on the flap's shoulder, in each dock
+ // every folder-style card (files, folders, photos, stacks): on the flap's shoulder, in each dock
for (const [sel, bottom] of [
- ['.item.is-image-folder-card .item-main:has(.file-kind-opening) > .actions', '37px'],
- ['.list.horizontal .item.is-image-folder-card .item-main:has(.file-kind-opening) > .actions', '28px'],
+ ['.item.is-image-folder-card .item-main > .actions', '37px'],
+ ['.list.horizontal .item.is-image-folder-card .item-main > .actions', '28px'],
]) {
expect(css, sel).toContain(`\n${sel} {\n top: auto;\n bottom: ${bottom};`)
}
+ // ...so photos and photo stacks sit above it, like file art
+ expect(css).toContain('.image-folder-viewport:has(> .image-folder-thumb) {\n padding-bottom: 36px;')
+ expect(css).toContain('.list.horizontal .image-folder-viewport:has(> .image-folder-thumb) {\n padding-bottom: 34px;')
+ expect(css).toContain('.image-folder-viewport .image-folder-stack-deck:not(.is-file-deck) {\n margin-top: 0;\n padding-bottom: 32px;')
+ expect(css).toContain('.list.horizontal .image-folder-viewport .image-folder-stack-deck:not(.is-file-deck) {\n margin-top: 0;\n padding-bottom: 30px;')
+ expect(css).not.toContain(':has(.file-kind-opening) > .actions')
// the preview keeps the pill in the corner and lowers its grid folders instead
expect(css).toContain('.flyout-subitem:not(.single-hero-card) .item-content:has(.file-kind-opening) {\n padding-top: 28px;')
})
diff --git a/tests/fileKind.test.ts b/tests/fileKind.test.ts
new file mode 100644
index 0000000..11de3d7
--- /dev/null
+++ b/tests/fileKind.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync, readdirSync } from 'node:fs'
+import { join } from 'node:path'
+import { EXT_MAP, fileKindOf } from '../src/lib/fileKind'
+import { getFileKind } from '../src/lib/fileType'
+
+describe('fileKind (the i18n-free half of fileType)', () => {
+ it('gives the same kind as getFileKind for every known extension, unknown ones and folders', () => {
+ const paths = [...Object.keys(EXT_MAP).map((ext) => `C:/x/file.${ext}`), 'C:/x/FILE.PDF', 'C:/x/noext', 'C:/x/a.unknownext', 'C:/x/dir.']
+ for (const p of paths) {
+ expect(fileKindOf(p), p).toBe(getFileKind(p).kind)
+ expect(fileKindOf(p, true), p).toBe(getFileKind(p, true).kind)
+ }
+ })
+
+ it('the main process never imports renderer-only modules (i18n, store) through fileType', () => {
+ const dir = join(__dirname, '..', 'electron', 'main')
+ for (const f of readdirSync(dir).filter((f) => f.endsWith('.ts'))) {
+ const src = readFileSync(join(dir, f), 'utf8')
+ expect(src, f).not.toMatch(/from '\.\.\/\.\.\/src\/lib\/fileType'/)
+ expect(src, f).not.toMatch(/from '\.\.\/\.\.\/src\/(i18n'|i18n\/index|store\/)/)
+ }
+ })
+})
diff --git a/tests/relativeTimeCache.test.ts b/tests/relativeTimeCache.test.ts
new file mode 100644
index 0000000..fa70426
--- /dev/null
+++ b/tests/relativeTimeCache.test.ts
@@ -0,0 +1,65 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+const lang = vi.hoisted(() => ({ code: 'en' }))
+vi.mock('../src/i18n', () => ({
+ t: (key: string) => (key === 'item.justNow' ? 'just now' : key === 'item.ago' ? 'ago' : key),
+ getResolvedLanguage: () => lang.code
+}))
+
+import { relativeTime } from '../src/lib/format'
+import { LANGUAGES } from '../src/i18n/translations'
+
+/** The original implementation, building fresh Intl formatters on every call. */
+function uncached(ts: number, code: string): string {
+ const s = Math.max(0, Math.round((Date.now() - ts) / 1000))
+ if (s < 5) return 'just now'
+ const rtf = new Intl.RelativeTimeFormat(code, { numeric: 'always', style: 'narrow' })
+ let res: string
+ if (s < 60) res = rtf.format(-s, 'second')
+ else if (s < 3600) res = rtf.format(-Math.round(s / 60), 'minute')
+ else if (s < 86400) res = rtf.format(-Math.round(s / 3600), 'hour')
+ else if (s < 604800) res = rtf.format(-Math.round(s / 86400), 'day')
+ else return new Date(ts).toLocaleDateString(code)
+ if (res.startsWith('-')) {
+ const short = new Intl.RelativeTimeFormat(code, { numeric: 'always', style: 'short' })
+ if (s < 60) return short.format(-s, 'second')
+ if (s < 3600) return short.format(-Math.round(s / 60), 'minute')
+ if (s < 86400) return short.format(-Math.round(s / 3600), 'hour')
+ return short.format(-Math.round(s / 86400), 'day')
+ }
+ return res
+}
+
+const AGES_S = [0, 4, 5, 30, 59, 60, 61, 90, 3599, 3600, 7200, 86399, 86400, 172800, 604799, 604800, 2_000_000, 40_000_000]
+
+describe('relativeTime with cached formatters', () => {
+ beforeEach(() => {
+ vi.useFakeTimers()
+ vi.setSystemTime(new Date('2026-09-04T12:00:00.000Z'))
+ })
+ afterEach(() => {
+ vi.useRealTimers()
+ lang.code = 'en'
+ })
+
+ it('gives exactly the same text as fresh formatters, in every app language', () => {
+ const codes = LANGUAGES.map((l) => l.code).filter((c) => c !== 'system')
+ expect(codes.length).toBeGreaterThan(25)
+ for (const code of codes) {
+ lang.code = code
+ for (const age of AGES_S) {
+ const ts = Date.now() - age * 1000
+ expect(relativeTime(ts), `${code} ${age}s`).toBe(uncached(ts, code))
+ }
+ }
+ })
+
+ it('switching language mid-session uses the new language', () => {
+ const ts = Date.now() - 3 * 3600 * 1000
+ lang.code = 'en'
+ const en = relativeTime(ts)
+ lang.code = 'de'
+ expect(relativeTime(ts)).toBe(uncached(ts, 'de'))
+ expect(relativeTime(ts)).not.toBe(en)
+ })
+})