Feat: Added a configuration option to define the save location of recordings.

* Add file picker for saving screen recordings

Implemented a file picker using Zenity to allow users to choose the save location for their screen recordings after stopping.

Replaced the hardcoded save path with dynamic user input.

Improved the notification system to inform users when recordings are saved or discarded.

* Refactored RecordingButton to fetch the latest recording path dynamically.

Removed static path references, ensuring the updated path from Hyprpanel config is always used.

* Update screen_record.sh

Added comment why use "sleep 1" at line 80

* Update module.nix

Updated nix module.

* Expand ~ in output directory, set default path, and add validation

- Properly expand `~` to `$HOME` in the output directory path.
- Set default recording directory to `$HOME/Videos` if none is provided.
- Validate that the output directory exists before starting a recording.

* Update scripts/screen_record.sh

Co-authored-by: Chase Taylor <11805686+dotaxis@users.noreply.github.com>

* Update scripts/screen_record.sh

Co-authored-by: Chase Taylor <11805686+dotaxis@users.noreply.github.com>

* Code Quality Check.

* Update RecordingButton.tsx

Removed debug logs as well.

* Update src/components/menus/dashboard/shortcuts/buttons/RecordingButton.tsx

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>

* updated RecordingButton.tsx && helper.tsx

Fixed the issues pointed by @Jas-SinghFSU

* Update RecordingButton.tsx

Fixed few linter errors.

---------

Co-authored-by: Chase Taylor <11805686+dotaxis@users.noreply.github.com>
Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
Siddharth Jain
2025-03-25 09:22:17 +05:30
committed by GitHub
parent c57d512ced
commit dba7ac64c6
7 changed files with 163 additions and 90 deletions

View File

@@ -1,18 +1,18 @@
#!/usr/bin/env bash
# Requires wf-recorder: https://github.com/ammen99/wf-recorder
outputDir="$HOME/Videos/Screencasts"
# Get the default audio sink
defaultSink=$(pactl get-default-sink)
WF_RECORDER_OPTS="--audio=$defaultSink.monitor -c libx264rgb"
outputFile=""
outputDir=""
# Function to check if recording is active
checkRecording() {
if pgrep -f "wf-recorder" >/dev/null; then
return 0
else
return 1
fi
pgrep -f "wf-recorder" >/dev/null
}
# Function to start screen recording
startRecording() {
if checkRecording; then
echo "A recording is already in progress."
@@ -21,66 +21,113 @@ startRecording() {
target="$2"
outputFile="recording_$(date +%Y-%m-%d_%H-%M-%S)"
outputPath="$outputDir/${outputFile}.mp4"
mkdir -p "$outputDir"
if [ "$target" == "screen" ]; then
monitor_info=$(hyprctl -j monitors | jq -r ".[] | select(.name == \"$3\")")
w=$(echo $monitor_info | jq -r '.width')
h=$(echo $monitor_info | jq -r '.height')
scale=$(echo $monitor_info | jq -r '.scale')
scaled_width=$(awk "BEGIN {print $w / $scale}")
scaled_height=$(awk "BEGIN {print $h / $scale}")
x=$(echo $monitor_info | jq -r '.x')
y=$(echo $monitor_info | jq -r '.y')
monitor_name="$3"
outputDir="$4"
elif [ "$target" == "region" ]; then
outputDir="$3"
else
echo "Usage: $0 start {screen <monitor_name> | region} <output_directory>"
exit 1
fi
# Set a default output directory if not provided
outputDir="${outputDir:-$HOME/Videos}"
# Expand ~ to $HOME if present in outputDir
outputDir="${outputDir/#\~/$HOME}"
# Ensure output directory exists
if [ ! -d "$outputDir" ]; then
echo "Error: Output directory '$outputDir' does not exist."
exit 1
fi
# Generate output filename and path
outputFile="recording_$(date +%Y-%m-%d_%H-%M-%S).mp4"
outputPath="$outputDir/$outputFile"
echo "Target: $target"
echo "Monitor: ${monitor_name:-N/A}"
echo "Output dir: $outputDir"
echo "Output file: $outputPath"
# Start screen recording
if [ "$target" == "screen" ]; then
if [ -z "$monitor_name" ]; then
echo "Error: Monitor name is required for screen recording."
exit 1
fi
monitor_info=$(hyprctl -j monitors | jq -r ".[] | select(.name == \"$monitor_name\")")
if [ -z "$monitor_info" ]; then
echo "Error: Monitor '$monitor_name' not found."
exit 1
fi
w=$(echo "$monitor_info" | jq -r '.width')
h=$(echo "$monitor_info" | jq -r '.height')
scale=$(echo "$monitor_info" | jq -r '.scale')
scaled_width=$(awk "BEGIN { print $w / $scale }")
scaled_height=$(awk "BEGIN { print $h / $scale }")
x=$(echo "$monitor_info" | jq -r '.x')
y=$(echo "$monitor_info" | jq -r '.y')
wf-recorder $WF_RECORDER_OPTS --geometry "${x},${y} ${scaled_width}x${scaled_height}" --file "$outputPath" &
elif [ "$target" == "region" ]; then
wf-recorder $WF_RECORDER_OPTS --geometry "$(slurp)" --file "$outputPath" &
else
echo "Usage: $0 start {region|screen [screen_name]}"
exit 1
fi
disown "$(jobs -p | tail -n 1)"
echo "Recording started. Output will be saved to $outputPath"
disown "$(jobs -p | tail -n 1)"
echo "Recording started. Saving to $outputPath"
echo "$outputPath" > /tmp/last_recording_path
}
# Function to stop screen recording
stopRecording() {
if ! checkRecording; then
echo "No recording is in progress."
echo "No recording in progress."
exit 1
fi
pkill -SIGINT -f wf-recorder
sleep 1 # Allow wf-recorder time to terminate before proceeding
recentFile=$(ls -t "$outputDir"/recording_*.mp4 | head -n 1)
outputPath=$(cat /tmp/last_recording_path 2>/dev/null)
notify-send "Recording stopped" "Your recording has been saved." \
if [ -z "$outputPath" ] || [ ! -f "$outputPath" ]; then
notify-send "Recording stopped" "No recent recording found." \
-i video-x-generic \
-a "Screen Recorder" \
-t 10000
exit 1
fi
notify-send "Recording stopped" "Saved to: $outputPath" \
-i video-x-generic \
-a "Screen Recorder" \
-t 10000 \
-u normal \
--action="scriptAction:-xdg-open $outputDir=Directory" \
--action="scriptAction:-xdg-open $recentFile=Play"
--action="scriptAction:-xdg-open $(dirname "$outputPath")=Open Directory" \
--action="scriptAction:-xdg-open $outputPath=Play"
}
# Handle script arguments
case "$1" in
start)
startRecording "$@"
;;
stop)
stopRecording
;;
status)
if checkRecording; then
echo "recording"
else
echo "not recording"
fi
;;
*)
echo "Usage: $0 {start [screen screen_name|region]|stop|status}"
exit 1
;;
esac
start)
startRecording "$@"
;;
stop)
stopRecording
;;
status)
if checkRecording; then
echo "recording"
else
echo "not recording"
fi
;;
*)
echo "Usage: $0 {start [screen <monitor_name> | region] <output_directory> | stop | status}"
exit 1
;;
esac