Skip to content

Commit

Permalink
Implement display: transient/persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed Oct 21, 2023
1 parent 6bfbd2b commit e1397e2
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 114 deletions.
14 changes: 14 additions & 0 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,27 @@ server.listen(0, () => {
autoHideMenuBar: true,
center: true,
show: false,
titleBarStyle: "hidden",
titleBarOverlay: {
color: "#00000000",
symbolColor: "#00000000",
},
webPreferences: {
preload: path.resolve(__dirname, "preload.js"),
},
});
win.loadURL(`http://localhost:${port}/index.html`);
win.maximize();
win.show();
win.webContents.on("did-finish-load", () => {
win.webContents.setZoomFactor(0.9);
});
electron.ipcMain.handle("title-bar", (_e, background, foreground) => {
win.setTitleBarOverlay({
color: background,
symbolColor: foreground,
});
});
};
electron.app.whenReady().then(() => {
createWindow();
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"scripts": {
"start": "vite",
"build": "vite build",
"build": "vite build --emptyOutDir",
"package": "sh ./package.sh",
"test": "vitest"
},
Expand Down
4 changes: 2 additions & 2 deletions client/package.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
npx electron-packager . Waypoint --dir dist --platform=win32 --arch=x64 --electronVersion=26.2.1 --ignore node_modules --ignore src --overwrite --icon ./dist/favicon --out bin
npx electron-packager . Waypoint --dir dist --platform=linux --arch=x64 --electronVersion=26.2.1 --ignore node_modules --ignore src --overwrite --icon ./dist/favicon --out bin
npx electron-packager . Visualiser --dir dist --platform=win32 --arch=x64 --electronVersion=26.2.1 --ignore node_modules --ignore src --overwrite --icon ./dist/favicon --out bin
npx electron-packager . Visualiser --dir dist --platform=linux --arch=x64 --electronVersion=26.2.1 --ignore node_modules --ignore src --overwrite --icon ./dist/favicon --out bin
9 changes: 9 additions & 0 deletions client/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
process.once("loaded", () => {
const { contextBridge, ipcRenderer } = require("electron");

contextBridge.exposeInMainWorld("electron", {
async invoke(eventName, ...params) {
return await ipcRenderer.invoke(eventName, ...params);
},
});
});
16 changes: 14 additions & 2 deletions client/src/components/layer-editor/layers/traceLayerSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,26 @@ export const traceLayerSource: LayerSource<"trace", TraceLayerData> = {
const path = use2DPath(layer, throttledStep);
const steps = useMemo(
() =>
map(result?.steps, (c) =>
map(result?.stepsPersistent, (c) =>
map(c, (d) => merge(d, { meta: { sourceLayer: layer?.key } }))
),
[result?.steps, layer]
[result?.stepsPersistent, layer]
);
const steps1 = useMemo(
() =>
map(result?.stepsTransient, (c) =>
map(c, (d) => merge(d, { meta: { sourceLayer: layer?.key } }))
),
[result?.stepsTransient, layer]
);
const steps2 = useMemo(
() => [steps1[throttledStep] ?? []],
[steps1, throttledStep]
);
return (
<>
<LazyNodeList step={throttledStep} nodes={steps} />
<NodeList nodes={steps2} />
{path}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/renderer/parser/parseTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useTrace(params: ParseTraceWorkerParameters) {
const output = await parseTraceAsync(params);
push(
"Trace loaded",
pluralize("step", output?.steps?.length ?? 0, true)
pluralize("step", output?.stepsPersistent?.length ?? 0, true)
);
return output;
}
Expand Down
26 changes: 17 additions & 9 deletions client/src/components/renderer/parser/parseTrace.worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chain, findLast, map } from "lodash";
import { chain, findLast, map, mapValues, negate } from "lodash";
import {
CompiledComponent,
EventContext,
Expand All @@ -17,6 +17,9 @@ type Key = string | number;

type KeyRef = Key | null | undefined;

const isPersistent = (c: CompiledComponent<string, Record<string, any>>) =>
c.display !== "transient";

function parse({
trace,
context,
Expand Down Expand Up @@ -61,21 +64,25 @@ function parse({
.value();

const steps = chain(trace?.events)
.map((e, i, esx) =>
apply(e, {
.map((e, i, esx) => {
const component = apply(e, {
...context,
step: i,
parent: !isNullish(e.pId)
? esx[findLast(r[e.pId], (x) => x.step <= i)?.step ?? 0]
: undefined,
})
)
.map((c) => c.filter(isVisible))
.map((c, i) => c.map(makeEntryIteratee(i)))
});
const persistent = component.filter(isPersistent);
const transient = component.filter(negate(isPersistent));
return { persistent, transient };
})
.map((c) => mapValues(c, (b) => b.filter(isVisible)))
.map((c, i) => mapValues(c, (b) => b.map(makeEntryIteratee(i))))
.value();

return {
steps,
stepsPersistent: map(steps, "persistent"),
stepsTransient: map(steps, "transient"),
};
}

Expand All @@ -86,7 +93,8 @@ export type ParseTraceWorkerParameters = {
};

export type ParseTraceWorkerReturnType = {
steps: ComponentEntry[][];
stepsPersistent: ComponentEntry[][];
stepsTransient: ComponentEntry[][];
};

onmessage = ({ data }: MessageEvent<ParseTraceWorkerParameters>) => {
Expand Down
13 changes: 13 additions & 0 deletions client/src/hooks/useTitleBar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { useEffect } from "react";
import { name } from "manifest.json";
import { getContrastRatio } from "@mui/material";

const getForegroundColor = (bg: string) =>
getContrastRatio(bg, "#ffffff") > getContrastRatio(bg, "#000000")
? "#ffffff"
: "#000000";

export function useTitleBar(color: string) {
useEffect(() => {
document
.querySelector('meta[name="theme-color"]')!
.setAttribute("content", color);
document.title = name;
if ("electron" in window) {
(window.electron as any).invoke(
"title-bar",
"#00000000",
getForegroundColor(color)
);
}
}, [color]);
}
Loading

0 comments on commit e1397e2

Please sign in to comment.