Skip to content

Commit

Permalink
feat: pipe store ui ready to go
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Aug 27, 2024
1 parent a7d4a2b commit d8be878
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 63 deletions.
1 change: 0 additions & 1 deletion examples/apps/screenpipe-app-tauri/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default function Home() {

return (
<main className="flex min-h-screen flex-col items-center p-8">
{/* <DevSettings /> */}
<NotificationHandler />
{/* <UpdateNotification checkIntervalHours={3} /> */}
{/* <ScreenpipeInstanceChecker /> */}
Expand Down
110 changes: 54 additions & 56 deletions examples/apps/screenpipe-app-tauri/components/pipe-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const PipeDialog: React.FC = () => {

// Update installed pipes in settings
const updatedInstalledPipes = [...settings.installedPipes, pipe];
console.log("updated installed pipes", updatedInstalledPipes);
await updateSettings({ installedPipes: updatedInstalledPipes });

// Kill existing screenpipe processes
Expand All @@ -99,6 +100,8 @@ const PipeDialog: React.FC = () => {
// Spawn new screenpipe process with the pipe
await invoke("spawn_screenpipe");

await new Promise((resolve) => setTimeout(resolve, 1000));

toast({
title: "Pipe installed successfully",
description: "Screenpipe has been restarted with the new pipe.",
Expand Down Expand Up @@ -126,11 +129,13 @@ const PipeDialog: React.FC = () => {
const updatedInstalledPipes = settings.installedPipes.filter(
(p) => p.name !== pipe.name
);
console.log("updated installed pipes", updatedInstalledPipes);
await updateSettings({ installedPipes: updatedInstalledPipes });

// restart screenpipe with no pipe
await invoke("kill_all_sreenpipes");
await invoke("spawn_screenpipe");
await new Promise((resolve) => setTimeout(resolve, 1000));

toast({
title: "Pipe uninstalled successfully",
Expand Down Expand Up @@ -221,67 +226,60 @@ const PipeDialog: React.FC = () => {
</Button>
</div>
<Separator className="my-4" />
{isInstalled ? (
<div className="mt-4">
<h3 className="text-xl font-semibold mb-2">Controls</h3>
{/* Add controls for the installed pipe here */}
<p>Pipe controls will be displayed here.</p>
</div>
) : (
<div className="mt-4">
<h3 className="text-xl font-semibold mb-2">About this pipe</h3>
<MemoizedReactMarkdown
className="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 w-full"
remarkPlugins={[remarkGfm, remarkMath]}
components={{
p({ children }) {
return <p className="mb-2 last:mb-0">{children}</p>;
},
code({ node, className, children, ...props }) {
const content = String(children).replace(/\n$/, "");
const match = /language-(\w+)/.exec(className || "");

if (!match) {
return (
<code
className="py-0.5 rounded-sm font-mono text-sm"
{...props}
>
{content}
</code>
);
}
<div className="mt-4">
<h3 className="text-xl font-semibold mb-2">About this pipe</h3>
<MemoizedReactMarkdown
className="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 w-full"
remarkPlugins={[remarkGfm, remarkMath]}
components={{
p({ children }) {
return <p className="mb-2 last:mb-0">{children}</p>;
},
code({ node, className, children, ...props }) {
const content = String(children).replace(/\n$/, "");
const match = /language-(\w+)/.exec(className || "");

if (!match) {
return (
<CodeBlock
key={Math.random()}
language={(match && match[1]) || ""}
value={content}
<code
className="py-0.5 rounded-sm font-mono text-sm"
{...props}
/>
);
},
img({ src, alt }) {
return (
/* eslint-disable @next/next/no-img-element */
<img
src={src}
alt={alt}
className="max-w-full h-auto"
onError={(e) => {
const target = e.target as HTMLImageElement;
target.onerror = null;
target.src = "path/to/fallback/image.png"; // Replace with your fallback image
}}
/>
>
{content}
</code>
);
},
}}
>
{selectedPipe.fullDescription.replace(/Â/g, "")}
</MemoizedReactMarkdown>
</div>
)}
}

return (
<CodeBlock
key={Math.random()}
language={(match && match[1]) || ""}
value={content}
{...props}
/>
);
},
img({ src, alt }) {
return (
/* eslint-disable @next/next/no-img-element */
<img
src={src}
alt={alt}
className="max-w-full h-auto"
onError={(e) => {
const target = e.target as HTMLImageElement;
target.onerror = null;
target.src = "path/to/fallback/image.png"; // Replace with your fallback image
}}
/>
);
},
}}
>
{selectedPipe.fullDescription.replace(/Â/g, "")}
</MemoizedReactMarkdown>
</div>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Button } from "./ui/button";
import { Separator } from "./ui/separator";
import { Card, CardContent, CardFooter } from "./ui/card";
import { useHealthCheck } from "@/lib/hooks/use-health-check";
import { DevSettings } from "./dev-dialog";

const getDebuggingCommands = (os: string | null) => {
let cliInstructions = "";
Expand Down Expand Up @@ -309,6 +310,7 @@ const DevModeSettings = () => {
and ask ChatGPT for curl commands to interact with the API.
</p>
</div>
<DevSettings />
</>
)}
</>
Expand Down
17 changes: 11 additions & 6 deletions examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
.map(|arr| arr.to_vec()))
})
.map_err(|e| e.to_string())?
.unwrap_or_default();
.unwrap_or_default();

debug!("pipes: {:?}", pipes);
let port = with_store(app.clone(), stores.clone(), path.clone(), |store| {
Ok(store
.get("port")
Expand Down Expand Up @@ -250,13 +252,16 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
}

if !pipes.is_empty() {
info!("adding pipes: {:?}", pipes);
let mut added_pipes = std::collections::HashSet::new();
for pipe in &pipes {
if let Some(pipe_str) = pipe.as_str() {
if added_pipes.insert(pipe_str) {
args.push("--pipe");
args.push(pipe_str);
info!("adding pipe: {}", pipe_str);
if let Some(obj) = pipe.as_object() {
if let Some(main_file) = obj.get("mainFile").and_then(Value::as_str) {
if added_pipes.insert(main_file) {
args.push("--pipe");
args.push(main_file);
info!("adding pipe: {}", main_file);
}
}
}
}
Expand Down

0 comments on commit d8be878

Please sign in to comment.