Slide 1

Slide 1 text

VSCode͔Β ҰൃͰProxymanΛىಈ͢Δ 2023/09/29 YOUTRUST x ΏΊΈ Flutter LTձ #3 twitter.com/kumamo_tone

Slide 2

Slide 2 text

• FlutterΤϯδχΞ @ YOUTRUST ۽ຊ ࿨ਖ਼ (͘·΋Μ) (@kumamo_tone)

Slide 3

Slide 3 text

SwiftUI

Slide 4

Slide 4 text

• 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ܗࣜʹม׵ • ஗͍ΠϯλʔωοτΛγϛϡϨʔτ

Slide 5

Slide 5 text

• Proxyman Λىಈ͢Δ • ίʔυ্Ͱ localhost:9090 
 Λ࢖͏Α͏ʹมߋ͢Δ • Hot Restart Λ࣮ߦ ศར͕ͩ… • ProxymanΛऴྃ͢Δ • ίʔυ্Ͱ localhost:9090 
 Λ࢖Θͳ͍Α͏ʹมߋ͢Δ • Hot Restart Λ࣮ߦ ࢖͍ऴΘͬͨͱ͖ ࢖͏ͱ͖ ΍΍ͭΒ͍ʂ

Slide 6

Slide 6 text

੾Γସ͑Ϙλϯԡͨ͠Β ੾ΓସΘͬͯ΄͍͠

Slide 7

Slide 7 text

DEMO

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

• keybindings.json ʹίϚϯυΛ࣮ߦ͢ΔΩʔόΠϯυΛొ࿥ • tasks.json ʹλεΫΛ௥Ճ • ίʔυΛॻ͖׵͑Δ • ProxymanΛىಈ͢Δ • Hot Restart͢Δ ΍Γํ

Slide 10

Slide 10 text

؆қਤղ ίʔυͷॻ͖׵͑ Proxyman ͷ্ཱͪ͛ ⌘ ⇧ ^ P ɾ ɾ Hot Restart ɾ

Slide 11

Slide 11 text

؆қਤղ ίʔυͷॻ͖׵͑ Proxyman ͷ্ཱͪ͛ ⌘ ⇧ P ɾ ɾ Hot Restart ɾ ^

Slide 12

Slide 12 text

γϣʔτΧοτͷઃఆ { "key": "cmd+shift+ctrl+p", "command": "multiCommand.toggleProxyAndReload" }, 1. ΩʔϘʔυγϣʔτΧοτͷઃఆΛ։͘ 2. ӈ্ʹ͋ΔΩʔϘʔυγϣʔτΧοτΛ։͘(JSON)ϘλϯΛબ୒ 3. Ωʔͱ࣮ߦ͢ΔίϚϯυΛࢦఆ

Slide 13

Slide 13 text

؆қਤղ ίʔυͷॻ͖׵͑ Proxyman ͷ্ཱͪ͛ ⌘ ⇧ P ɾ ɾ Hot Restart ɾ ^

Slide 14

Slide 14 text

ίϚϯυͷఆٛ(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Λ࢖͍ͬͯ·͢ˠ

Slide 15

Slide 15 text

؆қਤղ ίʔυͷॻ͖׵͑ Proxyman ͷ্ཱͪ͛ ⌘ ⇧ P ɾ ɾ Hot Restart ɾ ^

Slide 16

Slide 16 text

{ "label": "toggleProxySetting", "type": "shell", "command": "python3", "args": [ "~/toggle_proxy.py" ], "problemMatcher": [] } tasks.json toggleProxySetting ͱ͍͏ίϚϯυΛఆٛ toggle_proxy.py (࣍ϖʔδͰ঺հ) Λ࣮ߦ

Slide 17

Slide 17 text

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͕ىಈ͍ͯ͠ ͳ͔ͬͨΒىಈ͢Δ

Slide 18

Slide 18 text

• 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 ޻෉

Slide 19

Slide 19 text

• ࢦఆͨ͠ϑΝΠϧͷࢦఆͨ͠ߦΛॻ͖׵͑ • →ࢦఆͨ͠ϑΝΠϧͷ಺༰͕ͪΐͬͱͰ΋มΘͬͨΒಈ͔ͳ͘ͳΔ • ASTΛ࢖ͬͯॻ͖׵͑ͨΒͪΐͬͱϚγʹͳΓͦ͏ • ࢀߟʹͳΓͦ͏ • DartͷASTͱcodemodΛ࢖ͬͯػցతͳϦϑΝΫλϦϯάΛࣗಈ Խ https://qiita.com/b4tchkn/items/4b8620c5baa60bfca128 • ΞΠσΞืूͰ͕͢ϥϑʹӡ༻ͯ͠·͢ վྑͷ༨஍

Slide 20

Slide 20 text

·ͱΊ

Slide 21

Slide 21 text

• tasks.json / multi-command֦ு / shell ίϚϯυΛ૊Έ߹Θͤͨ΋ͷ Λ keybind ʹઃఆ͢Δ͜ͱͰɺҎԼΛҰൃͰߦ͏͜ͱ͕Ͱ͖Δ • ίʔυͷॻ͖׵͑ • Proxymanͷىಈ • Hot Restart • git update-index —skip-worktree ίϚϯυΛ࢖͏ͱgit ؅ཧԼʹ͋Δ ϑΝΠϧΛ͋͑ͯແࢹ͢Δ͜ͱ͕Ͱ͖Δ • Ͳ͏͙ͤ͢յΕΔ͚ͲࣗಈԽͰ͖Δͱָ͍͠ ·ͱΊ