all repos

onasty @ c9bc2f83b8df50e6713d59b5874e1d2c1a09d053

a one-time notes service

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

Smirnov Oleksandr Smirnov Oleksandr
ss2316544@gmail.com
web: create note page (#144)..., 11 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
};