Skip to content

Commit 82f652e

Browse files
authored
Merge pull request #3 from JS00001/main
Fix a bunch of bugs
2 parents 4acd916 + 497d75e commit 82f652e

File tree

13 files changed

+234
-49
lines changed

13 files changed

+234
-49
lines changed

bridge/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ async fn launch_browser() -> Result<(), String> {
3131
Command::new(chrome_path)
3232
.args(&[
3333
"--remote-debugging-port=9222",
34+
"--remote-debugging-address=127.0.0.1",
3435
&format!("--user-data-dir={}", profile_dir.display()),
3536
"--no-first-run",
3637
"--no-default-browser-check",

bridge/tauri.conf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "HTTP Interceptor",
4-
"version": "0.1.3",
4+
"version": "0.1.4",
55
"identifier": "com.http-interceptor.js00001",
66
"build": {
77
"beforeDevCommand": "npm run dev",
@@ -33,4 +33,4 @@
3333
"icons/icon.ico"
3434
]
3535
}
36-
}
36+
}

interceptor/chrome/tab-listener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Base64 } from 'js-base64';
12
import Protocol from 'devtools-protocol';
23

34
import { GREEN } from '@shared/lib';
@@ -33,7 +34,7 @@ export default class TabListener extends SocketManager {
3334
await this.send('Fetch.continueRequest', {
3435
headers,
3536
requestId: event.fetchId,
36-
postData: btoa(event.request.postData ?? ''),
37+
postData: Base64.encode(event.request.postData ?? ''),
3738
});
3839
}
3940

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@tauri-apps/plugin-websocket": "^2.4.0",
2323
"classnames": "^2.5.1",
2424
"immer": "^10.1.1",
25+
"js-base64": "^3.7.8",
2526
"lodash": "^4.17.21",
2627
"motion": "^12.23.12",
2728
"react": "^18.3.1",

