patch_mod_ui_rigforge.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. #!/usr/bin/env python3
  2. """Apply the small Rigforge integration patch to the pinned mod-ui source tree."""
  3. import sys
  4. from pathlib import Path
  5. def replace_once(path, original, replacement):
  6. text = path.read_text(encoding="utf-8")
  7. if replacement in text:
  8. return
  9. if text.count(original) != 1:
  10. raise RuntimeError(f"expected one upstream match in {path}")
  11. path.write_text(text.replace(original, replacement), encoding="utf-8")
  12. def replace_if_present(path, original, replacement):
  13. text = path.read_text(encoding="utf-8")
  14. if (replacement and replacement in text) or original not in text:
  15. return
  16. if text.count(original) != 1:
  17. raise RuntimeError(f"expected at most one upstream match in {path}")
  18. path.write_text(text.replace(original, replacement), encoding="utf-8")
  19. def replace_host_method(path, method_name, replacement):
  20. """Replace a complete Host method, independent of its upstream body variant."""
  21. text = path.read_text(encoding="utf-8")
  22. marker = f" def {method_name}("
  23. start = text.find(marker)
  24. if start < 0:
  25. raise RuntimeError(f"could not find Host.{method_name} in {path}")
  26. next_method = text.find("\n def ", start + len(marker))
  27. end = len(text) if next_method < 0 else next_method + 1
  28. replacement = replacement.rstrip() + "\n\n"
  29. updated = text[:start] + replacement + text[end:]
  30. if updated != text:
  31. path.write_text(updated, encoding="utf-8")
  32. def patch_host_connection_methods(host):
  33. """Normalize manual connection handling across old Rigforge patch variants."""
  34. replace_host_method(
  35. host,
  36. "connect",
  37. ''' def connect(self, port_from, port_to, callback):
  38. if (port_from, port_to) in self.connections:
  39. logging.info("[host] NOTE: Requested connection already exists")
  40. callback(True)
  41. return
  42. resolved = pedalboard_connection(
  43. port_from, port_to, self.rigforge_capture_ports,
  44. self.rigforge_playback_ports, self._fix_host_connection_port
  45. )
  46. if resolved is not None and resolved[0] == "pipewire":
  47. pipewire_link = resolved[1]
  48. ok = connect_link(*pipewire_link)
  49. callback(ok)
  50. if ok:
  51. self.connections.append((port_from, port_to))
  52. self.pedalboard_modified = True
  53. self.msg_callback("connect %s %s" % (port_from, port_to))
  54. else:
  55. logging.error(
  56. "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
  57. pipewire_link[0], pipewire_link[1]
  58. )
  59. return
  60. def host_callback(ok):
  61. callback(ok)
  62. if ok:
  63. self.connections.append((port_from, port_to))
  64. self.msg_callback("connect %s %s" % (port_from, port_to))
  65. else:
  66. logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
  67. if resolved is not None:
  68. port_from_2, port_to_2 = resolved[1]
  69. else:
  70. port_from_2 = self._fix_host_connection_port(port_from)
  71. port_to_2 = self._fix_host_connection_port(port_to)
  72. self.send_modified(
  73. "connect %s %s" % (port_from_2, port_to_2),
  74. host_callback,
  75. datatype='boolean'
  76. )''',
  77. )
  78. text = host.read_text(encoding="utf-8")
  79. if " def _rigforge_pipewire_boundary(" in text:
  80. replace_host_method(
  81. host,
  82. "_rigforge_pipewire_boundary",
  83. ''' def _rigforge_pipewire_boundary(self, port_from, port_to):
  84. resolved = pedalboard_connection(
  85. port_from, port_to, self.rigforge_capture_ports,
  86. self.rigforge_playback_ports, self._fix_host_connection_port
  87. )
  88. if resolved is not None and resolved[0] == "pipewire":
  89. return resolved[1]
  90. return None''',
  91. )
  92. replace_host_method(
  93. host,
  94. "disconnect",
  95. ''' def disconnect(self, port_from, port_to, callback):
  96. resolved = pedalboard_connection(
  97. port_from, port_to, self.rigforge_capture_ports,
  98. self.rigforge_playback_ports, self._fix_host_connection_port
  99. )
  100. if resolved is not None and resolved[0] == "pipewire":
  101. pipewire_link = resolved[1]
  102. ok = disconnect_link(*pipewire_link)
  103. callback(ok)
  104. if ok:
  105. self.msg_callback("disconnect %s %s" % (port_from, port_to))
  106. self.pedalboard_modified = True
  107. try:
  108. self.connections.remove((port_from, port_to))
  109. except ValueError:
  110. logging.info(
  111. "[host] Requested '%s' => '%s' connection was not in the UI state",
  112. port_from, port_to
  113. )
  114. else:
  115. logging.error(
  116. "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
  117. pipewire_link[0], pipewire_link[1]
  118. )
  119. return
  120. def host_callback(ok):
  121. # Upstream disconnect failures are not fatal to the UI state.
  122. callback(True)
  123. self.msg_callback("disconnect %s %s" % (port_from, port_to))
  124. if not ok:
  125. logging.error("[host] disconnect '%s' => '%s' failed", port_from, port_to)
  126. self.pedalboard_modified = True
  127. try:
  128. self.connections.remove((port_from, port_to))
  129. except ValueError:
  130. logging.info(
  131. "[host] NOTE: Requested '%s' => '%s' connection doesn't exist",
  132. port_from, port_to
  133. )
  134. if resolved is not None:
  135. port_from_2, port_to_2 = resolved[1]
  136. else:
  137. try:
  138. port_from_2 = self._fix_host_connection_port(port_from)
  139. except Exception:
  140. logging.info("[host] NOTE: Requested '%s' source port doesn't exist, assume disconnected", port_from)
  141. return host_callback(True)
  142. try:
  143. port_to_2 = self._fix_host_connection_port(port_to)
  144. except Exception:
  145. logging.info("[host] NOTE: Requested '%s' target port doesn't exist, assume disconnected", port_to)
  146. return host_callback(True)
  147. if len(self.connections) == 0:
  148. return host_callback(False)
  149. self.send_modified(
  150. "disconnect %s %s" % (port_from_2, port_to_2),
  151. host_callback,
  152. datatype='boolean'
  153. )''',
  154. )
  155. def patch_load_connections(host):
  156. """Make pedalboard restore use the same resolution as manual UI actions."""
  157. text = host.read_text(encoding="utf-8")
  158. method_marker = " def load_pb_connections("
  159. method_start = text.find(method_marker)
  160. if method_start < 0:
  161. raise RuntimeError(f"could not find Host.load_pb_connections in {host}")
  162. block_start = text.find(" if doConnectionNow:", method_start)
  163. block_end = text.find(
  164. "\n elif aliasname1 is not None or aliasname2 is not None:",
  165. block_start,
  166. )
  167. if block_start < 0 or block_end < 0:
  168. raise RuntimeError(
  169. f"could not identify mod-ui pedalboard connection restoration block in {host}"
  170. )
  171. replacement = ''' if doConnectionNow:
  172. resolved = pedalboard_connection(
  173. port_from, port_to, self.rigforge_capture_ports,
  174. self.rigforge_playback_ports, self._fix_host_connection_port
  175. )
  176. if resolved is not None and resolved[0] == "pipewire":
  177. self._rigforge_restore_pipewire_boundary(
  178. resolved[1],
  179. port_from,
  180. port_to,
  181. self.connections,
  182. attempts_left=60
  183. )
  184. continue
  185. try:
  186. if resolved is not None:
  187. port_from_2, port_to_2 = resolved[1]
  188. else:
  189. port_from_2 = self._fix_host_connection_port(port_from)
  190. port_to_2 = self._fix_host_connection_port(port_to)
  191. except Exception:
  192. continue
  193. self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
  194. self.connections.append((port_from, port_to))
  195. self.msg_callback("connect %s %s" % (port_from, port_to))'''
  196. updated = text[:block_start] + replacement + text[block_end:]
  197. if " def _rigforge_restore_pipewire_boundary(" not in updated:
  198. marker = " def load_pb_connections("
  199. position = updated.find(marker)
  200. restore_method = ''' def _rigforge_restore_pipewire_boundary(
  201. self, pipewire_link, port_from, port_to, connection_list, attempts_left
  202. ):
  203. if self.connections is not connection_list:
  204. return
  205. if connect_link(*pipewire_link):
  206. edge = (port_from, port_to)
  207. if edge not in connection_list:
  208. connection_list.append(edge)
  209. self.msg_callback("connect %s %s" % (port_from, port_to))
  210. return
  211. if attempts_left <= 1:
  212. logging.error(
  213. "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
  214. pipewire_link[0], pipewire_link[1]
  215. )
  216. return
  217. IOLoop.instance().call_later(
  218. 0.5,
  219. self._rigforge_restore_pipewire_boundary,
  220. pipewire_link,
  221. port_from,
  222. port_to,
  223. connection_list,
  224. attempts_left - 1
  225. )
  226. '''
  227. if position < 0:
  228. raise RuntimeError(f"could not insert PipeWire restore method in {host}")
  229. updated = updated[:position] + restore_method + updated[position:]
  230. if updated != text:
  231. host.write_text(updated, encoding="utf-8")
  232. def apply(source_root):
  233. app = Path(source_root)
  234. helper = Path(__file__).with_name("mod_ui_pipewire.py")
  235. (app / "mod" / "rigforge_pipewire.py").write_bytes(helper.read_bytes())
  236. replace_if_present(
  237. app / "mod" / "host.py",
  238. "from mod import (\n",
  239. "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection\n"
  240. "from mod import (\n",
  241. )
  242. replace_if_present(
  243. app / "mod" / "host.py",
  244. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  245. ''',
  246. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  247. self.rigforge_capture_ports = {
  248. "capture_%d" % (index + 1): port
  249. for index, port in enumerate(
  250. os.environ.get("MOD_RIGFORGE_CAPTURE_PORTS", "").split(",")
  251. )
  252. if port
  253. }
  254. self.rigforge_playback_ports = {
  255. "playback_%d" % (index + 1): port
  256. for index, port in enumerate(
  257. os.environ.get("MOD_RIGFORGE_PLAYBACK_PORTS", "").split(",")
  258. )
  259. if port
  260. }
  261. ''',
  262. )
  263. replace_if_present(
  264. app / "mod" / "host.py",
  265. ''' self.rigforge_capture_port = os.environ.get("MOD_RIGFORGE_CAPTURE_PORT")
  266. self.rigforge_playback_port = os.environ.get("MOD_RIGFORGE_PLAYBACK_PORT")
  267. ''',
  268. "",
  269. )
  270. replace_if_present(
  271. app / "mod" / "host.py",
  272. ''' if self.rigforge_capture_port and self.rigforge_playback_port:
  273. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  274. self.audioportsIn = ["capture_1"]
  275. self.audioportsOut = ["playback_1"]
  276. ''',
  277. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  278. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  279. self.audioportsIn = [
  280. "capture_%d" % index
  281. for index in range(1, len(self.rigforge_capture_ports) + 1)
  282. ]
  283. self.audioportsOut = [
  284. "playback_%d" % index
  285. for index in range(1, len(self.rigforge_playback_ports) + 1)
  286. ]
  287. ''',
  288. )
  289. replace_once(
  290. app / "mod" / "host.py",
  291. ''' for port in get_jack_hardware_ports(True, False):
  292. client_name, port_name = port.split(":",1)
  293. if client_name == "mod-spi2jack":
  294. cv_port_name = CV_PREFIX + port_name
  295. self.cvportsIn.append(cv_port_name)
  296. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  297. else:
  298. self.audioportsIn.append(port_name)
  299. for port in get_jack_hardware_ports(True, True):
  300. client_name, port_name = port.split(":",1)
  301. if client_name == "mod-jack2spi":
  302. self.cvportsOut.append(CV_PREFIX + port_name)
  303. else:
  304. self.audioportsOut.append(port_name)
  305. ''',
  306. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  307. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  308. self.audioportsIn = [
  309. "capture_%d" % index
  310. for index in range(1, len(self.rigforge_capture_ports) + 1)
  311. ]
  312. self.audioportsOut = [
  313. "playback_%d" % index
  314. for index in range(1, len(self.rigforge_playback_ports) + 1)
  315. ]
  316. else:
  317. for port in get_jack_hardware_ports(True, False):
  318. client_name, port_name = port.split(":",1)
  319. if client_name == "mod-spi2jack":
  320. cv_port_name = CV_PREFIX + port_name
  321. self.cvportsIn.append(cv_port_name)
  322. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  323. else:
  324. self.audioportsIn.append(port_name)
  325. for port in get_jack_hardware_ports(True, True):
  326. client_name, port_name = port.split(":",1)
  327. if client_name == "mod-jack2spi":
  328. self.cvportsOut.append(CV_PREFIX + port_name)
  329. else:
  330. self.audioportsOut.append(port_name)
  331. ''',
  332. )
  333. replace_if_present(
  334. app / "mod" / "host.py",
  335. ''' if data[2] == "capture_1" and self.rigforge_capture_port:
  336. return self.rigforge_capture_port
  337. if data[2] == "playback_1" and self.rigforge_playback_port:
  338. return self.rigforge_playback_port
  339. ''',
  340. ''' if data[2] in self.rigforge_capture_ports:
  341. return self.rigforge_capture_ports[data[2]]
  342. if data[2] in self.rigforge_playback_ports:
  343. return self.rigforge_playback_ports[data[2]]
  344. ''',
  345. )
  346. replace_if_present(
  347. app / "mod" / "host.py",
  348. ''' if len(data) == 3:
  349. # Handle special cases
  350. if data[2] == "serial_midi_in":
  351. ''' + " \n",
  352. ''' if len(data) == 3:
  353. # Handle special cases
  354. if data[2] in self.rigforge_capture_ports:
  355. return self.rigforge_capture_ports[data[2]]
  356. if data[2] in self.rigforge_playback_ports:
  357. return self.rigforge_playback_ports[data[2]]
  358. if data[2] == "serial_midi_in":
  359. ''',
  360. )
  361. replace_if_present(
  362. app / "mod" / "host.py",
  363. ''' if len(data) == 3:
  364. # Handle special cases
  365. if data[2] == "serial_midi_in":
  366. ''',
  367. ''' if len(data) == 3:
  368. # Handle special cases
  369. if data[2] in self.rigforge_capture_ports:
  370. return self.rigforge_capture_ports[data[2]]
  371. if data[2] in self.rigforge_playback_ports:
  372. return self.rigforge_playback_ports[data[2]]
  373. if data[2] == "serial_midi_in":
  374. ''',
  375. )
  376. host_file = app / "mod" / "host.py"
  377. patch_load_connections(host_file)
  378. patch_host_connection_methods(host_file)
  379. replace_if_present(
  380. app / "mod" / "session.py",
  381. ''' # Set a plugin block position within the canvas
  382. ''',
  383. ''' def ws_rigforge_patch_set(self, request_id, instance, uri, valuetype, valuedata, ws):
  384. if valuetype != "p":
  385. ws.write_message("rigforge_patch_set_ack %s 0" % request_id)
  386. return
  387. def completed(ok):
  388. status = 1 if ok else 0
  389. if ok:
  390. self.msg_callback_broadcast(
  391. "patch_set %s 1 %s %c %s" % (instance, uri, valuetype, valuedata),
  392. ws,
  393. )
  394. ws.write_message("rigforge_patch_set_ack %s %d" % (request_id, status))
  395. self.host.patch_set(instance, uri, valuedata, completed)
  396. # Set a plugin block position within the canvas
  397. ''',
  398. )
  399. replace_if_present(
  400. app / "mod" / "webserver.py",
  401. ''' elif cmd == "plugin_pos":
  402. ''',
  403. ''' elif cmd == "rigforge_patch_set":
  404. data = data[1].split(" ", 4)
  405. if len(data) != 5:
  406. self.write_message("rigforge_patch_set_ack invalid 0")
  407. return
  408. request_id, inst, uri, vtype, value = data
  409. if not request_id.isalnum():
  410. self.write_message("rigforge_patch_set_ack invalid 0")
  411. return
  412. SESSION.ws_rigforge_patch_set(
  413. request_id, inst, uri, vtype, value, self
  414. )
  415. elif cmd == "plugin_pos":
  416. ''',
  417. )
  418. replace_if_present(
  419. app / "server.py",
  420. "os.environ['MOD_DEVICE_WEBSERVER_PORT'] = '8888'",
  421. "os.environ.setdefault('MOD_DEVICE_WEBSERVER_PORT', '8888')",
  422. )
  423. replace_if_present(
  424. app / "server.py",
  425. "os.environ['MOD_DEFAULT_PEDALBOARD'] = os.path.join(ROOT, 'default.pedalboard')",
  426. "os.environ.setdefault('MOD_DEFAULT_PEDALBOARD', os.path.join(ROOT, 'default.pedalboard'))",
  427. )
  428. replace_if_present(
  429. app / "html" / "js" / "pedalboard.js",
  430. ''' var captureTitles = {
  431. 1: 'Guitar - Mod-UI Input',
  432. 2: 'Bass - Mod-UI Input',
  433. 3: 'Micro - Mod-UI Input',
  434. 4: 'Synth - Mod-UI Input'
  435. }
  436. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  437. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  438. ''',
  439. ''' var captureTitles = {
  440. 1: 'Guitare - Entrée mod-ui',
  441. 2: 'Basse - Entrée mod-ui',
  442. 3: 'Micro - Entrée mod-ui',
  443. 4: 'Synthé - Entrée mod-ui'
  444. }
  445. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  446. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  447. ''',
  448. )
  449. replace_if_present(
  450. app / "html" / "js" / "pedalboard.js",
  451. ''' var playbackTitles = {
  452. 1: 'Guitar - Mod-UI Output',
  453. 2: 'Bass - Mod-UI Output',
  454. 3: 'Micro - Mod-UI Output',
  455. 4: 'Synth - Mod-UI Output'
  456. }
  457. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  458. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  459. ''',
  460. ''' var playbackTitles = {
  461. 1: 'Guitare - Sortie mod-ui',
  462. 2: 'Basse - Sortie mod-ui',
  463. 3: 'Micro - Sortie mod-ui',
  464. 4: 'Synthé - Sortie mod-ui'
  465. }
  466. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  467. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  468. ''',
  469. )
  470. replace_if_present(
  471. app / "html" / "js" / "pedalboard.js",
  472. ''' var captureTitle = (i === 1) ? 'Rigforge Mod-Host Input' : ('Hardware Capture ' + i)
  473. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  474. ''',
  475. ''' var captureTitles = {
  476. 1: 'Guitare - Entrée mod-ui',
  477. 2: 'Basse - Entrée mod-ui',
  478. 3: 'Micro - Entrée mod-ui',
  479. 4: 'Synthé - Entrée mod-ui'
  480. }
  481. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  482. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  483. ''',
  484. )
  485. replace_if_present(
  486. app / "html" / "js" / "pedalboard.js",
  487. ''' var playbackTitle = (i === 1) ? 'Rigforge Mod-Host Output' : ('Hardware Playback ' + i)
  488. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  489. ''',
  490. ''' var playbackTitles = {
  491. 1: 'Guitare - Sortie mod-ui',
  492. 2: 'Basse - Sortie mod-ui',
  493. 3: 'Micro - Sortie mod-ui',
  494. 4: 'Synthé - Sortie mod-ui'
  495. }
  496. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  497. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  498. ''',
  499. )
  500. replace_once(
  501. app / "html" / "js" / "pedalboard.js",
  502. ''' var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="Hardware Capture ' + i + '">')
  503. ''',
  504. ''' var captureTitles = {
  505. 1: 'Guitare - Entrée mod-ui',
  506. 2: 'Basse - Entrée mod-ui',
  507. 3: 'Micro - Entrée mod-ui',
  508. 4: 'Synthé - Entrée mod-ui'
  509. }
  510. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  511. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  512. ''',
  513. )
  514. replace_once(
  515. app / "html" / "js" / "pedalboard.js",
  516. ''' var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="Hardware Playback ' + i + '">')
  517. ''',
  518. ''' var playbackTitles = {
  519. 1: 'Guitare - Sortie mod-ui',
  520. 2: 'Basse - Sortie mod-ui',
  521. 3: 'Micro - Sortie mod-ui',
  522. 4: 'Synthé - Sortie mod-ui'
  523. }
  524. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  525. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  526. ''',
  527. )
  528. js_file = app / "html" / "js" / "pedalboard.js"
  529. if not js_file.read_bytes().endswith(b"\n"):
  530. js_file.write_bytes(js_file.read_bytes() + b"\n")
  531. if __name__ == "__main__":
  532. if len(sys.argv) != 2:
  533. raise SystemExit("Usage: patch_mod_ui_rigforge.py path/to/mod-ui/app")
  534. apply(Path(sys.argv[1]))