all repos

onasty @ cbf53ca

a one-time notes service

onasty/web/src/interop.js(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import "./styles.css";

export const flags = ({ env }) => {
  return {
    access_token: JSON.parse(window.localStorage.access_token || "null"),
    refresh_token: JSON.parse(window.localStorage.refresh_token || "null"),
    app_url: env.FRONTEND_URL || "http://localhost:3000",
  };
};

export const onReady = ({ app }) => {
  if (app.ports?.sendToLocalStorage) {
    app.ports.sendToLocalStorage.subscribe(({ key, value }) => {
      window.localStorage[key] = JSON.stringify(value);
    });
  }

  if (app.ports?.sendToClipboard) {
    app.ports.sendToClipboard.subscribe(async (text) => {
      try {
        await navigator.clipboard.writeText(text);
      } catch (error) {
        console.error("Failed to write to clipboard:", error);
      }
    });
  }
};