shared/stores/network-event.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ interface INetworkEventState {
88
/** List of request IDs for quickly checking if a request exists */
99
requestIds: string[];
1010

11-
/** Array of requestIDs that have been intercepted */
11+
/** Array of requestIDs that are currently intercepted, pending action */
1212
interceptedEvents: string[];
1313

14+
/** Array of all requestIDs that have been intercepted */
15+
allInterceptedEvents: string[];
16+
1417
/** Map of network events by their requestID */
1518
events: { [requestId: string]: NetworkEvent };
1619
}
@@ -72,6 +75,7 @@ export const useNetworkEventStore = create<INetworkEventStore>()((set) => {
7275
events: {},
7376
requestIds: [],
7477
interceptedEvents: [],
78+
allInterceptedEvents: [],
7579
};
7680

7781
/**
@@ -134,6 +138,7 @@ export const useNetworkEventStore = create<INetworkEventStore>()((set) => {
134138
produce(state, (draft) => {
135139
if (!draft.events[requestId]) return;
136140
draft.interceptedEvents.push(requestId);
141+
draft.allInterceptedEvents.push(requestId);
137142
if (fetchId) draft.events[requestId].fetchId = fetchId;
138143
})
139144
);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { useMemo } from "react";
2+
import { useDebounce } from "use-debounce";
3+
import { createColumnHelper } from "@tanstack/react-table";
4+
5+
import UrlCell from "./cells/UrlCell";
6+
import StatusCell from "./cells/StatusCell";
7+
import MethodCell from "./cells/MethodCell";
8+
import NetworkEventTable from "./NetworkEventTable";
9+
10+
import { NetworkEvent } from "@shared/types";
11+
import { useNetworkEventStore } from "@shared/stores/network-event";
12+
13+
const columnHelper = createColumnHelper<NetworkEvent>();
14+
15+
const columns = [
16+
columnHelper.display({
17+
id: "url",
18+
header: "Url",
19+
cell: UrlCell,
20+
meta: { width: "auto" },
21+
}),
22+
columnHelper.accessor("response.status", {
23+
id: "status",
24+
cell: StatusCell,
25+
header: "Status",
26+
meta: { width: 140 },
27+
}),
28+
columnHelper.accessor("request.method", {
29+
id: "method",
30+
cell: MethodCell,
31+
header: "Method",
32+
meta: { width: 140 },
33+
}),
34+
];
35+
36+
export default function InterceptionHistoryTable() {
37+
const events = useNetworkEventStore((s) => s.events);
38+
const interceptedEvents = useNetworkEventStore((s) => s.allInterceptedEvents);
39+
40+
const rows = useMemo(() => {
41+
return interceptedEvents.map((id) => events[id]);
42+
}, [interceptedEvents, events]);
43+
44+
const [data] = useDebounce(rows, 50);
45+
46+
return <NetworkEventTable data={data} columns={columns} />;
47+
}

ui/components/ui/TextAreaAutosize.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default function TextAreaAutosize({
1919
style,
2020
horizontal,
2121
className,
22+
onChange,
2223
onKeyDown,
2324
...props
2425
}: TextAreaAutosizeProps & ReactTextAreaAutosizeProps) {
@@ -59,6 +60,19 @@ export default function TextAreaAutosize({
5960
}
6061
};
6162

63+
const changeHandler = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
64+
// We are using text areas for inputting JSON, so we dont ever want ugly italisized quotes
65+
const event = {
66+
...e,
67+
target: {
68+
...e.target,
69+
value: e.target.value.replace(/[]/g, '"'),
70+
},
71+
};
72+
73+
onChange?.(event);
74+
};
75+
6276
if (!horizontal) {
6377
return (
6478
<ReactTextAreaAutosize
@@ -70,6 +84,7 @@ export default function TextAreaAutosize({
7084
autoComplete="off"
7185
autoCorrect="off"
7286
className={classes}
87+
onChange={changeHandler}
7388
onKeyDown={keydownHandler}
7489
{...props}
7590
/>
@@ -91,6 +106,7 @@ export default function TextAreaAutosize({
91106
autoCorrect="off"
92107
className={classes}
93108
style={{ width, ...style }}
109+
onChange={changeHandler}
94110
onKeyDown={keydownHandler}
95111
{...props}
96112
/>

ui/pages/intercept.tsx

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,35 @@ import useModalStore from "@ui/store/modal";
66
import { NetworkEvent } from "@shared/types";
77
import Button from "@ui/components/ui/Button";
88
import HistoryTable from "@ui/components/tables/HistoryTable";
9-
import { useNetworkEventStore } from "@shared/stores/network-event";
109
import DropRequestButton from "@ui/components/DropRequestButton";
10+
import { useNetworkEventStore } from "@shared/stores/network-event";
1111
import InterceptedTable from "@ui/components/tables/InterceptedTable";
1212
import BrowserControlButton from "@ui/components/BrowserControlButton";
1313
import ForwardRequestButton from "@ui/components/ForwardRequestButton";
14+
import InterceptionHistoryTable from "@ui/components/tables/InterceptionHistoryTable";
1415

1516
enum Tab {
1617
Intercept = "Intercept",
17-
History = "History",
18+
History = "Network History",
19+
InterceptionHistory = "Interception History",
1820
}
1921

2022
const Tabs = [
2123
{
2224
label: "Intercepted",
2325
tab: Tab.Intercept,
26+
description: "Intercepted requests, pending action",
2427
},
28+
2529
{
26-
label: "History",
30+
label: "Network History",
2731
tab: Tab.History,
32+
description: "All network requests",
33+
},
34+
{
35+
label: "Interception History",
36+
tab: Tab.InterceptionHistory,
37+
description: "All previous & current intercepted requests",
2838
},
2939
];
3040

@@ -52,28 +62,12 @@ export default function Intercept() {
5262
</div>
5363
</div>
5464

55-
{/* Tab Layer */}
65+
{/* Tab Bar and Quick Actions */}
5666
<div className="pb-1 flex items-center text-sm gap-1">
57-
{Tabs.map((item) => {
58-
const isActive = item.tab === tab;
59-
const onClick = () => setTab(item.tab);
60-
61-
const classes = classNames(
62-
"px-2 rounded-md py-1 cursor-pointer",
63-
"hover:bg-primary-50 hover:text-primary-500",
64-
"active:bg-primary-100 active:text-primary-600",
65-
isActive ? "bg-primary-50 text-primary-500" : "text-gray-500"
66-
);
67-
68-
return (
69-
<button key={item.tab} className={classes} onClick={onClick}>
70-
<p>{item.label}</p>
71-
</button>
72-
);
73-
})}
67+
<TabBar value={tab} onChange={setTab} />
7468

