about summary refs log tree commit diff
path: root/nixpkgs/pkgs/desktops/deepin/go-package/dde-daemon/0003-search-in-XDG-directories.patch
blob: c0a8a02558c54948f45c97e75a10cbab3aa8a378 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
From a0667a7e82b3176e64122f4d68c43de4fa350780 Mon Sep 17 00:00:00 2001
From: rewine <luhongxu@deepin.org>
Date: Tue, 18 Apr 2023 17:04:36 +0800
Subject: [PATCH 3/4] search-in-XDG-directories

---
 accounts/manager.go                     |  5 ++++-
 accounts/user.go                        |  8 +++++++-
 appearance/fsnotify.go                  | 21 +++++++++++++++++----
 appearance/ifc.go                       |  3 ++-
 apps/utils.go                           |  3 ++-
 gesture/config.go                       |  4 ++--
 keybinding/shortcuts/system_shortcut.go |  4 +++-
 mime/app_info.go                        |  7 ++++++-
 system/gesture/config.go                |  4 +++-
 9 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/accounts/manager.go b/accounts/manager.go
index 22c26ce7..009d9dd9 100644
--- a/accounts/manager.go
+++ b/accounts/manager.go
@@ -15,6 +15,7 @@ import (
 	"sync"
 	"syscall"
 
+	"github.com/adrg/xdg"
 	dbus "github.com/godbus/dbus"
 	"github.com/linuxdeepin/dde-daemon/accounts/users"
 	"github.com/linuxdeepin/dde-daemon/common/sessionmsg"
@@ -35,8 +36,10 @@ const (
 	actConfigFile       = actConfigDir + "/accounts.ini"
 	actConfigGroupGroup = "Accounts"
 	actConfigKeyGuest   = "AllowGuest"
+)
 
-	interfacesFile = "/usr/share/dde-daemon/accounts/dbus-udcp.json"
+var (
+	interfacesFile, _ = xdg.SearchDataFile("dde-daemon/accounts/dbus-udcp.json")
 )
 
 type InterfaceConfig struct {
diff --git a/accounts/user.go b/accounts/user.go
index 900033c6..f8827fb2 100644
--- a/accounts/user.go
+++ b/accounts/user.go
@@ -15,6 +15,7 @@ import (
 	"strings"
 	"sync"
 
+	"github.com/adrg/xdg"
 	dbus "github.com/godbus/dbus"
 	"github.com/linuxdeepin/dde-daemon/accounts/users"
 	authenticate "github.com/linuxdeepin/go-dbus-factory/com.deepin.daemon.authenticate"
@@ -649,7 +650,12 @@ func getUserSession(homeDir string) string {
 }
 
 func getSessionList() []string {
-	fileInfoList, err := ioutil.ReadDir("/usr/share/xsessions")
+	xsessionPath, err := xdg.SearchDataFile("xsessions")
+	if err != nil {
+		return nil;
+	}
+
+	fileInfoList, err := ioutil.ReadDir(xsessionPath)
 	if err != nil {
 		return nil
 	}
diff --git a/appearance/fsnotify.go b/appearance/fsnotify.go
index a409d0ba..ff674600 100644
--- a/appearance/fsnotify.go
+++ b/appearance/fsnotify.go
@@ -5,12 +5,15 @@
 package appearance
 
 import (
+	"errors"
+	"io/fs"
 	"os"
 	"path"
 	"path/filepath"
 	"strings"
 	"time"
 
+	"github.com/adrg/xdg"
 	"github.com/fsnotify/fsnotify"
 	"github.com/linuxdeepin/dde-daemon/appearance/background"
 	"github.com/linuxdeepin/dde-daemon/appearance/subthemes"
@@ -100,9 +103,14 @@ func (m *Manager) watchGtkDirs() {
 	gtkDirs = []string{
 		path.Join(home, ".local/share/themes"),
 		path.Join(home, ".themes"),
-		"/usr/local/share/themes",
-		"/usr/share/themes",
 	}
+	for _, dataPath := range xdg.DataDirs {
+                gtkPath := filepath.Join(dataPath, "themes");
+                if _, err := os.Stat(gtkPath); err != nil && errors.Is(err, fs.ErrNotExist) {
+                        continue
+                }
+                gtkDirs = append(gtkDirs, gtkPath);
+        }
 
 	m.watchDirs(gtkDirs)
 }
@@ -112,9 +120,14 @@ func (m *Manager) watchIconDirs() {
 	iconDirs = []string{
 		path.Join(home, ".local/share/icons"),
 		path.Join(home, ".icons"),
-		"/usr/local/share/icons",
-		"/usr/share/icons",
 	}
+	for _, dataPath := range xdg.DataDirs {
+                iconPath := filepath.Join(dataPath, "icons");
+                if _, err := os.Stat(iconPath); err != nil && errors.Is(err, fs.ErrNotExist) {
+                        continue
+                }
+                iconDirs = append(iconDirs, iconPath);
+        }
 
 	m.watchDirs(iconDirs)
 }
diff --git a/appearance/ifc.go b/appearance/ifc.go
index f0bf32a3..6d60ffe4 100644
--- a/appearance/ifc.go
+++ b/appearance/ifc.go
@@ -10,6 +10,7 @@ import (
 	"strconv"
 	"strings"
 
+	"github.com/adrg/xdg"
 	"github.com/godbus/dbus"
 	"github.com/linuxdeepin/dde-daemon/appearance/fonts"
 	"github.com/linuxdeepin/dde-daemon/appearance/subthemes"
@@ -265,7 +266,7 @@ func (m *Manager) thumbnail(ty, name string) (string, error) {
 	case TypeGtkTheme:
 		fName, ok := gtkThumbnailMap[name]
 		if ok {
-			return filepath.Join("/usr/share/dde-daemon/appearance", fName+".svg"), nil
+			return xdg.SearchDataFile(filepath.Join("dde-daemon/appearance", fName+".svg"))
 		}
 		return subthemes.GetGtkThumbnail(name)
 	case TypeIconTheme:
diff --git a/apps/utils.go b/apps/utils.go
index 8863d6c2..dd6f8e16 100644
--- a/apps/utils.go
+++ b/apps/utils.go
@@ -11,6 +11,7 @@ import (
 	"strconv"
 	"strings"
 	"syscall"
+	"github.com/adrg/xdg"
 )
 
 func intSliceContains(slice []int, a int) bool {
@@ -96,7 +97,7 @@ func removeDesktopExt(name string) string {
 }
 
 func getSystemDataDirs() []string {
-	return []string{"/usr/share", "/usr/local/share"}
+	return xdg.DataDirs
 }
 
 // get user home
diff --git a/gesture/config.go b/gesture/config.go
index bfbd4db7..4ce9d641 100644
--- a/gesture/config.go
+++ b/gesture/config.go
@@ -10,6 +10,7 @@ import (
 	"io/ioutil"
 	"path/filepath"
 
+	"github.com/adrg/xdg"
 	"github.com/linuxdeepin/go-lib/xdg/basedir"
 )
 
@@ -21,11 +22,10 @@ const (
 
 var (
 	configUserPath = filepath.Join(basedir.GetUserConfigDir(), "deepin/dde-daemon/gesture.json")
+	configSystemPath, _ = xdg.SearchDataFile("dde-daemon/gesture.json")
 )
 
 const (
-	configSystemPath = "/usr/share/dde-daemon/gesture.json"
-
 	gestureSchemaId         = "com.deepin.dde.gesture"
 	gsKeyTouchPadEnabled    = "touch-pad-enabled"
 	gsKeyTouchScreenEnabled = "touch-screen-enabled"
diff --git a/keybinding/shortcuts/system_shortcut.go b/keybinding/shortcuts/system_shortcut.go
index eaec22b5..95e1b222 100644
--- a/keybinding/shortcuts/system_shortcut.go
+++ b/keybinding/shortcuts/system_shortcut.go
@@ -10,6 +10,7 @@ import (
 	"path"
 	"sync"
 
+	"github.com/adrg/xdg"
 	dutils "github.com/linuxdeepin/go-lib/utils"
 )
 
@@ -152,5 +153,6 @@ func getSystemActionsFile() string {
 		return file
 	}
 
-	return ""
+	filepath, _ := xdg.SearchDataFile(systemActionsFile)
+	return filepath;
 }
diff --git a/mime/app_info.go b/mime/app_info.go
index 63fcdcc0..18436164 100644
--- a/mime/app_info.go
+++ b/mime/app_info.go
@@ -9,6 +9,7 @@ import (
 	"os"
 	"path"
 
+	"github.com/adrg/xdg"
 	"github.com/linuxdeepin/go-lib/appinfo/desktopappinfo"
 	"github.com/linuxdeepin/go-lib/mime"
 	dutils "github.com/linuxdeepin/go-lib/utils"
@@ -162,5 +163,9 @@ func findFilePath(file string) string {
 		return data
 	}
 
-	return path.Join("/usr/share", file)
+	filepath, err := xdg.SearchDataFile(file)
+	if err != nil {
+		return path.Join("/usr/share", file)
+	}
+	return filepath;
 }
diff --git a/system/gesture/config.go b/system/gesture/config.go
index d4aebaac..f3fc92c3 100644
--- a/system/gesture/config.go
+++ b/system/gesture/config.go
@@ -8,6 +8,7 @@ import (
 	"encoding/json"
 	"io/ioutil"
 
+	"github.com/adrg/xdg"
 	"github.com/linuxdeepin/go-lib/utils"
 )
 
@@ -35,5 +36,6 @@ func getConfigPath() string {
 	if utils.IsFileExist(filename) {
 		return filename
 	}
-	return "/usr/share/" + suffix
+	filepath, _ := xdg.SearchDataFile(suffix)
+	return filepath;
 }
-- 
2.38.1