@r_masseater/masseater-utils 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/README.md +1 -1
  2. package/dist/app-name.d.mts +1 -2
  3. package/dist/browser-test/vite.d.mts +1 -2
  4. package/dist/browser-test/vite.mjs +1 -1
  5. package/dist/{browser-test-vite-DS3fTcyM.mjs → browser-test-vite-DtB8cExi.mjs} +1 -1
  6. package/dist/{browser-test-vite-DS3fTcyM.mjs.map → browser-test-vite-DtB8cExi.mjs.map} +1 -1
  7. package/dist/{button-980Op0uF.mjs → button-Cu09f5VU.mjs} +4 -4
  8. package/dist/{button-980Op0uF.mjs.map → button-Cu09f5VU.mjs.map} +1 -1
  9. package/dist/{button-variants-BLMlMm-s.mjs → button-variants-BlDbQ4DD.mjs} +1 -1
  10. package/dist/{button-variants-BLMlMm-s.mjs.map → button-variants-BlDbQ4DD.mjs.map} +1 -1
  11. package/dist/{button-variants-Bupz7GI3.d.mts → button-variants-YGBhQ_mb.d.mts} +1 -2
  12. package/dist/{client-BS-MCJ0I.mjs → client-DX2jXirb.mjs} +39 -42
  13. package/dist/client-DX2jXirb.mjs.map +1 -0
  14. package/dist/{cn-DtxpfSUK.mjs → cn-COS9Py_F.mjs} +1 -1
  15. package/dist/{cn-DtxpfSUK.mjs.map → cn-COS9Py_F.mjs.map} +1 -1
  16. package/dist/{context-B_4aJtEC.mjs → context-COCO-Ecg.mjs} +1 -1
  17. package/dist/{context-B_4aJtEC.mjs.map → context-COCO-Ecg.mjs.map} +1 -1
  18. package/dist/desktop-shell/media-notes/protocol.d.mts +1 -1
  19. package/dist/desktop-shell/media-notes/protocol.mjs +1 -1
  20. package/dist/desktop-shell/media-notes.d.mts +5 -5
  21. package/dist/desktop-shell/media-notes.mjs +7 -7
  22. package/dist/desktop-shell/media-notes.mjs.map +1 -1
  23. package/dist/desktop-shell/release-cli.mjs +2 -2
  24. package/dist/desktop-shell/telemetry.d.mts +1 -2
  25. package/dist/desktop-shell/telemetry.mjs +2 -2
  26. package/dist/desktop-shell/vite.d.mts +1 -2
  27. package/dist/desktop-shell/vite.mjs +2 -2
  28. package/dist/effect2cs.d.mts +1 -2
  29. package/dist/effect2rs.d.mts +2 -3
  30. package/dist/effect2rs.mjs +4 -4
  31. package/dist/{failure-CjeINRVu.mjs → failure-BhLz69b6.mjs} +1 -1
  32. package/dist/{failure-CjeINRVu.mjs.map → failure-BhLz69b6.mjs.map} +1 -1
  33. package/dist/github-workflow.d.mts +2 -3
  34. package/dist/github-workflow.mjs +1 -1
  35. package/dist/{headers-Cr6gAurg.mjs → headers-Bpv9DhNS.mjs} +2 -2
  36. package/dist/{headers-Cr6gAurg.mjs.map → headers-Bpv9DhNS.mjs.map} +1 -1
  37. package/dist/{headers-BK-aW9Kw.d.mts → headers-NUwRihYD.d.mts} +1 -2
  38. package/dist/{heading-class-H4Z13Bpn.mjs → heading-class-Cj0jHgsZ.mjs} +1 -1
  39. package/dist/{heading-class-H4Z13Bpn.mjs.map → heading-class-Cj0jHgsZ.mjs.map} +1 -1
  40. package/dist/{heading-class-CDq0WZpR.d.mts → heading-class-DPbs-YiQ.d.mts} +1 -2
  41. package/dist/hook-flags.d.mts +1 -2
  42. package/dist/{index-CeVmiNfF.d.mts → index-1-4t9rX2.d.mts} +2 -3
  43. package/dist/{index-KNezbJnC.d.mts → index-2z0Rr69i.d.mts} +1 -2
  44. package/dist/{index-ChbPLmqu.d.mts → index-8ZrDzBaY.d.mts} +1 -2
  45. package/dist/{index-CjUS4pmA.d.mts → index-B9MYxbAp.d.mts} +2 -3
  46. package/dist/{index-BkZOsFv4.d.mts → index-BhIR7Vrb.d.mts} +1 -2
  47. package/dist/index-Cz3K0tg_.d.mts +3 -0
  48. package/dist/index-DJGZKGut.d.mts +5 -0
  49. package/dist/{index-CLb1-l_c.d.mts → index-DeL_mxdJ.d.mts} +2 -3
  50. package/dist/index-DgofHxew.d.mts +1 -0
  51. package/dist/{index-Cb8YSEwo.d.mts → index-DmIMnqv8.d.mts} +1 -2
  52. package/dist/kestrion/node.d.mts +1 -2
  53. package/dist/kestrion/npm.d.mts +2 -3
  54. package/dist/kestrion/npm.mjs +1 -1
  55. package/dist/kestrion/pnpm.d.mts +2 -3
  56. package/dist/kestrion/pnpm.mjs +4 -4
  57. package/dist/kestrion.d.mts +1 -1
  58. package/dist/kestrion.mjs +1 -1
  59. package/dist/lapse/sdk.d.mts +1 -2
  60. package/dist/lapse.d.mts +2 -3
  61. package/dist/lapse.mjs +1 -1
  62. package/dist/local-server/node.d.mts +2 -3
  63. package/dist/local-server/node.mjs +3 -3
  64. package/dist/local-server/node.mjs.map +1 -1
  65. package/dist/local-server/serve.d.mts +1 -2
  66. package/dist/local-server.d.mts +2 -3
  67. package/dist/local-server.mjs +1 -1
  68. package/dist/mapped-import/mapper.d.mts +2 -3
  69. package/dist/mapped-import/vite.d.mts +1 -2
  70. package/dist/mapped-import/vite.mjs +1 -1
  71. package/dist/mapped-import.d.mts +1 -1
  72. package/dist/{media-protocol-CMyatw7A.mjs → media-protocol-Buk1x3Gb.mjs} +1 -1
  73. package/dist/{media-protocol-CMyatw7A.mjs.map → media-protocol-Buk1x3Gb.mjs.map} +1 -1
  74. package/dist/model-server/process.mjs +7 -7
  75. package/dist/model-server/process.mjs.map +1 -1
  76. package/dist/model-server.d.mts +423 -102
  77. package/dist/model-server.mjs +1 -1
  78. package/dist/model-server.mjs.map +1 -1
  79. package/dist/{node-main-Bwril94o.mjs → node-main-BrhzkUvP.mjs} +1 -1
  80. package/dist/{node-main-Bwril94o.mjs.map → node-main-BrhzkUvP.mjs.map} +1 -1
  81. package/dist/node-main.d.mts +2 -3
  82. package/dist/node-main.mjs +2 -2
  83. package/dist/{normalize-CogX79EO.mjs → normalize-CboffJzv.mjs} +1 -1
  84. package/dist/{normalize-CogX79EO.mjs.map → normalize-CboffJzv.mjs.map} +1 -1
  85. package/dist/{otlp-ohapzeFh.mjs → otlp-DwZqQqjc.mjs} +1 -1
  86. package/dist/{otlp-ohapzeFh.mjs.map → otlp-DwZqQqjc.mjs.map} +1 -1
  87. package/dist/{otlp-schema-CDBPGJ5s.mjs → otlp-schema-DcYNaxGn.mjs} +1 -1
  88. package/dist/{otlp-schema-CDBPGJ5s.mjs.map → otlp-schema-DcYNaxGn.mjs.map} +1 -1
  89. package/dist/{otlp-spans-D88555DO.mjs → otlp-spans-BF7m_C1W.mjs} +2 -2
  90. package/dist/{otlp-spans-D88555DO.mjs.map → otlp-spans-BF7m_C1W.mjs.map} +1 -1
  91. package/dist/{package-json-CYRyaF9U.mjs → package-json-CdnNcBLT.mjs} +1 -1
  92. package/dist/{package-json-CYRyaF9U.mjs.map → package-json-CdnNcBLT.mjs.map} +1 -1
  93. package/dist/plugin-kit.d.mts +3 -4
  94. package/dist/plugin-kit.mjs +1 -1
  95. package/dist/plugin-kit.mjs.map +1 -1
  96. package/dist/{portfolio-BQJtJtfK.mjs → portfolio-VMbxOrAS.mjs} +1 -1
  97. package/dist/{portfolio-BQJtJtfK.mjs.map → portfolio-VMbxOrAS.mjs.map} +1 -1
  98. package/dist/{process-_W_7DeKe.d.mts → process-BHJEIAWo.d.mts} +1 -2
  99. package/dist/{process-lKS6nYWh.mjs → process-l69KvwcT.mjs} +1 -1
  100. package/dist/{process-lKS6nYWh.mjs.map → process-l69KvwcT.mjs.map} +1 -1
  101. package/dist/process.d.mts +1 -1
  102. package/dist/process.mjs +1 -1
  103. package/dist/{receive-S2txZwcV.mjs → receive-o3h4RxCi.mjs} +1 -1
  104. package/dist/{receive-S2txZwcV.mjs.map → receive-o3h4RxCi.mjs.map} +1 -1
  105. package/dist/{route-handlers-Cn3O2hmf.mjs → route-handlers-CKVY2bqC.mjs} +1 -1
  106. package/dist/{route-handlers-Cn3O2hmf.mjs.map → route-handlers-CKVY2bqC.mjs.map} +1 -1
  107. package/dist/{route-handlers-E2lwhaAf.d.mts → route-handlers-DAmv3iMD.d.mts} +1 -2
  108. package/dist/{run-D59Owiv1.d.mts → run-C1nPjDih.d.mts} +1 -2
  109. package/dist/{run-Cc5W9mi8.mjs → run-DKB2KSjp.mjs} +2 -2
  110. package/dist/{run-Cc5W9mi8.mjs.map → run-DKB2KSjp.mjs.map} +1 -1
  111. package/dist/{run-main-BD4uT8sr.mjs → run-main-Chtieg-p.mjs} +7 -7
  112. package/dist/run-main-Chtieg-p.mjs.map +1 -0
  113. package/dist/security-headers/http.d.mts +2 -3
  114. package/dist/security-headers/http.mjs +1 -1
  115. package/dist/security-headers/request.d.mts +1 -2
  116. package/dist/security-headers/response.d.mts +1 -2
  117. package/dist/security-headers/response.mjs +1 -1
  118. package/dist/security-headers/static.d.mts +1 -1
  119. package/dist/security-headers/static.mjs +1 -1
  120. package/dist/security-headers/vite.d.mts +1 -1
  121. package/dist/security-headers/vite.mjs +1 -1
  122. package/dist/security-headers.d.mts +3 -3
  123. package/dist/security-headers.mjs +2 -2
  124. package/dist/skerm.d.mts +1 -2
  125. package/dist/{socket-port-CTg-qfiP.mjs → socket-port-Cq7YKLFS.mjs} +1 -1
  126. package/dist/{socket-port-CTg-qfiP.mjs.map → socket-port-Cq7YKLFS.mjs.map} +1 -1
  127. package/dist/{span-BKjRu617.mjs → span-BK0kTs11.mjs} +2 -2
  128. package/dist/{span-BKjRu617.mjs.map → span-BK0kTs11.mjs.map} +1 -1
  129. package/dist/{static-page-headers-_B0WGkew.mjs → static-page-headers-muClDOhu.mjs} +2 -2
  130. package/dist/{static-page-headers-_B0WGkew.mjs.map → static-page-headers-muClDOhu.mjs.map} +1 -1
  131. package/dist/{sync-BkyZGGDA.mjs → sync-Ctl9b02O.mjs} +1 -1
  132. package/dist/{sync-BkyZGGDA.mjs.map → sync-Ctl9b02O.mjs.map} +1 -1
  133. package/dist/{table-class-BeiCXlFj.d.mts → table-class-B6OCkS3k.d.mts} +1 -2
  134. package/dist/{table-class-RQvT6MYy.mjs → table-class-Ck9lRrm4.mjs} +1 -1
  135. package/dist/{table-class-RQvT6MYy.mjs.map → table-class-Ck9lRrm4.mjs.map} +1 -1
  136. package/dist/{telemetry-BEWIE8tU.d.mts → telemetry-D6lI0_F9.d.mts} +1 -2
  137. package/dist/ui/backdrop-palette.d.mts +1 -2
  138. package/dist/ui/badge.d.mts +1 -2
  139. package/dist/ui/badge.mjs +1 -1
  140. package/dist/ui/browser-runtime.d.mts +1 -2
  141. package/dist/ui/browser-runtime.mjs +1 -1
  142. package/dist/ui/button-variants.d.mts +1 -1
  143. package/dist/ui/button-variants.mjs +1 -1
  144. package/dist/ui/button.d.mts +3 -4
  145. package/dist/ui/button.mjs +1 -1
  146. package/dist/ui/cn.d.mts +1 -2
  147. package/dist/ui/cn.mjs +1 -1
  148. package/dist/ui/color-scheme.d.mts +1 -2
  149. package/dist/ui/heading-class.d.mts +1 -1
  150. package/dist/ui/heading-class.mjs +1 -1
  151. package/dist/ui/heading.d.mts +2 -3
  152. package/dist/ui/heading.mjs +1 -1
  153. package/dist/ui/input-class.d.mts +1 -2
  154. package/dist/ui/native-select-class.d.mts +1 -2
  155. package/dist/ui/next-page-trigger.d.mts +1 -2
  156. package/dist/ui/next-page-trigger.mjs +2 -2
  157. package/dist/ui/page-footer.d.mts +2 -3
  158. package/dist/ui/page-footer.mjs +1 -1
  159. package/dist/ui/page-header.d.mts +2 -3
  160. package/dist/ui/page-header.mjs +1 -1
  161. package/dist/ui/pointer.d.mts +1 -2
  162. package/dist/ui/portfolio.d.mts +1 -2
  163. package/dist/ui/portfolio.mjs +1 -1
  164. package/dist/ui/table-class.d.mts +1 -1
  165. package/dist/ui/table-class.mjs +1 -1
  166. package/dist/ui/table.d.mts +2 -3
  167. package/dist/ui/table.mjs +2 -2
  168. package/dist/ui/to-wavy-letters.d.mts +1 -2
  169. package/dist/ui/web-analytics.d.mts +3 -4
  170. package/dist/ui/web-analytics.mjs +1 -1
  171. package/dist/usage-meter/report.d.mts +2 -3
  172. package/dist/usage-meter/report.mjs +1 -1
  173. package/dist/{usage-meter-CmCceKx1.mjs → usage-meter-B196tKiM.mjs} +2 -2
  174. package/dist/{usage-meter-CmCceKx1.mjs.map → usage-meter-B196tKiM.mjs.map} +1 -1
  175. package/dist/usage-meter.d.mts +3 -4
  176. package/dist/usage-meter.mjs +2 -2
  177. package/dist/{usage-tally-C7zVBg75.d.mts → usage-tally-BBhBouif.d.mts} +1 -2
  178. package/dist/{usage-tally-FiAxcD-H.mjs → usage-tally-BD3f41V8.mjs} +1 -1
  179. package/dist/{usage-tally-FiAxcD-H.mjs.map → usage-tally-BD3f41V8.mjs.map} +1 -1
  180. package/dist/vitest-otlp/collector-files.d.mts +3 -4
  181. package/dist/vitest-otlp/collector-files.mjs +2 -2
  182. package/dist/vitest-otlp/semconv.d.mts +1 -2
  183. package/dist/vitest-otlp/semconv.mjs +2 -2
  184. package/dist/vitest-otlp/setup.mjs +4 -4
  185. package/dist/vitest-otlp/workers.d.mts +2 -3
  186. package/dist/vitest-otlp/workers.mjs +1 -1
  187. package/dist/{vitest-otlp-current-receiver-8c7rIP1N.mjs → vitest-otlp-current-receiver-Bh_4YbhT.mjs} +1 -1
  188. package/dist/{vitest-otlp-current-receiver-8c7rIP1N.mjs.map → vitest-otlp-current-receiver-Bh_4YbhT.mjs.map} +1 -1
  189. package/dist/{vitest-otlp-current-receiver-DphmM9Ha.d.mts → vitest-otlp-current-receiver-DSgQ3zo9.d.mts} +3 -4
  190. package/dist/vitest-otlp.d.mts +4 -5
  191. package/dist/vitest-otlp.mjs +3 -3
  192. package/dist/{web-analytics-Bz6nyJmQ.mjs → web-analytics-CondjbtC.mjs} +1 -1
  193. package/dist/{web-analytics-Bz6nyJmQ.mjs.map → web-analytics-CondjbtC.mjs.map} +1 -1
  194. package/dist/{web-analytics-BM9LdncT.d.mts → web-analytics-Cvs9PDoh.d.mts} +1 -2
  195. package/dist/workers-tracing/alchemy.d.mts +3 -4
  196. package/dist/workers-tracing/alchemy.mjs +3 -3
  197. package/dist/workers-tracing/browser-logs.d.mts +2 -3
  198. package/dist/workers-tracing/browser-logs.mjs +2 -2
  199. package/dist/workers-tracing/browser-spans.d.mts +2 -3
  200. package/dist/workers-tracing/browser-spans.mjs +2 -2
  201. package/dist/workers-tracing/effect.browser.d.mts +2 -3
  202. package/dist/workers-tracing/effect.browser.mjs +1 -1
  203. package/dist/workers-tracing/effect.d.mts +2 -3
  204. package/dist/workers-tracing/effect.mjs +3 -3
  205. package/dist/workers-tracing/elysia.d.mts +2 -3
  206. package/dist/workers-tracing/elysia.mjs +4 -4
  207. package/dist/workers-tracing/elysia.node.d.mts +1 -1
  208. package/dist/workers-tracing/elysia.node.mjs +1 -1
  209. package/dist/workers-tracing/tanstack-start.browser.d.mts +1 -2
  210. package/dist/workers-tracing/tanstack-start.d.mts +1 -2
  211. package/dist/workers-tracing/tanstack-start.mjs +3 -3
  212. package/dist/workers-tracing/trace-sink-worker.d.mts +1 -2
  213. package/dist/workers-tracing/trace-sink-worker.mjs +1 -1
  214. package/dist/workers-tracing/workers-ai.d.mts +1 -2
  215. package/dist/yohaku-protocol/sync.d.mts +1 -1
  216. package/dist/yohaku-protocol/sync.mjs +1 -1
  217. package/dist/yohaku-protocol.d.mts +1 -1
  218. package/dist/yohaku-protocol.mjs +1 -1
  219. package/native/desktop-shell/Cargo.toml +38 -0
  220. package/native/desktop-shell/src/app/builder.rs +39 -0
  221. package/native/desktop-shell/src/app/mod.rs +3 -0
  222. package/native/desktop-shell/src/entities/access_token.rs +77 -0
  223. package/native/desktop-shell/src/entities/mod.rs +1 -0
  224. package/native/desktop-shell/src/features/mod.rs +4 -0
  225. package/native/desktop-shell/src/features/record_telemetry/appender.rs +127 -0
  226. package/native/desktop-shell/src/features/record_telemetry/forwarder.rs +183 -0
  227. package/native/desktop-shell/src/features/record_telemetry/invoke.rs +80 -0
  228. package/native/desktop-shell/src/features/record_telemetry/mod.rs +231 -0
  229. package/native/desktop-shell/src/features/serve_screen/mod.rs +135 -0
  230. package/native/desktop-shell/src/features/serve_tools/mod.rs +37 -0
  231. package/native/desktop-shell/src/features/update_app/mod.rs +53 -0
  232. package/native/desktop-shell/src/lib.rs +17 -0
  233. package/native/desktop-shell/src/shared/lib/bearer.rs +49 -0
  234. package/native/desktop-shell/src/shared/lib/host.rs +1 -0
  235. package/native/desktop-shell/src/shared/lib/mod.rs +5 -0
  236. package/native/desktop-shell/src/shared/mod.rs +2 -0
  237. package/native/desktop-shell/src/shared/ui/log.rs +15 -0
  238. package/native/desktop-shell/src/shared/ui/menu.rs +37 -0
  239. package/native/desktop-shell/src/shared/ui/mod.rs +7 -0
  240. package/native/desktop-shell/src/shared/ui/window.rs +49 -0
  241. package/native/media-notes/Cargo.toml +36 -0
  242. package/native/media-notes/src/entities/media_file.rs +89 -0
  243. package/native/media-notes/src/entities/media_notes.rs +31 -0
  244. package/native/media-notes/src/entities/mod.rs +3 -0
  245. package/native/media-notes/src/entities/source/credit.rs +129 -0
  246. package/native/media-notes/src/entities/source/link.rs +194 -0
  247. package/native/media-notes/src/entities/source/mod.rs +5 -0
  248. package/native/media-notes/src/features/mod.rs +2 -0
  249. package/native/media-notes/src/features/open_media/mod.rs +88 -0
  250. package/native/media-notes/src/features/share_mcp_access.rs +15 -0
  251. package/native/media-notes/src/lib.rs +12 -0
  252. package/native/media-notes/src/shared/db/mod.rs +3 -0
  253. package/native/media-notes/src/shared/db/store.rs +276 -0
  254. package/native/media-notes/src/shared/lib/failure.rs +55 -0
  255. package/native/media-notes/src/shared/lib/mcp.rs +34 -0
  256. package/native/media-notes/src/shared/lib/mod.rs +5 -0
  257. package/native/media-notes/src/shared/mod.rs +3 -0
  258. package/native/media-notes/src/shared/protocol.rs +69 -0
  259. package/package.json +7 -3
  260. package/skills/build-tauri-app/SKILL.md +4 -2
  261. package/dist/client-BS-MCJ0I.mjs.map +0 -1
  262. package/dist/index-BtcxUsGh.d.mts +0 -4
  263. package/dist/index-CUo4CRam.d.mts +0 -1
  264. package/dist/index-DudHILTn.d.mts +0 -6
  265. package/dist/run-main-BD4uT8sr.mjs.map +0 -1