7569
<div className="flex flex-grow items-center justify-end gap-1">
76-
{tab === Tab.History && (
70+
{[Tab.History, Tab.InterceptionHistory].includes(tab) && (
7771
<Button color="secondary" onClick={clearRequests}>
7872
<ProhibitIcon size={16} /> Clear History
7973
</Button>
@@ -86,6 +80,32 @@ export default function Intercept() {
8680
{/* Main View */}
8781
{tab === Tab.History && <HistoryTable />}
8882
{tab === Tab.Intercept && <InterceptedTable onRowSelectionChange={setSelectedEvents} />}
83+
{tab === Tab.InterceptionHistory && <InterceptionHistoryTable />}
8984
</div>
9085
);
9186
}
87+
88+
interface TabBarProps {
89+
value: Tab;
90+
onChange: (value: Tab) => void;
91+
}
92+
93+
function TabBar({ value, onChange }: TabBarProps) {
94+
return Tabs.map((item) => {
95+
const isActive = item.tab === value;
96+
const onClick = () => onChange(item.tab);
97+
98+
const tabClasses = classNames(
99+
"px-2 rounded-md py-1 cursor-pointer",
100+
"hover:bg-primary-50 hover:text-primary-500",
101+
"active:bg-primary-100 active:text-primary-600",
102+
isActive ? "bg-primary-50 text-primary-500" : "text-gray-500"
103+
);
104+
105+
return (
106+
<button key={item.tab} title={item.description} className={tabClasses} onClick={onClick}>
107+
<p>{item.label}</p>
108+
</button>
109+
);
110+
});
111+
}

ui/pages/settings.tsx

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,46 @@ export default function Settings() {
88
const setPreference = usePreferencesStore((s) => s.setPreference);
99

1010
const themes = [
11-
{
12-
color: colors.indigo[400],
13-
selected: theme === "indigo",
14-
onClick: () => setPreference("theme", "indigo"),
15-
},
1611
{
1712
color: colors.red[400],
1813
selected: theme === "red",
1914
onClick: () => setPreference("theme", "red"),
2015
},
2116
{
22-
color: colors.blue[400],
23-
selected: theme === "blue",
24-
onClick: () => setPreference("theme", "blue"),
17+
color: colors.orange[400],
18+
selected: theme === "orange",
19+
onClick: () => setPreference("theme", "orange"),
20+
},
21+
{
22+
color: colors.green[400],
23+
selected: theme === "green",
24+
onClick: () => setPreference("theme", "green"),
2525
},
2626
{
2727
color: colors.emerald[400],
2828
selected: theme === "emerald",
2929
onClick: () => setPreference("theme", "emerald"),
3030
},
31+
{
32+
color: colors.teal[400],
33+
selected: theme === "teal",
34+
onClick: () => setPreference("theme", "teal"),
35+
},
36+
{
37+
color: colors.blue[400],
38+
selected: theme === "blue",
39+
onClick: () => setPreference("theme", "blue"),
40+
},
41+
{
42+
color: colors.indigo[400],
43+
selected: theme === "indigo",
44+
onClick: () => setPreference("theme", "indigo"),
45+
},
46+
{
47+
color: colors.purple[400],
48+
selected: theme === "purple",
49+
onClick: () => setPreference("theme", "purple"),
50+
},
3151
{
3252
color: colors.fuchsia[400],
3353
selected: theme === "fuchsia",
@@ -55,18 +75,16 @@ interface ThemeSelectorProps {
5575
}
5676

5777
function ThemeSelector({ selected, color, onClick }: ThemeSelectorProps) {
58-
const classes = classNames("rounded-full cursor-pointer", !selected ? "size-8" : "size-6");
78+
const classes = classNames("rounded-full cursor-pointer size-6");
79+
const borderColor = selected ? color : "transparent";
5980

60-
if (selected) {
61-
return (
62-
<div
63-
style={{ borderColor: color }}
64-
className="flex items-center justify-center border-2 size-8 rounded-full"
65-
>
66-
<div className={classes} style={{ backgroundColor: color }} />
67-
</div>
68-
);
69-
}
70-
71-
return <button className={classes} style={{ backgroundColor: color }} onClick={onClick} />;
81+
return (
82+
<div
83+
style={{ borderColor }}
84+
className="flex items-center justify-center border-2 size-8 rounded-full"
85+
onClick={onClick}
86+
>
87+
<div className={classes} style={{ backgroundColor: color }} />
88+
</div>
89+
);
7290
}

0 commit comments

Comments
 (0)