Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Logs Redesign (#1140)

neo7732364ca8ed6a0
diff --git a/screenpipe-app-tauri/app/globals.css b/screenpipe-app-tauri/app/globals.css
index 9c059f27e..831b79ebd 100644
--- a/screenpipe-app-tauri/app/globals.css
+++ b/screenpipe-app-tauri/app/globals.css
@@ -112,4 +112,52 @@
body {
@apply bg-background text-foreground !pointer-events-auto;
}
+}
+.pf-v6-c-log-viewer__text {
+ font-family: monospace!important;
+ padding-inline-end: 16px!important;
+ padding-inline-start: 16px!important;
+}
+.pf-v6-c-text-input-group__text-input {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ position: relative;
+ width: 100%;
+ padding-block-end: 8px!important;
+ padding-block-start: 8px!important;
+ padding-bottom: 8px!important;
+ padding-inline-end: 16px!important;
+ padding-inline-start: 38px!important;
+ padding-left: 38px!important;
+ padding-right: 16px!important;
+ padding-top: 8px!important;
+}
+.pf-v6-c-text-input-group__text-input::placeholder {
+ padding-left: 20px!important;
+}
+.pf-v6-c-text-input-group__icon {
+ inset-block-start: 18.5px!important;
+ inset-inline-start: 16px!important;
+ line-height: 21px!important;
+ position: absolute!important;
+}
+
+.pf-v6-c-log-viewer.pf-m-line-numbers .pf-v6-c-log-viewer__list::before {
+ position: absolute!important;
+ inset-block-start: 0!important;
+ inset-block-end: 0!important;
+ inset-inline-start: 0!important;
+ width: 1px!important;
+ content: ""!important;
+ background: rgb(199, 199, 199)!important;
+}
+
+.pf-v6-c-log-viewer__index {
+ padding-inline-start: 16px!important;
+ font-family: monospace!important;
+}
+
+.pf-v6-c-log-viewer__string.pf-m-current {
+ background-color: #dca614!important;
}
\ No newline at end of file
diff --git a/screenpipe-app-tauri/bun.lockb b/screenpipe-app-tauri/bun.lockb
index 0ccfd97a4..a9bf0ff80 100755
Binary files a/screenpipe-app-tauri/bun.lockb and b/screenpipe-app-tauri/bun.lockb differ
diff --git a/screenpipe-app-tauri/components/log-file-button.tsx b/screenpipe-app-tauri/components/log-file-button.tsx
index dc858c214..c3625370e 100644
--- a/screenpipe-app-tauri/components/log-file-button.tsx
+++ b/screenpipe-app-tauri/components/log-file-button.tsx
@@ -1,6 +1,4 @@
-import { homeDir } from "@tauri-apps/api/path";
import { useToast } from "./ui/use-toast";
-import { platform } from "@tauri-apps/plugin-os";
import {
Tooltip,
TooltipContent,
@@ -9,11 +7,45 @@ import {
} from "./ui/tooltip";
import { Button } from "./ui/button";
import { FileText, Copy } from "lucide-react";
-import { open } from "@tauri-apps/plugin-shell";
import { readTextFile } from "@tauri-apps/plugin-fs";
import { useCopyToClipboard } from "@/lib/hooks/use-copy-to-clipboard";
import { cn } from "@/lib/utils";
import { useSettings } from "@/lib/hooks/use-settings";
+import {
+ Dialog,
+ DialogHeader,
+ DialogTitle,
+ DialogContent,
+ DialogDescription,
+} from "./ui/dialog";
+import { useState } from "react";
+import { ScrollArea } from "./ui/scroll-area";
+import { invoke } from "@tauri-apps/api/core";
+import React from "react";
+import { LogViewer, LogViewerSearch } from "@patternfly/react-log-viewer";
+import { Toolbar, ToolbarContent, ToolbarItem } from "@patternfly/react-core";
+
+const LogContent = ({ content }: { content: string }) => {
+ return (
+ <LogViewer
+ theme="dark"
+ isTextWrapped={false}
+ hasLineNumbers={true}
+ data={content}
+ height="58vh"
+ toolbar={
+ <Toolbar>
+ <ToolbarContent>
+ <ToolbarItem>
+ <LogViewerSearch placeholder="Search value" minSearchChars={3} />
+ </ToolbarItem>
+ </ToolbarContent>
+ </Toolbar>
+ }
+ />
+ );
+};
+LogContent.displayName = "LogContent";
export const LogFileButton = ({
className,
@@ -28,53 +60,157 @@ export const LogFileButton = ({
const { copyToClipboard } = useCopyToClipboard({ timeout: 3000 });
const { getDataDir } = useSettings();
- const getLogFilePath = async () => {
- const dataDir = await getDataDir();
- const logFileName = isAppLog ? "screenpipe-app" : "screenpipe";
- const os = platform();
- if (os === "macos" || os === "linux") {
- return `${dataDir}/${logFileName}.${new Date().toISOString().split("T")[0]}.log`
+ const [isOpen, setIsOpen] = useState(false);
+ const [logPath, setLogPath] = useState("");
+ const [logContent, setLogContent] = useState("");
+ const [logFiles, setLogFiles] = useState<LogFile[]>([]);
+
+ interface LogFile {
+ name: string;
+ path: string;
+ modified_at: number;
+ }
+ const getLogFiles = async () => {
+ try {
+ const logFiles = await invoke("get_log_files");
+ return logFiles as LogFile[];
+ } catch (error) {
+ console.error("failed to get log files:", error);
+ return [];
}
- return `${dataDir}\\${logFileName}.${new Date().toISOString().split("T")[0]}.log`
};
- const handleOpenLogFile = async () => {
+ const loadLogContent = async (filePath: string) => {
try {
- const logPath = await getLogFilePath();
- console.log("opening log file:", logPath);
- await open(logPath);
+ console.log("loadLogContent", filePath);
+
+ const content = await readTextFile(filePath);
+ setLogPath(filePath);
+ setLogContent(content);
} catch (error) {
- console.error("failed to open log file:", error);
+ console.error("failed to read log file:", error);
toast({
title: "error",
- description: "failed to open log file.",
+ description: "failed to read log file",
variant: "destructive",
- duration: 3000,
});
}
};
+ const handleShowLog = async () => {
+ const files = await getLogFiles();
+ setLogFiles(files);
+ if (files.length > 0) {
+ await loadLogContent(files[0].path);
+ }
+ setIsOpen(true);
+ };
return (
- <div className={cn("flex", className)}>
+ <>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="icon"
- className={cn("h-8 w-8", size === "8" && "h-8 w-8", size === "10" && "h-10 w-10", size === "12" && "h-12 w-12")}
- onClick={handleOpenLogFile}
+ className={cn(
+ "h-8 w-8",
+ size === "8" && "h-8 w-8",
+ size === "10" && "h-10 w-10",
+ size === "12" && "h-12 w-12"
+ )}
+ onClick={handleShowLog}
>
- <FileText className={cn("h-4 w-4", size === "8" && "h-4 w-4", size === "10" && "h-6 w-6", size === "12" && "h-8 w-8")} />
+ <FileText
+ className={cn(
+ "h-4 w-4",
+ size === "8" && "h-4 w-4",
+ size === "10" && "h-6 w-6",
+ size === "12" && "h-8 w-8"
+ )}
+ />
</Button>
</TooltipTrigger>
<TooltipContent>
- <p>open {isAppLog ? "app " : ""}log file</p>
+ <p>view {isAppLog ? "app " : ""}log files</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
- </div>
+ <Dialog open={isOpen} onOpenChange={setIsOpen}>
+ <DialogContent className="sm:max-w-[90vw] h-[80vh] overflow-hidden flex flex-col">
+ <DialogHeader>
+ <DialogTitle>log files</DialogTitle>
+ <DialogDescription>
+ select a log file from the list to view its contents
+ </DialogDescription>
+ </DialogHeader>
+
+ {logFiles.length === 0 ? (
+ <div className="flex-1 flex flex-col items-center justify-center">
+ <FileText className="h-12 w-12 mb-4 text-muted-foreground opacity-50" />
+ <p className="text-sm text-muted-foreground">
+ no log files found yet, come back later
+ </p>
+ </div>
+ ) : (
+ <div className="grid grid-cols-[250px,1fr] gap-4 h-[calc(100%-80px)]">
+ {/* Sidebar with log files list */}
+ <div className="border rounded-md overflow-hidden">
+ <ScrollArea className="h-full">
+ <div className="p-2 space-y-1">
+ {logFiles.map((file, i) => (
+ <Button
+ key={i}
+ variant={
+ logPath === file.modified_at.toString()
+ ? "secondary"
+ : "ghost"
+ }
+ className="w-full justify-start text-xs"
+ onClick={() => loadLogContent(file.path)}
+ >
+ <FileText className="h-3 w-3 mr-2" />
+ <span className="truncate">{file.name}</span>
+ </Button>
+ ))}
+ </div>
+ </ScrollArea>
+ </div>
+
+ {/* Content area */}
+ <div className="flex flex-col space-y-2 h-full">
+ {logPath && (
+ <>
+ <div className="relative flex-1 border rounded-md">
+ <LogContent content={logContent} />
+ <Button
+ variant="outline"
+ size="sm"
+ className="absolute top-2 right-2 opacity-0 transition-opacity hover:opacity-100 group-hover:opacity-100 focus:opacity-100"
+ onClick={() => copyToClipboard(logContent)}
+ >
+ <Copy className="h-3 w-3" />
+ </Button>
+ </div>
+ <div className="flex items-center justify-between px-2 py-1 bg-secondary/50 rounded-md">
+ <code className="text-sm font-mono">{logPath}</code>
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => copyToClipboard(logPath)}
+ >
+ <Copy className="h-3 w-3" />
+ </Button>
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+ )}
+ </DialogContent>
+ </Dialog>
+ </>
);
};
diff --git a/screenpipe-app-tauri/lib/hooks/use-copy-to-clipboard.tsx b/screenpipe-app-tauri/lib/hooks/use-copy-to-clipboard.tsx
index e011d69bd..4918b6110 100644
--- a/screenpipe-app-tauri/lib/hooks/use-copy-to-clipboard.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-copy-to-clipboard.tsx
@@ -1,5 +1,6 @@
"use client";
+import { toast } from "@/components/ui/use-toast";
import * as React from "react";
export interface useCopyToClipboardProps {
@@ -22,6 +23,10 @@ export function useCopyToClipboard({
navigator.clipboard.writeText(value).then(() => {
setIsCopied(true);
+ toast({
+ title: "Copied to clipboard",
+ duration: 2000,
+ });
setTimeout(() => {
setIsCopied(false);
diff --git a/screenpipe-app-tauri/package.json b/screenpipe-app-tauri/package.json
index 61aaddd97..802233a6c 100644
--- a/screenpipe-app-tauri/package.json
+++ b/screenpipe-app-tauri/package.json
@@ -15,6 +15,8 @@
"@opentelemetry/resources": "^1.26.0",
"@opentelemetry/sdk-trace-base": "^1.22.0",
"@opentelemetry/sdk-trace-web": "^1.22.0",
+ "@patternfly/react-core": "^6.1.0",
+ "@patternfly/react-log-viewer": "^6.1.0",
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index 54f96129a..63f5d1640 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -329,6 +329,69 @@ fn get_base_dir(app: &tauri::AppHandle, custom_path: Option<String>) -> anyhow::
Ok(local_data_dir)
}
+#[derive(Debug, serde::Serialize)]
+pub struct LogFile {
+ name: String,
+ path: String,
+ modified_at: u64,
+}
+
+#[tauri::command]
+async fn get_log_files(app: AppHandle) -> Result<Vec<LogFile>, String> {
+ let data_dir = get_data_dir(&app).map_err(|e| e.to_string())?;
+ let mut log_files = Vec::new();
+
+ // Collect all entries first
+ let mut entries = Vec::new();
+ let mut dir = tokio::fs::read_dir(&data_dir).await.map_err(|e| e.to_string())?;
+ while let Some(entry) = dir.next_entry().await.map_err(|e| e.to_string())? {
+ // Get metadata immediately for each entry
+ if let Ok(metadata) = entry.metadata().await {
+ entries.push((entry, metadata));
+ }
+ }
+
+ // Sort by modified time descending (newest first)
+ entries.sort_by_key(|(_, metadata)| {
+ std::cmp::Reverse(
+ metadata
+ .modified()
+ .ok()
+ .and_then(|m| m.duration_since(std::time::SystemTime::UNIX_EPOCH).ok())
+ .map(|d| d.as_secs())
+ .unwrap_or(0)
+ )
+ });
+
+ // Process sorted entries
+ for (entry, metadata) in entries {
+ let path = entry.path();
+ if let Some(extension) = path.extension() {
+ if extension == "log" {
+ let modified = metadata
+ .modified()
+ .map_err(|e| e.to_string())?
+ .duration_since(std::time::SystemTime::UNIX_EPOCH)
+ .map_err(|e| e.to_string())?
+ .as_secs();
+
+ log_files.push(LogFile {
+ name: path
+ .file_name()
+ .unwrap_or_default()
+ .to_string_lossy()
+ .to_string(),
+ path: path.to_string_lossy().to_string(),
+ modified_at: modified,
+ });
+ }
+ }
+ }
+
+ Ok(log_files)
+}
+
+
fn send_recording_notification(
app_handle: &tauri::AppHandle,
success: bool,
@@ -552,6 +615,7 @@ async fn main() {
commands::show_meetings,
commands::show_identify_speakers,
commands::open_pipe_window,
+ get_log_files,
update_global_shortcuts,
])
.setup(|app| {