Skip to content

Refactor: unify capture filename assembly into CaptureFilename#9

Merged
GamalAnwar merged 1 commit into
masterfrom
claude/solid-refactor-capture-filename
Jun 18, 2026
Merged

Refactor: unify capture filename assembly into CaptureFilename#9
GamalAnwar merged 1 commit into
masterfrom
claude/solid-refactor-capture-filename

Conversation

@GamalAnwar

Copy link
Copy Markdown
Contributor

Summary

The capture filename rule — <prefix><app slug> <timestamp>.<ext>, with prefix defaulting to Stag_ and the slug omitted (with its space) when empty — lived in CaptureManager.saveImage and was re-implemented in PreferencesWindow.filenamePreview. Two copies of the same rule that could (and partly did) drift.

This extracts the assembly into a pure helper used by both:

CaptureFilename.make(prefix: prefs.filePrefix,
                     slug: slug,
                     timestamp: Date().shotTimestamp,
                     ext: prefs.defaultFormat.fileExtension)

and adds CaptureFormat.fileExtension (png/jpg) so the extension derivation isn't an inline ternary either.

Scope / safety

  • Real save path (CaptureManager) is behavior-preservingfileExtension returns exactly what the old == .jpeg ? "jpg" : "png" ternary did, and the prefix/slug assembly is identical.
  • One intentional preview fix: filenamePreview previously hardcoded .png regardless of the selected format; it now reflects prefs.defaultFormat.fileExtension. Same example values otherwise (Safari, 2026-01-01). Called out because it's a (minor) visible change to the settings label.

Tests

CaptureFilenameTests (6 cases): empty-prefix fallback, custom prefix verbatim, slug inserted with separating space, empty-slug omits the space (no double space), extension applied, and CaptureFormat.fileExtension mapping.

🤖 Generated with Claude Code


Generated by Claude Code

The '<prefix><app slug> <timestamp>.<ext>' rule lived in CaptureManager.saveImage
and was re-implemented in PreferencesWindow.filenamePreview, so the two could
drift (the preview also hardcoded .png regardless of the chosen format). Extract
the assembly into a pure CaptureFilename.make(prefix:slug:timestamp:ext:) used by
both, and add CaptureFormat.fileExtension to unify the jpg/png derivation.

Real save path is behavior-preserving. The settings preview now reflects the
selected format's extension (was always .png) and otherwise renders identically.
Adds CaptureFilenameTests (6 cases).
@GamalAnwar GamalAnwar merged commit 6cf434c into master Jun 18, 2026
1 check passed
@GamalAnwar GamalAnwar deleted the claude/solid-refactor-capture-filename branch June 18, 2026 07:35
GamalAnwar added a commit that referenced this pull request Jun 18, 2026
Extract the '<prefix><slug> <timestamp>.<ext>' rule (duplicated across
CaptureManager.saveImage and PreferencesWindow.filenamePreview) into a pure
CaptureFilename.make(...), and add CaptureFormat.fileExtension. Real save path is
behavior-preserving; the settings preview now reflects the chosen format's
extension (was hardcoded .png). Adds CaptureFilenameTests (6 cases). CI green.
GamalAnwar added a commit that referenced this pull request Jun 18, 2026
Extract the '<prefix><slug> <timestamp>.<ext>' rule (duplicated across
CaptureManager.saveImage and PreferencesWindow.filenamePreview) into a pure
CaptureFilename.make(...), and add CaptureFormat.fileExtension. Real save path is
behavior-preserving; the settings preview now reflects the chosen format's
extension (was hardcoded .png). Adds CaptureFilenameTests (6 cases). CI green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants