-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdbus.go
67 lines (56 loc) · 1.63 KB
/
dbus.go
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
56
57
58
59
60
61
62
63
64
65
66
67
package definitions
import (
"io/fs"
"os"
"path/filepath"
)
const (
DistributorPrefix = "org.unifiedpush.Distributor"
DistributorPath = "/org/unifiedpush/Distributor"
DistributorInterface = "org.unifiedpush.Distributor1"
)
const (
ConnectorPath = "/org/unifiedpush/Connector"
ConnectorInterface = "org.unifiedpush.Connector1"
ConnectorBackgroundArgument = "UNIFIEDPUSH_DBUS_BACKGROUND_ACTIVATION"
)
const (
ConnectorPerm fs.FileMode = 0o600
)
// storagePaths provides a basic cache for StoragePath
var storagePaths = map[string]string{}
// StoragePath appName only recommends using something that can be a filename for now
func StoragePath(appName string) string {
if a, ok := storagePaths[appName]; ok {
return a
}
basedir := os.Getenv("XDG_CONFIG_HOME")
if len(basedir) == 0 {
basedir = os.Getenv("HOME")
if len(basedir) == 0 {
basedir = "./" // FIXME: set to cwd if dunno wth is going on
}
basedir = filepath.Join(basedir, ".config")
}
basedir = filepath.Join(basedir, "unifiedpush", "connectors")
err := os.MkdirAll(basedir, 0o700)
if err != nil {
basedir = "./"
// FIXME idk wth to do when there's an error here
}
finalFilename := filepath.Join(basedir, appName+".json")
storagePaths[appName] = finalFilename
return finalFilename
}
type RegisterStatus int
const (
RegisterStatusNewEndpoint RegisterStatus = iota
RegisterStatusRefused
RegisterStatusFailed
RegisterStatusFailedRequest = 99
)
var RegisterStatusMap = map[string]RegisterStatus{
"REGISTRATION_SUCCEEDED": RegisterStatusNewEndpoint,
"REGISTRATION_REFUSED": RegisterStatusRefused,
"REGISTRATION_FAILED": RegisterStatusFailed,
}