Renamed all services to xxxService. Moved a couple things in Commons
This commit is contained in:
parent
7e334ae768
commit
83ff5f5589
86 changed files with 275 additions and 211 deletions
65
Services/ScreenRecorderService.qml
Normal file
65
Services/ScreenRecorderService.qml
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property var settings: Settings.data.screenRecorder
|
||||
property bool isRecording: false
|
||||
property string outputPath: ""
|
||||
|
||||
// Start or Stop recording
|
||||
function toggleRecording() {
|
||||
isRecording ? stopRecording() : startRecording()
|
||||
}
|
||||
|
||||
// Start screen recording using Quickshell.execDetached
|
||||
function startRecording() {
|
||||
if (isRecording) {
|
||||
return
|
||||
}
|
||||
isRecording = true
|
||||
|
||||
var filename = Time.getFormattedTimestamp() + ".mp4"
|
||||
var videoDir = settings.directory
|
||||
if (videoDir && !videoDir.endsWith("/")) {
|
||||
videoDir += "/"
|
||||
}
|
||||
outputPath = videoDir + filename
|
||||
var command = "gpu-screen-recorder -w portal" + " -f " + settings.frameRate + " -ac " + settings.audioCodec
|
||||
+ " -k " + settings.videoCodec + " -a " + settings.audioSource + " -q " + settings.quality
|
||||
+ " -cursor " + (settings.showCursor ? "yes" : "no") + " -cr " + settings.colorRange + " -o " + outputPath
|
||||
|
||||
//console.log("[ScreenRecorder]", command)
|
||||
Quickshell.execDetached(["sh", "-c", command])
|
||||
console.log("[ScreenRecorder] Started recording")
|
||||
}
|
||||
|
||||
// Stop recording using Quickshell.execDetached
|
||||
function stopRecording() {
|
||||
if (!isRecording) {
|
||||
return
|
||||
}
|
||||
|
||||
Quickshell.execDetached(["sh", "-c", "pkill -SIGINT -f 'gpu-screen-recorder.*portal'"])
|
||||
console.log("[ScreenRecorder] Finished recording:", outputPath)
|
||||
|
||||
// Just in case, force kill after 3 seconds
|
||||
killTimer.running = true
|
||||
isRecording = false
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: killTimer
|
||||
interval: 3000
|
||||
running: false
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
Quickshell.execDetached(["sh", "-c", "pkill -9 -f 'gpu-screen-recorder.*portal' 2>/dev/null || true"])
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue