diff --git a/kittens/desktop_ui/portal.go b/kittens/desktop_ui/portal.go index c9366627c..d8b16d42b 100644 --- a/kittens/desktop_ui/portal.go +++ b/kittens/desktop_ui/portal.go @@ -313,12 +313,24 @@ func show_settings(opts *ShowSettingsOptions) (err error) { } var DataDirs = sync.OnceValue(func() (ans []string) { - d := os.Getenv("XDG_DATA_DIRS") - if d == "" { - d = "/usr/local/share/:/usr/share/" + // $XDG_DATA_DIRS defines the preference-ordered set of base directories + // to search for data files **in addition to the $XDG_DATA_HOME** base + // directory. The directories in $XDG_DATA_DIRS should be separated with + // a colon ':'. + // https://specifications.freedesktop.org/basedir-spec/0.8/#variables + + data_dirs := os.Getenv("XDG_DATA_DIRS") + if data_dirs == "" { + data_dirs = "/usr/local/share/:/usr/share/" } - all := []string{os.Getenv("XDG_DATA_HOME")} - all = append(all, strings.Split(d, ":")...) + + data_home := os.Getenv("XDG_DATA_HOME") + if data_home == "" { + data_home = os.Getenv("HOME") + "/.local/share" + } + + all := []string{data_home} + all = append(all, strings.Split(data_dirs, ":")...) seen := map[string]bool{} for _, x := range all { if !seen[x] { @@ -381,21 +393,13 @@ func enable_portal() (err error) { } portals_dir := "" for _, x := range WritableDataDirs() { + // Find-or-create the first available xdg-desktop-portals/portals directory q := filepath.Join(x, "xdg-desktop-portal", "portals") - if unix.Access(q, unix.W_OK) == nil && IsDir(q) { + if (unix.Access(q, unix.W_OK) == nil && IsDir(q)) || (os.MkdirAll(q, 0o755) == nil) { portals_dir = q break } } - if portals_dir == "" { - for _, x := range WritableDataDirs() { - q := filepath.Join(x, "xdg-desktop-portal", "portals") - if err := os.MkdirAll(q, 0o755); err == nil { - portals_dir = q - break - } - } - } if portals_dir == "" { return fmt.Errorf("Could not find any writable portals directories. Make sure XDG_DATA_HOME is set and point to a directory for which you have write permission.") }