Skip to content

Commit

Permalink
Safeguard webview message predicates.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed May 11, 2024
1 parent c1200f0 commit 396bfaa
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 6 additions & 0 deletions ide/packages/common/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export type CallArgus = <T extends ArgusCliOptions>(

// Type predicates (these shouldn't really exist ...)

export function isSysMsg(
obj: any
): obj is SystemToPanoptesMsg<SystemToPanoptesCmds> {
return typeof obj === "object" && "command" in obj;
}

export function isSysMsgOpenError(
msg: SystemToPanoptesMsg<SystemToPanoptesCmds>
): msg is SystemToPanoptesMsg<"open-error"> {
Expand Down
3 changes: 2 additions & 1 deletion ide/packages/panoptes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@argus/panoptes",
"version": "0.0.1",
"main": "dist/panoptes.iife.js",
"depot": {
"platform": "browser"
},
Expand Down Expand Up @@ -31,4 +32,4 @@
"react-json-view": "^1.21.3",
"vite": "^4.4.9"
}
}
}
6 changes: 3 additions & 3 deletions ide/packages/panoptes/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
EvaluationMode,
PanoptesConfig,
SystemSpec,
SystemToPanoptesCmds,
SystemToPanoptesMsg,
isSysMsg,
isSysMsgOpenError,
isSysMsgOpenFile,
isSysMsgReset,
Expand Down Expand Up @@ -53,9 +52,10 @@ const App = observer(({ config }: { config: PanoptesConfig }) => {
const {
payload,
}: {
payload: SystemToPanoptesMsg<SystemToPanoptesCmds>;
payload: any;
} = e.data;

if (!isSysMsg(payload)) return;
console.debug("Received message from system", payload);

if (isSysMsgOpenError(payload)) {
Expand Down
2 changes: 0 additions & 2 deletions ide/packages/panoptes/src/TreeView/TreeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
} from "@argus/common/bindings";
import _ from "lodash";

import { isHiddenObl, isTraitClause } from "../utilities/func";

type MultiRecord<K extends number, T> = Record<K, T[]>;

type Direction = "to-root" | "from-root";
Expand Down
8 changes: 2 additions & 6 deletions ide/packages/panoptes/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ConfigConsts,
PanoptesConfig,
maybeStringToConfig,
} from "@argus/common/lib";
import { ConfigConsts, maybeStringToConfig } from "@argus/common/lib";
import * as React from "react";
import * as ReactDOM from "react-dom/client";

Expand All @@ -29,6 +25,6 @@ window.initializeArgusBlocks = (root: HTMLElement) => {

window.addEventListener(
"load",
() => initializeArgusBlocks(document.body),
() => window.initializeArgusBlocks(document.body),
false
);
1 change: 0 additions & 1 deletion ide/packages/panoptes/src/print/private/ty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { PrintConst } from "./const";
import { PrintDefPath } from "./path";
import {
Angled,
CBraced,
CommaSeparated,
DBraced,
Parenthesized,
Expand Down

0 comments on commit 396bfaa

Please sign in to comment.