-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_linux.go
More file actions
55 lines (48 loc) · 1.14 KB
/
main_linux.go
File metadata and controls
55 lines (48 loc) · 1.14 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"encoding/json"
"log"
"os"
"github.com/roffe/txlogger/pkg/native"
"kernel.org/pub/linux/libs/security/libcap/cap"
)
func runFileChild() {
_, err := native.Drop(cap.NET_ADMIN)
if err != nil {
log.Fatalf("failed to drop NET_ADMIN capability: %v", err)
}
dec := json.NewDecoder(os.Stdin)
enc := json.NewEncoder(os.Stdout)
var req native.FileRequest
if err := dec.Decode(&req); err != nil {
log.Printf("error decoding request: %v", err)
return
}
var path string
switch req.Op {
case "select_folder":
path, err = native.OpenFolderDialog(req.Title)
case "save_file":
path, err = native.SaveFileDialog(req.Title, req.Exts[0], native.FileFilter{
Description: req.Desc,
Extensions: req.Exts,
})
case "open_file":
path, err = native.OpenFileDialog(req.Title, native.FileFilter{
Description: req.Desc,
Extensions: req.Exts,
})
case "quit":
return
default:
log.Printf("unknown operation: %s", req.Op)
return
}
resp := native.FileResponse{Path: path}
if err != nil {
resp.Err = err.Error()
}
if err := enc.Encode(resp); err != nil {
log.Printf("error encoding response: %v", err)
}
}