Skip to content

Commit c442def

Browse files
greyxp1ItsLemmy
andauthored
feat(screen_recorder): added a replay filename pattern setting (#11)
* added a replay filename pattern setting * fix(screen_recorder): rename saved replays by matching the newest replay file --------- Co-authored-by: Lemmy <studio@quadbyte.net>
1 parent b011a60 commit c442def

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

screen_recorder/plugin.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ min = 5
153153
max = 3600
154154
visible_when = { key = "replay_enabled", values = ["true"] }
155155

156+
[[setting]]
157+
key = "replay_filename_pattern"
158+
type = "string"
159+
label_key = "settings.replay_filename_pattern.label"
160+
default = "replay_%Y%m%d_%H%M%S"
161+
description_key = "settings.replay_filename_pattern.description"
162+
visible_when = { key = "replay_enabled", values = ["true"] }
163+
156164
[[setting]]
157165
key = "replay_storage"
158166
type = "select"

screen_recorder/recorder_service.luau

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,32 @@ end
360360
local function saveReplay()
361361
if state ~= "replaying" then return end
362362
noctalia.runAsync("pkill -SIGUSR1 -f 'gpu-screen-recorder.*-r ' 2>/dev/null || true")
363+
364+
local pattern = cfg("replay_filename_pattern")
365+
if pattern ~= nil and pattern ~= "" then
366+
local dir = outputDirectory()
367+
local targetFile = `{dir}{noctalia.formatTime(pattern)}.mp4`
368+
-- Replay mode only accepts an output directory (-o "{dir}"), so gpu-screen-recorder
369+
-- names the file itself as Replay_<timestamp>.mp4 using its own clock when it
370+
-- finalizes. Rather than predict that name, poll for the newest Replay_*.mp4 the
371+
-- save produced and rename it. `ref` (one second before the SIGUSR1) bounds the
372+
-- search so an earlier replay sitting in the directory is never picked up.
373+
local ref = (tonumber(noctalia.formatTime("%s")) or 0) - 1
374+
local claim = `f=$(find {shellQuote(dir)} -maxdepth 1 -name 'Replay_*.mp4' -newermt "@{ref}" -printf '%T@ %p\\n' 2>/dev/null | sort -n | tail -1 | cut -d' ' -f2-); `
375+
.. `if [ -n "$f" ]; then mv -n -- "$f" {shellQuote(targetFile)}; else exit 1; fi`
376+
local attempts = 50
377+
local function poll()
378+
noctalia.runAsync(`sleep 0.2; {claim}`, function(result)
379+
if result.exitCode == 0 then return end
380+
if attempts > 0 then
381+
attempts -= 1
382+
poll()
383+
end
384+
end)
385+
end
386+
poll()
387+
end
388+
363389
noctalia.notify(noctalia.tr("notify.replay-saved"))
364390
end
365391

screen_recorder/translations/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
"replay_duration": {
9999
"label": "Replay seconds"
100100
},
101+
"replay_filename_pattern": {
102+
"label": "Replay filename pattern",
103+
"description": "Date-format pattern for saved replays without extension; use %s for Unix timestamp"
104+
},
101105
"replay_storage": {
102106
"label": "Replay storage",
103107
"options": {

screen_recorder/translations/fr.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
"replay_duration": {
9999
"label": "Secondes de relecture"
100100
},
101+
"replay_filename_pattern": {
102+
"label": "Modèle de nom de fichier de relecture",
103+
"description": "Modèle de date pour les relectures sauvegardées sans extension; utilisez %s pour l'horodatage Unix"
104+
},
101105
"replay_storage": {
102106
"label": "Stockage de relecture",
103107
"options": {

0 commit comments

Comments
 (0)