From 1abb8f69217910c8623bd1339da2502aed98ff0d Mon Sep 17 00:00:00 2001 From: ian klatzco Date: Sun, 16 Jan 2022 15:34:07 +0100 Subject: [PATCH] add keyboard shortcut n to mitmweb (by using runCommand inside the kb shortcut handler) (#5061) * add keyboard shortcut n to mitmweb (by creating /flows/create route) * add keyboard shortcut n to mitmweb (simplified, by using runCommand instead of a new route) --- CHANGELOG.md | 1 + web/src/js/__tests__/ducks/ui/keyboardSpec.tsx | 7 ++++++- web/src/js/ducks/ui/keyboard.tsx | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77af9e6a6..666cd7d33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * Fix a bug where `running()` is invoked twice on startup (#3584, @mhils) * Correct documentation example for User-Agent header modification (#4997, @jamesyale) * Fix random connection stalls (#5040, @EndUser509) +* Add `n` new flow keybind to mitmweb (#5061, @ianklatzco) ## 28 September 2021: mitmproxy 7.0.4 diff --git a/web/src/js/__tests__/ducks/ui/keyboardSpec.tsx b/web/src/js/__tests__/ducks/ui/keyboardSpec.tsx index 9f15ab4a4..514cfb98c 100644 --- a/web/src/js/__tests__/ducks/ui/keyboardSpec.tsx +++ b/web/src/js/__tests__/ducks/ui/keyboardSpec.tsx @@ -2,7 +2,7 @@ import reduceFlows, * as flowsActions from "../../../ducks/flows"; import {onKeyDown} from '../../../ducks/ui/keyboard' import * as UIActions from '../../../ducks/ui/flow' import * as modalActions from '../../../ducks/ui/modal' -import {fetchApi} from '../../../utils' +import {fetchApi, runCommand} from '../../../utils' import {TStore} from "../tutils"; jest.mock('../../../utils') @@ -102,6 +102,11 @@ describe('onKeyDown', () => { }) + it('should handle create action', () => { + store.dispatch(createKeyEvent("n")) + expect(runCommand).toBeCalledWith('view.flows.create', "get", "https://example.com/") + }) + it('should handle duplicate action', () => { store.dispatch(createKeyEvent("D")) expect(fetchApi).toBeCalledWith('/flows/1/duplicate', {method: 'POST'}) diff --git a/web/src/js/ducks/ui/keyboard.tsx b/web/src/js/ducks/ui/keyboard.tsx index 76981814d..e318e808f 100644 --- a/web/src/js/ducks/ui/keyboard.tsx +++ b/web/src/js/ducks/ui/keyboard.tsx @@ -2,6 +2,7 @@ import {selectTab} from "./flow" import * as flowsActions from "../flows" import * as modalActions from "./modal" import {tabsForFlow} from "../../components/FlowView"; +import {runCommand} from "../../utils" export function onKeyDown(e: KeyboardEvent) { @@ -80,6 +81,11 @@ export function onKeyDown(e: KeyboardEvent) { break } + case "n": { + runCommand("view.flows.create", "get", "https://example.com/") + break + } + case "D": { if (!flow) { return