1import type { App } from "./elm/types"
2
3
4// 🏔️
5
6
7let app: App
8
9
10
11// 🚀
12
13
14export function init(a: App) {
15 app = a
16
17 app.ports.copyToClipboard.subscribe(copyToClipboard)
18}
19
20
21
22// Clipboard
23// ---------
24
25
26async function copyToClipboard(text: string) {
27 navigator.clipboard.writeText(text)
28}
29
30
31
32// Focus
33// -----
34
35window.addEventListener("blur", event => {
36 if (app && event.target === window) app.ports.lostWindowFocus.send(null)
37})
38
39
40
41// Internet Connection
42// -------------------
43
44window.addEventListener("online", onlineStatusChanged)
45window.addEventListener("offline", onlineStatusChanged)
46
47
48function onlineStatusChanged() {
49 if (app) app.ports.setIsOnline.send(navigator.onLine)
50}
51
52
53
54// Touch Device
55// ------------
56
57window.addEventListener("touchstart", function onFirstTouch() {
58 if (!app) return
59 app.ports.indicateTouchDevice.send()
60 window.removeEventListener("touchstart", onFirstTouch, false)
61}, false)