onasty/web/src/interop.js (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com feat(web): add dashboard (#214)..., 8 months ago
olexsmir@gmail.com feat(web): add dashboard (#214)..., 8 months ago
| 1 | import "./styles.css"; |
| 2 | |
| 3 | export const flags = ({ env }) => { |
| 4 | return { |
| 5 | access_token: JSON.parse(window.localStorage.access_token || "null"), |
| 6 | refresh_token: JSON.parse(window.localStorage.refresh_token || "null"), |
| 7 | app_url: env.FRONTEND_URL || "http://localhost:3000", |
| 8 | }; |
| 9 | }; |
| 10 | |
| 11 | export const onReady = ({ app }) => { |
| 12 | if (app.ports?.sendToLocalStorage) { |
| 13 | app.ports.sendToLocalStorage.subscribe(({ key, value }) => { |
| 14 | window.localStorage[key] = JSON.stringify(value); |
| 15 | }); |
| 16 | } |
| 17 | |
| 18 | if (app.ports?.sendToClipboard) { |
| 19 | app.ports.sendToClipboard.subscribe(async (text) => { |
| 20 | try { |
| 21 | await navigator.clipboard.writeText(text); |
| 22 | } catch (error) { |
| 23 | console.error("Failed to write to clipboard:", error); |
| 24 | } |
| 25 | }); |
| 26 | } |
| 27 | |
| 28 | if (app.ports?.confirmRequest && app.ports?.confirmResponse) { |
| 29 | app.ports.confirmRequest.subscribe(msg => { |
| 30 | const res = window.confirm(msg); |
| 31 | app.ports.confirmResponse.send(res); |
| 32 | }); |
| 33 | } |
| 34 | }; |