-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.go
More file actions
39 lines (35 loc) · 1.18 KB
/
Copy pathextension.go
File metadata and controls
39 lines (35 loc) · 1.18 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
_ "embed"
"fmt"
"os"
)
// xmppToolsExt is the companion Pi extension source, embedded into the binary
// so there's nothing to install separately. pi-msg writes it to a temp file at
// startup and launches pi with `-e <that file>`. See piext/xmpp-tools.ts.
//
//go:embed piext/xmpp-tools.ts
var xmppToolsExt string
// relayPrefix marks a pi extension `notify` as a pi-msg action relay rather
// than a genuine user notification. Kept in sync with RELAY_PREFIX in
// piext/xmpp-tools.ts.
const relayPrefix = "pi-msg-relay:"
// writeTempExtension materialises the embedded companion extension to a temp
// `.ts` file (jiti keys off the extension) and returns its path. The caller is
// responsible for removing it.
func writeTempExtension() (string, error) {
f, err := os.CreateTemp("", "pi-msg-ext-*.ts")
if err != nil {
return "", fmt.Errorf("creating extension temp file: %w", err)
}
if _, err := f.WriteString(xmppToolsExt); err != nil {
f.Close()
os.Remove(f.Name())
return "", fmt.Errorf("writing extension: %w", err)
}
if err := f.Close(); err != nil {
os.Remove(f.Name())
return "", fmt.Errorf("closing extension: %w", err)
}
return f.Name(), nil
}