Skip to content

Commit

Permalink
feat: add fps in recording settings
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Sep 17, 2024
1 parent da479b0 commit 04ba434
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
46 changes: 45 additions & 1 deletion screenpipe-app-tauri/components/recording-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
} from "./ui/tooltip";
import { Switch } from "./ui/switch";
import { Input } from "./ui/input";
import { Slider } from "./ui/slider";

interface AudioDevice {
name: string;
Expand Down Expand Up @@ -164,6 +165,7 @@ export function RecordingSettings({
ignoredWindows: localSettings.ignoredWindows,
includedWindows: localSettings.includedWindows,
deepgramApiKey: localSettings.deepgramApiKey,
fps: localSettings.fps,
};
console.log("Settings to update:", settingsToUpdate);
await updateSettings(settingsToUpdate);
Expand Down Expand Up @@ -261,6 +263,10 @@ export function RecordingSettings({
setLocalSettings({ ...localSettings, disableAudio: checked });
};

const handleFpsChange = (value: number[]) => {
setLocalSettings({ ...localSettings, fps: value[0] });
};

return (
<>
<div className="relative">
Expand All @@ -271,7 +277,9 @@ export function RecordingSettings({
(go to status)
</CardTitle>
</Card>
) : <></>}
) : (
<></>
)}
<Card className={cn(isDisabled && "opacity-50 pointer-events-none")}>
<CardHeader>
<CardTitle className="text-center">recording settings</CardTitle>
Expand Down Expand Up @@ -708,6 +716,42 @@ export function RecordingSettings({
</div>
</div>

<div className="flex flex-col space-y-2">
<Label htmlFor="fps" className="flex items-center space-x-2">
<span>frames per second (fps)</span>
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<HelpCircle className="h-4 w-4" />
</TooltipTrigger>
<TooltipContent side="right">
<p>
adjust the recording frame rate. lower values save
<br />
resources, higher values provide smoother recordings, less likely to miss activity.
<br />
(we do not use resources if your screen does not change much)
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</Label>
<div className="flex items-center space-x-4">
<Slider
id="fps"
min={0.1}
max={10}
step={0.1}
value={[localSettings.fps]}
onValueChange={handleFpsChange}
className="flex-grow"
/>
<span className="w-12 text-right">
{localSettings.fps.toFixed(1)}
</span>
</div>
</div>

<div className="flex flex-col space-y-2">
<Button
onClick={handleUpdate}
Expand Down
9 changes: 8 additions & 1 deletion screenpipe-app-tauri/lib/hooks/use-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const defaultSettings: Settings = {
includedWindows: [],
aiUrl: "https://api.openai.com/v1",
aiMaxContextChars: 30000,
fps: 0.5,
};

export interface Settings {
Expand All @@ -62,6 +63,7 @@ export interface Settings {
includedWindows: string[];
aiUrl: string;
aiMaxContextChars: number;
fps: number;
}

let store: Store | null = null;
Expand Down Expand Up @@ -107,7 +109,8 @@ export function useSettings() {
await store!.load();
const savedKey = ((await store!.get("openaiApiKey")) as string) || "";
const savedDeepgramKey =
((await store!.get("deepgramApiKey")) as string) || "7ed2a159a094337b01fd8178b914b7ae0e77822d";
((await store!.get("deepgramApiKey")) as string) ||
"7ed2a159a094337b01fd8178b914b7ae0e77822d";
const savedUseOllama =
((await store!.get("useOllama")) as boolean) || false;
const savedOllamaUrl =
Expand Down Expand Up @@ -151,6 +154,9 @@ export function useSettings() {
"https://api.openai.com/v1";
const savedAiMaxContextChars =
((await store!.get("aiMaxContextChars")) as number) || 30000;
const savedFps =
((await store!.get("fps")) as number) ||
(platform() === "macos" ? 0.2 : 1);
setSettings({
openaiApiKey: savedKey,
deepgramApiKey: savedDeepgramKey,
Expand All @@ -175,6 +181,7 @@ export function useSettings() {
includedWindows: savedIncludedWindows,
aiUrl: savedAiUrl,
aiMaxContextChars: savedAiMaxContextChars,
fps: savedFps,
});
} catch (error) {
console.error("Failed to load settings:", error);
Expand Down
13 changes: 11 additions & 2 deletions screenpipe-app-tauri/src-tauri/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,20 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
.map_err(|e| e.to_string())?
.unwrap_or(String::from("default"));

let fps = with_store(app.clone(), stores.clone(), path.clone(), |store| {
Ok(store
.get("fps")
.and_then(|v| v.as_f64())
.unwrap_or(0.5))
})
.map_err(|e| e.to_string())?;

let port_str = port.to_string();
let mut args = vec!["--port", port_str.as_str()];
if cfg!(target_os = "macos") {
let fps_str = fps.to_string();
if fps != 0.5 {
args.push("--fps");
args.push("0.2");
args.push(fps_str.as_str());
}

if data_dir != "default" {
Expand Down

0 comments on commit 04ba434

Please sign in to comment.