mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
kitten desktop-ui: Do not create an empty *-portals.conf file
In the case where a portals.conf file does not exist in the user configuration, there is nothing to patch; we should default to defining the relevant portals for kitty.
This commit is contained in:
parent
ff1c8ab917
commit
dd7fa6b25a
1 changed files with 13 additions and 1 deletions
|
|
@ -363,6 +363,7 @@ var AllPortalInterfaces = sync.OnceValue(func() (ans []string) {
|
|||
func patch_portals_conf(text []byte) []byte {
|
||||
lines := []string{}
|
||||
in_preferred := false
|
||||
patched := false
|
||||
for _, line := range utils.Splitlines(utils.UnsafeBytesToString(text)) {
|
||||
sl := strings.TrimSpace(line)
|
||||
if strings.HasPrefix(sl, "[") {
|
||||
|
|
@ -371,6 +372,7 @@ func patch_portals_conf(text []byte) []byte {
|
|||
for _, iface := range AllPortalInterfaces() {
|
||||
lines = append(lines, iface+"=kitty")
|
||||
}
|
||||
patched = true
|
||||
} else if in_preferred {
|
||||
remove := false
|
||||
for _, iface := range AllPortalInterfaces() {
|
||||
|
|
@ -384,6 +386,15 @@ func patch_portals_conf(text []byte) []byte {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !patched {
|
||||
// the file was empty or did not contain a section
|
||||
lines = append(lines, "[preferred]")
|
||||
for _, iface := range AllPortalInterfaces() {
|
||||
lines = append(lines, iface+"=kitty")
|
||||
}
|
||||
}
|
||||
|
||||
return utils.UnsafeStringToBytes(strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
|
|
@ -458,6 +469,7 @@ Exec=%s desktop-ui run-server
|
|||
text := patch_portals_conf(text)
|
||||
if err = os.WriteFile(q, text, 0o644); err == nil {
|
||||
patched_file = q
|
||||
fmt.Printf("Patched %s to use the kitty portals\n", patched_file)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -470,8 +482,8 @@ Exec=%s desktop-ui run-server
|
|||
return err
|
||||
}
|
||||
patched_file = q
|
||||
fmt.Printf("Created %s to use the kitty portals\n", patched_file)
|
||||
}
|
||||
fmt.Printf("Patched %s to use the kitty portals\n", patched_file)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue