Skip to content

Commit

Permalink
feat: add basic ipc for live-painting
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelass committed Feb 21, 2024
1 parent a2f7239 commit 376c118
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/client/pages/[locale]/live-painting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useTranslation } from "next-i18next";
import type { PointerEvent as ReactPointerEvent } from "react";
import { useEffect, useRef, useState } from "react";

import { buildKey } from "#/build-key";
import { ID } from "#/enums";
import { makeStaticProperties } from "@/ions/i18n/get-static";

export type ViewType = "side-by-side" | "overlay";
Expand Down Expand Up @@ -55,6 +57,7 @@ function DrawingArea() {
context.current?.stroke();
const dataUrl = canvas.current.toDataURL();
setImage(dataUrl);
window.ipc.send(buildKey([ID.LIVE_PAINT], { suffix: ":dataUrl" }), dataUrl);
}

function handleMouseUp() {
Expand Down Expand Up @@ -184,6 +187,23 @@ export default function Page(_properties: InferGetStaticPropsType<typeof getStat
<Typography level="h4" component="h1">
{t("labels:livePainting")}
</Typography>
<Box sx={{ flex: 1 }} />
<Box sx={{ display: "flex", gap: 1 }}>
<Button
onClick={() => {
window.ipc.send(buildKey([ID.LIVE_PAINT], { suffix: ":start" }));
}}
>
Start
</Button>
<Button
onClick={() => {
window.ipc.send(buildKey([ID.LIVE_PAINT], { suffix: ":stop" }));
}}
>
Stop
</Button>
</Box>
</Sheet>
<Box
sx={{
Expand Down
24 changes: 24 additions & 0 deletions src/electron/future/ipc/listeners.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BrowserWindow, ipcMain } from "electron";
import { download } from "electron-dl";
import type { ExecaChildProcess } from "execa";
import { execa } from "execa";

import { buildKey } from "#/build-key";
import { DownloadState, ID } from "#/enums";
Expand Down Expand Up @@ -80,3 +82,25 @@ ipcMain.on(buildKey([ID.INSTALL], { suffix: "start" }), async () => {
ipcMain.on(buildKey([ID.USER], { suffix: ":language" }), (_event, language) => {
userStore.set("language", language);
});

let process: ExecaChildProcess<string>;

ipcMain.on(buildKey([ID.LIVE_PAINT], { suffix: ":dataUrl" }), (_event, dataUrl) => {
console.log("image input");
});

ipcMain.on(buildKey([ID.LIVE_PAINT], { suffix: ":start" }), () => {
if (!process) {
process = execa("echo", ["hello", "world", "!"], { stdout: "inherit" });
console.log("alive");
}
});

ipcMain.on(buildKey([ID.LIVE_PAINT], { suffix: ":stop" }), () => {
if (!process.killed) {
const result = process.kill();
console.log("killed", result);
}

console.log(process.pid);
});
1 change: 1 addition & 0 deletions src/shared/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum ID {
STORE = "STORE",
USER = "USER",
WINDOW = "WINDOW",
LIVE_PAINT = "LIVE_PAINT",
}

/**
Expand Down

0 comments on commit 376c118

Please sign in to comment.