-
-
Notifications
You must be signed in to change notification settings - Fork 181
feat: add configurable recordings save location #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abduznik
wants to merge
1
commit into
getopenscreen:main
Choose a base branch
from
abduznik:feature/configurable-recordings-location
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { mkdtemp, rm } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import path from "node:path"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { checkDiskSpace } from "./diskSpaceCheck"; | ||
|
|
||
| describe("checkDiskSpace", () => { | ||
| let dir: string; | ||
|
|
||
| beforeEach(async () => { | ||
| dir = await mkdtemp(path.join(tmpdir(), "openscreen-disk-space-")); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await rm(dir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it("reports the real filesystem as not low, using a near-zero threshold", async () => { | ||
| const status = await checkDiskSpace(dir, 1); | ||
| expect(status.low).toBe(false); | ||
| expect(status.availableBytes).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("reports low when the threshold is set far above any real free space", async () => { | ||
| const status = await checkDiskSpace(dir, Number.MAX_SAFE_INTEGER); | ||
| expect(status.low).toBe(true); | ||
| }); | ||
|
|
||
| it("does not throw and reports not-low for a directory that doesn't exist", async () => { | ||
| const status = await checkDiskSpace(path.join(dir, "does-not-exist")); | ||
| expect(status.low).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Pre-flight free-space check for recording start. Before this, the app had | ||
| // no disk-space awareness anywhere: a recording could run for its full | ||
| // duration and only fail once the user tried to save it, discarding the | ||
| // take. Catching it before capture starts costs one statfs() call and saves | ||
| // a wasted recording. | ||
| import fs from "node:fs/promises"; | ||
|
|
||
| /** Recording output is usually well under this; below it, a take is likely to run out mid-capture. */ | ||
| export const LOW_DISK_SPACE_THRESHOLD_BYTES = 500 * 1024 * 1024; | ||
|
|
||
| export interface DiskSpaceStatus { | ||
| /** Bytes free on the filesystem backing the recordings directory. */ | ||
| availableBytes: number; | ||
| low: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Checks free space on the filesystem that backs `dir`. Never throws — a | ||
| * platform or filesystem that doesn't support statfs (or a directory that | ||
| * doesn't exist yet) reports as not-low, since a bad check must never block | ||
| * a recording that would otherwise have worked. | ||
| */ | ||
| export async function checkDiskSpace( | ||
| dir: string, | ||
| thresholdBytes: number = LOW_DISK_SPACE_THRESHOLD_BYTES, | ||
| ): Promise<DiskSpaceStatus> { | ||
| try { | ||
| const stats = await fs.statfs(dir); | ||
| const availableBytes = stats.bavail * stats.bsize; | ||
| return { availableBytes, low: availableBytes < thresholdBytes }; | ||
| } catch { | ||
| return { availableBytes: Number.POSITIVE_INFINITY, low: false }; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Add tests next to the Electron source for
setRecordingsDir.electron/main.ts:setRecordingsDirandelectron/recording/RecordingsLocationStorehave no bound tests. Existing Electron recording tests do not exercise these symbols orRECORDINGS_DIR, so they will not detect regressions in persistence, reset, setter failures, or a directory change during recording. The repository convention requires a test for every new behavior in the same package.🤖 Prompt for AI Agents