@@ -0,0 +1,135 @@
1
+ use tauri::utils::acl::capability::{Capability, CapabilityRemote};
2
+ use tauri::{App, Builder, Manager, Runtime, Url, WebviewUrl, WebviewWindowBuilder, Wry};
3
+
4
+ use crate::shared::lib::HOST;
5
+ use crate::shared::ui::paint_like_the_page;
6
+
7
+ pub type Setup = Result<(), Box<dyn std::error::Error>>;
8
+
9
+ const SERVED: &str = "served-screen";
10
+
11
+ fn bound_port(port: u16) -> std::io::Result<u16> {
12
+ Ok(std::net::TcpListener::bind((HOST, port))?
13
+ .local_addr()?
14
+ .port())
15
+ }
16
+
17
+ pub fn screen_port(preferred: u16) -> std::io::Result<u16> {
18
+ bound_port(preferred).or_else(|_| bound_port(0))
19
+ }
20
+
21
+ fn origin(port: u16) -> String {
22
+ format!("http://{HOST}:{port}")
23
+ }
24
+
25
+ fn served_at(port: u16) -> Result<WebviewUrl, url::ParseError> {
26
+ if tauri::is_dev() {
27
+ return Ok(WebviewUrl::default());
28
+ }
29
+ Ok(WebviewUrl::External(Url::parse(&origin(port))?))
30
+ }
31
+
32
+ fn served_capability(capability: &str, port: u16) -> serde_json::Result<String> {
33
+ let mut capability: Capability = serde_json::from_str(capability)?;
34
+ SERVED.clone_into(&mut capability.identifier);
35
+ capability.local = false;
36
+ capability.remote = Some(CapabilityRemote {
37
+ urls: vec![origin(port)],
38
+ });
39
+ serde_json::to_string(&capability)
40
+ }
41
+
42
+ pub fn allow_screen<R: Runtime>(app: &impl Manager<R>, port: u16, capability: &str) -> Setup {
43
+ app.add_capability(served_capability(capability, port)?)?;
44
+ Ok(())
45
+ }
46
+
47
+ #[must_use]
48
+ pub fn served(app: Builder<Wry>, port: u16) -> Builder<Wry> {
49
+ if tauri::is_dev() {
50
+ return app;
51
+ }
52
+ app.plugin(
53
+ tauri_plugin_localhost::Builder::new(port)
54
+ .host(HOST)
55
+ .build(),
56
+ )
57
+ }
58
+
59
+ pub fn open_window(app: &App, port: u16, capability: &str) -> Setup {
60
+ if !tauri::is_dev() {
61
+ allow_screen(app, port, capability)?;
62
+ }
63
+ let mut config = app
64
+ .config()
65
+ .app
66
+ .windows
67
+ .first()
68
+ .cloned()
69
+ .ok_or("tauri.conf.json has no window")?;
70
+ config.url = served_at(port)?;
71
+ let window = WebviewWindowBuilder::from_config(app, &config)?.build()?;
72
+ paint_like_the_page(&window);
73
+ Ok(())
74
+ }
75
+
76
+ #[cfg(test)]
77
+ mod tests {
78
+ use std::net::TcpListener;
79
+
80
+ use tauri::Url;
81
+ use tauri::utils::acl::RemoteUrlPattern;
82
+ use tauri::utils::acl::capability::Capability;
83
+
84
+ use super::{HOST, SERVED, origin, screen_port, served_capability};
85
+
86
+ const CAPABILITY: &str = r#"{
87
+ "$schema": "../gen/schemas/desktop-schema.json",
88
+ "identifier": "default",
89
+ "windows": ["main"],
90
+ "permissions": ["core:default", "allow-list-marks"]
91
+ }"#;
92
+
93
+ #[test]
94
+ fn the_served_screen_gets_the_permissions_of_the_capability_on_its_own_origin_only() {
95
+ let local: Capability = serde_json::from_str(CAPABILITY).unwrap();
96
+ let served: Capability =
97
+ serde_json::from_str(&served_capability(CAPABILITY, 47_231).unwrap()).unwrap();
98
+ assert_eq!(served.identifier, SERVED);
99
+ assert!(!served.local);
100
+ assert_eq!(served.windows, local.windows);
101
+ assert_eq!(served.permissions, local.permissions);
102
+ assert_eq!(served.remote.unwrap().urls, ["http://127.0.0.1:47231"]);
103
+ }
104
+
105
+ #[test]
106
+ fn the_origin_covers_every_page_of_the_chosen_port_and_no_other_port() {
107
+ let pattern: RemoteUrlPattern = origin(47_231).parse().unwrap();
108
+ let page = |url: &str| pattern.test(&Url::parse(url).unwrap());
109
+ assert!(page("http://127.0.0.1:47231/"));
110
+ assert!(page("http://127.0.0.1:47231/assets/index.js?v=1#top"));
111
+ assert!(!page("http://127.0.0.1:47232/"));
112
+ assert!(!page("http://127.0.0.1/"));
113
+ assert!(!page("http://localhost:47231/"));
114
+ assert!(!page("https://127.0.0.1:47231/"));
115
+ }
116
+
117
+ #[test]
118
+ fn keeps_the_preferred_port_when_it_is_free() {
119
+ let free = TcpListener::bind((HOST, 0))
120
+ .unwrap()
121
+ .local_addr()
122
+ .unwrap()
123
+ .port();
124
+ assert_eq!(screen_port(free).unwrap(), free);
125
+ }
126
+
127
+ #[test]
128
+ fn moves_to_another_port_when_the_preferred_one_is_taken() {
129
+ let taken = TcpListener::bind((HOST, 0)).unwrap();
130
+ let port = taken.local_addr().unwrap().port();
131
+ let chosen = screen_port(port).unwrap();
132
+ assert_ne!(chosen, port);
133
+ assert_ne!(chosen, 0);
134
+ }
135
+ }
@@ -0,0 +1,37 @@
1
+ use std::io;
2
+ use std::sync::Arc;
3
+
4
+ use axum::Router;
5
+ use rmcp::ServerHandler;
6
+ use rmcp::transport::streamable_http_server::session::local::LocalSessionManager;
7
+ use rmcp::transport::streamable_http_server::{StreamableHttpServerConfig, StreamableHttpService};
8
+ use tokio::net::TcpListener;
9
+
10
+ use crate::shared::lib::{HOST, guarded};
11
+
12
+ pub const MCP_PATH: &str = "/mcp";
13
+
14
+ #[must_use]
15
+ pub fn url(port: u16) -> String {
16
+ format!("http://{HOST}:{port}{MCP_PATH}")
17
+ }
18
+
19
+ pub fn router<S: ServerHandler + Send + 'static>(
20
+ token: String,
21
+ tools: impl Fn() -> S + Send + Sync + 'static,
22
+ ) -> Router {
23
+ let service = StreamableHttpService::new(
24
+ move || Ok(tools()),
25
+ Arc::new(LocalSessionManager::default()),
26
+ StreamableHttpServerConfig::default(),
27
+ );
28
+ guarded(Router::new().nest_service(MCP_PATH, service), token)
29
+ }
30
+
31
+ pub async fn serve(port: u16, router: Router) -> io::Result<()> {
32
+ serve_on(TcpListener::bind((HOST, port)).await?, router).await
33
+ }
34
+
35
+ pub async fn serve_on(listener: TcpListener, router: Router) -> io::Result<()> {
36
+ axum::serve(listener, router).await
37
+ }
@@ -0,0 +1,53 @@
1
+ use tauri::plugin::{Builder, TauriPlugin};
2
+ use tauri::{AppHandle, Runtime, async_runtime};
3
+ use tauri_plugin_dialog::{DialogExt, MessageDialogButtons};
4
+ use tauri_plugin_updater::UpdaterExt;
5
+
6
+ const RESTART: &str = "再起動して更新";
7
+ const LATER: &str = "あとで";
8
+
9
+ fn agreed<R: Runtime>(app: &AppHandle<R>, version: &str) -> bool {
10
+ let name = &app.package_info().name;
11
+ app.dialog()
12
+ .message(format!("{name} {version} に更新できます。"))
13
+ .buttons(MessageDialogButtons::OkCancelCustom(
14
+ RESTART.to_owned(),
15
+ LATER.to_owned(),
16
+ ))
17
+ .blocking_show()
18
+ }
19
+
20
+ #[tracing::instrument(skip_all)]
21
+ async fn update<R: Runtime>(app: AppHandle<R>) -> tauri_plugin_updater::Result<()> {
22
+ let Some(update) = app.updater()?.check().await? else {
23
+ return Ok(());
24
+ };
25
+ let installer = update.download(|_, _| {}, || {}).await?;
26
+ let version = update.version.clone();
27
+ let asking = app.clone();
28
+ let agreed = async_runtime::spawn_blocking(move || agreed(&asking, &version))
29
+ .await
30
+ .unwrap_or(false);
31
+ if agreed {
32
+ update.install(installer)?;
33
+ app.restart();
34
+ }
35
+ Ok(())
36
+ }
37
+
38
+ #[must_use]
39
+ pub fn updates_plugin<R: Runtime>() -> TauriPlugin<R> {
40
+ Builder::new("updates")
41
+ .setup(|app, _api| {
42
+ if !tauri::is_dev() {
43
+ let app = app.clone();
44
+ async_runtime::spawn(async move {
45
+ if let Err(failure) = update(app).await {
46
+ tracing::warn!(%failure, "update failed");
47
+ }
48
+ });
49
+ }
50
+ Ok(())
51
+ })
52
+ .build()
53
+ }
@@ -0,0 +1,17 @@
1
+ mod app;
2
+ mod entities;
3
+ mod features;
4
+ mod shared;
5
+
6
+ pub use app::{Shell, builder};
7
+ pub use entities::access_token::token as mcp_token;
8
+ pub use features::record_telemetry::{telemetry_plugin, traced_commands};
9
+ pub use features::serve_screen::{Setup, allow_screen, open_window, screen_port, served};
10
+ pub use features::serve_tools::{
11
+ MCP_PATH, router as mcp_router, serve as serve_mcp, serve_on as serve_mcp_on, url as mcp_url,
12
+ };
13
+ pub use shared::lib::HOST;
14
+ pub use shared::ui::{
15
+ browser_keys_plugin, japanese_menu, log_plugin, paint_like_the_page, remembered, show,
16
+ state_plugin,
17
+ };
@@ -0,0 +1,49 @@
1
+ use std::sync::Arc;
2
+
3
+ use axum::Router;
4
+ use axum::extract::{Request, State};
5
+ use axum::http::{HeaderMap, StatusCode, header};
6
+ use axum::middleware::{self, Next};
7
+ use axum::response::{IntoResponse, Response};
8
+
9
+ const BEARER: &str = "Bearer ";
10
+
11
+ fn presented(headers: &HeaderMap, expected: &str) -> bool {
12
+ headers
13
+ .get(header::AUTHORIZATION)
14
+ .and_then(|value| value.to_str().ok())
15
+ .and_then(|value| value.strip_prefix(BEARER))
16
+ .is_some_and(|given| {
17
+ constant_time_eq::constant_time_eq(given.as_bytes(), expected.as_bytes())
18
+ })
19
+ }
20
+
21
+ async fn authorized(State(token): State<Arc<String>>, request: Request, next: Next) -> Response {
22
+ if presented(request.headers(), &token) {
23
+ return next.run(request).await;
24
+ }
25
+ StatusCode::UNAUTHORIZED.into_response()
26
+ }
27
+
28
+ pub fn guarded(router: Router, token: String) -> Router {
29
+ router.layer(middleware::from_fn_with_state(Arc::new(token), authorized))
30
+ }
31
+
32
+ #[cfg(test)]
33
+ mod tests {
34
+ use axum::http::{HeaderMap, HeaderValue, header};
35
+
36
+ use super::presented;
37
+
38
+ #[test]
39
+ fn requires_the_bearer_token() {
40
+ let mut headers = HeaderMap::new();
41
+ assert!(!presented(&headers, "secret"));
42
+ headers.insert(
43
+ header::AUTHORIZATION,
44
+ HeaderValue::from_static("Bearer secret"),
45
+ );
46
+ assert!(presented(&headers, "secret"));
47
+ assert!(!presented(&headers, "other"));
48
+ }
49
+ }
@@ -0,0 +1 @@
1
+ pub const HOST: &str = "127.0.0.1";
@@ -0,0 +1,5 @@
1
+ mod bearer;
2
+ mod host;
3
+
4
+ pub use bearer::guarded;
5
+ pub use host::HOST;
@@ -0,0 +1,2 @@
1
+ pub mod lib;
2
+ pub mod ui;
@@ -0,0 +1,15 @@
1
+ use tauri::Runtime;
2
+ use tauri::plugin::TauriPlugin;
3
+ use tauri_plugin_log::{RotationStrategy, log::LevelFilter};
4
+
5
+ const LOG_FILE_BYTES: u128 = 1_000_000;
6
+ const LOG_FILES_KEPT: usize = 5;
7
+
8
+ #[must_use]
9
+ pub fn log_plugin<R: Runtime>() -> TauriPlugin<R> {
10
+ tauri_plugin_log::Builder::new()
11
+ .level(LevelFilter::Info)
12
+ .max_file_size(LOG_FILE_BYTES)
13
+ .rotation_strategy(RotationStrategy::KeepSome(LOG_FILES_KEPT))
14
+ .build()
15
+ }
@@ -0,0 +1,37 @@
1
+ use tauri::menu::{Menu, MenuBuilder, SubmenuBuilder};
2
+ use tauri::{AppHandle, Wry};
3
+
4
+ pub fn japanese_menu(app: &AppHandle, name: &str) -> tauri::Result<Menu<Wry>> {
5
+ let application = SubmenuBuilder::new(app, name)
6
+ .about_with_text(format!("{name}について"), None)
7
+ .separator()
8
+ .services_with_text("サービス")
9
+ .separator()
10
+ .hide_with_text(format!("{name}を隠す"))
11
+ .hide_others_with_text("ほかを隠す")
12
+ .show_all_with_text("すべてを表示")
13
+ .separator()
14
+ .quit_with_text(format!("{name}を終了"))
15
+ .build()?;
16
+ let edit = SubmenuBuilder::new(app, "編集")
17
+ .undo_with_text("取り消す")
18
+ .redo_with_text("やり直す")
19
+ .separator()
20
+ .cut_with_text("カット")
21
+ .copy_with_text("コピー")
22
+ .paste_with_text("ペースト")
23
+ .select_all_with_text("すべてを選択")
24
+ .build()?;
25
+ let view = SubmenuBuilder::new(app, "表示")
26
+ .fullscreen_with_text("フルスクリーンにする")
27
+ .build()?;
28
+ let window = SubmenuBuilder::new(app, "ウインドウ")
29
+ .minimize_with_text("しまう")
30
+ .maximize_with_text("拡大/縮小")
31
+ .separator()
32
+ .close_window_with_text("閉じる")
33
+ .build()?;
34
+ MenuBuilder::new(app)
35
+ .items(&[&application, &edit, &view, &window])
36
+ .build()
37
+ }
@@ -0,0 +1,7 @@
1
+ mod log;
2
+ mod menu;
3
+ mod window;
4
+
5
+ pub use log::log_plugin;
6
+ pub use menu::japanese_menu;
7
+ pub use window::{browser_keys_plugin, paint_like_the_page, remembered, show, state_plugin};
@@ -0,0 +1,49 @@
1
+ use tauri::plugin::TauriPlugin;
2
+ use tauri::window::Color;
3
+ use tauri::{AppHandle, Manager, Theme, WebviewWindow, Wry};
4
+ use tauri_plugin_prevent_default::Flags;
5
+ use tauri_plugin_window_state::StateFlags;
6
+
7
+ const LIGHT_PAGE: Color = Color(255, 255, 255, 255);
8
+ const DARK_PAGE: Color = Color(9, 9, 11, 255);
9
+
10
+ #[must_use]
11
+ pub fn remembered() -> StateFlags {
12
+ StateFlags::all() - StateFlags::VISIBLE
13
+ }
14
+
15
+ #[must_use]
16
+ pub fn state_plugin() -> TauriPlugin<Wry> {
17
+ tauri_plugin_window_state::Builder::new()
18
+ .with_state_flags(remembered())
19
+ .build()
20
+ }
21
+
22
+ #[must_use]
23
+ pub fn browser_keys_plugin() -> TauriPlugin<Wry> {
24
+ let kept = Flags::CONTEXT_MENU | Flags::FOCUS_MOVE;
25
+ let kept = if cfg!(debug_assertions) {
26
+ kept | Flags::DEV_TOOLS | Flags::RELOAD
27
+ } else {
28
+ kept
29
+ };
30
+ tauri_plugin_prevent_default::Builder::new()
31
+ .with_flags(Flags::all().difference(kept))
32
+ .build()
33
+ }
34
+
35
+ pub fn paint_like_the_page(window: &WebviewWindow) {
36
+ let page = match window.theme() {
37
+ Ok(Theme::Dark) => DARK_PAGE,
38
+ _ => LIGHT_PAGE,
39
+ };
40
+ let _ = window.set_background_color(Some(page));
41
+ }
42
+
43
+ pub fn show(app: &AppHandle, label: &str) {
44
+ if let Some(window) = app.get_webview_window(label) {
45
+ let _ = window.show();
46
+ let _ = window.unminimize();
47
+ let _ = window.set_focus();
48
+ }
49
+ }
@@ -0,0 +1,36 @@
1
+ [package]
2
+ name = "media-notes"
3
+ version.workspace = true
4
+ edition.workspace = true
5
+ license = "MIT"
6
+ repository.workspace = true
7
+ rust-version.workspace = true
8
+ publish = false
9
+
10
+ [dependencies]
11
+ desktop-shell = { path = "../desktop-shell" }
12
+ regex = "=1.13.2"
13
+ reqwest = { version = "=0.13.5", default-features = false, features = [
14
+ "json",
15
+ "query",
16
+ "rustls",
17
+ "system-proxy",
18
+ ] }
19
+ rmcp = { version = "=3.12.0", features = ["macros", "server", "transport-streamable-http-server"] }
20
+ rusqlite = { version = "=0.43.0", features = ["bundled"] }
21
+ schemars = "=1.2.3"
22
+ serde = { version = "=1.0.229", features = ["derive"] }
23
+ serde_json = "=1.0.154"
24
+ sha2 = "=0.11.2"
25
+ specta = { version = "=2.0.0-rc.28", features = ["derive", "function"] }
26
+ specta-typescript = "=0.0.15"
27
+ tauri = { version = "=2.12.7", features = ["protocol-asset"] }
28
+ tauri-plugin-dialog = "=2.8.4"
29
+ url = "=2.5.9"
30
+ uuid = { version = "=1.29.3", features = ["v7"] }
31
+
32
+ [dev-dependencies]
33
+ tempfile = "=3.27.0"
34
+
35
+ [lints]
36
+ workspace = true
@@ -0,0 +1,89 @@
1
+ use std::fmt::Write;
2
+ use std::fs::File;
3
+ use std::io::{BufRead, BufReader};
4
+ use std::path::Path;
5
+
6
+ use sha2::{Digest, Sha256};
7
+
8
+ use crate::shared::lib::{Failure, Outcome};
9
+ use crate::shared::protocol::{Media, Opened, Site, Source};
10
+
11
+ fn hex(bytes: &[u8]) -> String {
12
+ bytes.iter().fold(String::new(), |mut text, byte| {
13
+ let _ = write!(text, "{byte:02x}");
14
+ text
15
+ })
16
+ }
17
+
18
+ pub fn digest(path: &Path) -> Outcome<String> {
19
+ let mut reader = BufReader::new(File::open(path)?);
20
+ let mut hasher = Sha256::new();
21
+ loop {
22
+ let chunk = reader.fill_buf()?;
23
+ if chunk.is_empty() {
24
+ break;
25
+ }
26
+ hasher.update(chunk);
27
+ let read = chunk.len();
28
+ reader.consume(read);
29
+ }
30
+ Ok(hex(&hasher.finalize()))
31
+ }
32
+
33
+ pub fn opened_file(path: &Path) -> Outcome<Opened> {
34
+ let title = path
35
+ .file_name()
36
+ .and_then(|name| name.to_str())
37
+ .ok_or_else(|| Failure::new("the file has no name"))?
38
+ .to_owned();
39
+ Ok(Opened {
40
+ media: Media {
41
+ source: Source {
42
+ site: Site::File,
43
+ id: digest(path)?,
44
+ },
45
+ title,
46
+ artist: String::new(),
47
+ },
48
+ location: path.to_string_lossy().into_owned(),
49
+ })
50
+ }
51
+
52
+ #[cfg(test)]
53
+ mod tests {
54
+ use std::fs;
55
+
56
+ use super::{digest, opened_file};
57
+ use crate::shared::protocol::Site;
58
+
59
+ #[test]
60
+ fn digests_the_file_as_sha256() {
61
+ let directory = tempfile::tempdir().expect("temporary directory");
62
+ let file = directory.path().join("abc.txt");
63
+ fs::write(&file, b"abc").expect("file");
64
+ assert_eq!(
65
+ digest(&file).expect("digest"),
66
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
67
+ );
68
+ }
69
+
70
+ #[test]
71
+ fn names_a_file_by_its_contents() {
72
+ let directory = tempfile::tempdir().expect("temporary directory");
73
+ let first = directory.path().join("cut-v1.mp4");
74
+ let renamed = directory.path().join("cut-final.mp4");
75
+ fs::write(&first, b"frames").expect("first file");
76
+ fs::write(&renamed, b"frames").expect("renamed file");
77
+ let opened = opened_file(&first).expect("opened");
78
+ assert_eq!(opened.media.source.site, Site::File);
79
+ assert_eq!(
80
+ opened.media.source.id,
81
+ "594cfd2607d4f09e1ce6241203e418cacfed545063792bc5eab7afaadbf0c4e0"
82
+ );
83
+ assert_eq!(opened.media.title, "cut-v1.mp4");
84
+ assert_eq!(
85
+ opened_file(&renamed).expect("renamed").media.source,
86
+ opened.media.source
87
+ );
88
+ }
89
+ }
@@ -0,0 +1,31 @@
1
+ use std::path::Path;
2
+
3
+ use crate::shared::lib::Outcome;
4
+ use crate::shared::protocol::{McpAccess, Site};
5
+
6
+ pub struct MediaNotes {
7
+ pub client: reqwest::Client,
8
+ pub sites: &'static [Site],
9
+ pub mcp: McpAccess,
10
+ }
11
+
12
+ pub struct Setting<'a> {
13
+ pub name: &'static str,
14
+ pub version: &'static str,
15
+ pub data: &'a Path,
16
+ pub sites: &'static [Site],
17
+ pub port: u16,
18
+ }
19
+
20
+ pub fn media_notes(setting: &Setting<'_>) -> Outcome<MediaNotes> {
21
+ Ok(MediaNotes {
22
+ client: reqwest::Client::builder()
23
+ .user_agent(format!("{}/{}", setting.name, setting.version))
24
+ .build()?,
25
+ sites: setting.sites,
26
+ mcp: McpAccess {
27
+ url: desktop_shell::mcp_url(setting.port),
28
+ token: desktop_shell::mcp_token(setting.data)?,
29
+ },
30
+ })
31
+ }
@@ -0,0 +1,3 @@
1
+ pub mod media_file;
2
+ pub mod media_notes;
3
+ pub mod source;