Upgrade to Pro — share decks privately, control downloads, hide ads and more …

VSCodeから一発でProxymanを起動する

kumamotone
September 29, 2023

 VSCodeから一発でProxymanを起動する

2023/09/29 YOUTRUST x ゆめみ Flutter LT会 #3
https://yumemi.connpass.com/event/294763/

Proxyman
https://proxyman.io/

Flutter & Proxymanで通信デバッグをする
https://tech.youtrust.co.jp/entry/2022/10/21/132855

アプリ開発時の通信デバッグに便利な Proxyman の Scripting Tool の使い方
https://tech.youtrust.co.jp/entry/2023/08/30/190746

multi-command
https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command

DartのASTとcodemodを使って機械的なリファクタリングを自動化
https://qiita.com/b4tchkn/items/4b8620c5baa60bfca128

kumamotone

September 29, 2023
Tweet

More Decks by kumamotone

Other Decks in Programming

Transcript

  1. • macOS Ͱ࢖͑Δ Web σόοΪϯάπʔϧ • ௨৴಺༰Λ৭ʑͰ͖Δ • ௨৴಺༰ͷ֬ೝ •

    ௨৴಺༰ͷࠩ͠ସ͑ Proxymanͱ͸ʁ • Flutter & ProxymanͰ௨৴σόοάΛ͢Δ https://tech.youtrust.co.jp/entry/2022/10/21/132855 • ΞϓϦ։ൃ࣌ͷ௨৴σόοάʹศརͳ Proxyman ͷ Scripting Tool ͷ࢖͍ํ https://tech.youtrust.co.jp/entry/2023/08/30/190746 ࢖͍ํ͸ YOUTRUST Tech Blog Λ͝ࢀর͍ͩ͘͞ • cURLܗࣜʹม׵ • ஗͍ΠϯλʔωοτΛγϛϡϨʔτ
  2. • Proxyman Λىಈ͢Δ • ίʔυ্Ͱ localhost:9090 
 Λ࢖͏Α͏ʹมߋ͢Δ • Hot

    Restart Λ࣮ߦ ศར͕ͩ… • ProxymanΛऴྃ͢Δ • ίʔυ্Ͱ localhost:9090 
 Λ࢖Θͳ͍Α͏ʹมߋ͢Δ • Hot Restart Λ࣮ߦ ࢖͍ऴΘͬͨͱ͖ ࢖͏ͱ͖ ΍΍ͭΒ͍ʂ
  3. γϣʔτΧοτͷઃఆ { "key": "cmd+shift+ctrl+p", "command": "multiCommand.toggleProxyAndReload" }, 1. ΩʔϘʔυγϣʔτΧοτͷઃఆΛ։͘ 2.

    ӈ্ʹ͋ΔΩʔϘʔυγϣʔτΧοτΛ։͘(JSON)ϘλϯΛબ୒ 3. Ωʔͱ࣮ߦ͢ΔίϚϯυΛࢦఆ
  4. ίϚϯυͷఆٛ(settings.json) "multiCommand.commands": [ { "command": "multiCommand.toggleProxyAndReload", "interval": 200, "sequence": [

    { "command": "workbench.action.tasks.runTask", "args": "toggleProxySetting" }, "workbench.action.debug.restart" ] } ], 1. toggleProxySetting (࣍ͷεϥΠυͰ঺հ)ͱ͍͏ίϚϯυΛ࣮ߦ͢Δ 2. 0.2ඵ଴ͭ(଴ͨͳ͍ͱίʔυ͕ॻ͖׵ΘΒͳ͍ͷͰ) 3. Hot Restart(workbench.action.debug.restart) Λ࣮ߦ͢Δ https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command multi-commandͱ͍͏ExtensionΛ࢖͍ͬͯ·͢ˠ
  5. { "label": "toggleProxySetting", "type": "shell", "command": "python3", "args": [ "~/toggle_proxy.py"

    ], "problemMatcher": [] } tasks.json toggleProxySetting ͱ͍͏ίϚϯυΛఆٛ toggle_proxy.py (࣍ϖʔδͰ঺հ) Λ࣮ߦ
  6. toggle_proxy.py import subprocess filepath, line_number = "lib/system/http/dio_provider.dart", 22 with open(filepath,

    "r+") as file: lines = file.readlines() line_content = lines[line_number].strip() if line_content == ": null,": lines[line_number] = " : Constants.of().proxyUrl,\n" state = "ON" elif line_content == ": Constants.of().proxyUrl,": lines[line_number] = " : null,\n" state = "OFF" file.seek(0) file.writelines(lines) file.truncate() is_proxyman_running = bool(subprocess.run(["pgrep", "Proxyman"], capture_output=True).stdout) if state == "ON" and not is_proxyman_running: subprocess.run(["open", "-a", "Proxyman"]) elif state == "OFF" and is_proxyman_running: subprocess.run(["pkill", "Proxyman"]) print(f"Proxy is now {state}") ࢦఆͨ͠ϑΝΠϧͷ ࢦఆߦΛॻ͖׵͑ 1SPYZNBO͕ىಈ͍ͯ͠ ͳ͔ͬͨΒىಈ͢Δ
  7. • tasks.jsonͱॻ͖׵͑ର৅ͷϑΝΠϧ͸git؅ཧ͞Ε͍ͯΔ • .gitignoreʹ௥Ճ͢Δͱଞͷਓ΋ӨڹΛड͚ͯ͠·͏ • git update-index —skip-worktree ίϚϯυΛ࢖͏ͱgit ؅ཧԼʹ͋Δ

    ϑΝΠϧΛ͋͑ͯແࢹ͢Δ͜ͱ͕Ͱ͖Δ • git update-index --skip-worktree .vscode/tasks.json • git update-index --skip-worktree lib/system/http/dio_provider.dart ޻෉
  8. • tasks.json / multi-command֦ு / shell ίϚϯυΛ૊Έ߹Θͤͨ΋ͷ Λ keybind ʹઃఆ͢Δ͜ͱͰɺҎԼΛҰൃͰߦ͏͜ͱ͕Ͱ͖Δ

    • ίʔυͷॻ͖׵͑ • Proxymanͷىಈ • Hot Restart • git update-index —skip-worktree ίϚϯυΛ࢖͏ͱgit ؅ཧԼʹ͋Δ ϑΝΠϧΛ͋͑ͯແࢹ͢Δ͜ͱ͕Ͱ͖Δ • Ͳ͏͙ͤ͢յΕΔ͚ͲࣗಈԽͰ͖Δͱָ͍͠ ·ͱΊ