mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 16:58:09 +02: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:
@@ -363,6 +363,7 @@ var AllPortalInterfaces = sync.OnceValue(func() (ans []string) {
|
|||||||
func patch_portals_conf(text []byte) []byte {
|
func patch_portals_conf(text []byte) []byte {
|
||||||
lines := []string{}
|
lines := []string{}
|
||||||
in_preferred := false
|
in_preferred := false
|
||||||
|
patched := false
|
||||||
for _, line := range utils.Splitlines(utils.UnsafeBytesToString(text)) {
|
for _, line := range utils.Splitlines(utils.UnsafeBytesToString(text)) {
|
||||||
sl := strings.TrimSpace(line)
|
sl := strings.TrimSpace(line)
|
||||||
if strings.HasPrefix(sl, "[") {
|
if strings.HasPrefix(sl, "[") {
|
||||||
@@ -371,6 +372,7 @@ func patch_portals_conf(text []byte) []byte {
|
|||||||
for _, iface := range AllPortalInterfaces() {
|
for _, iface := range AllPortalInterfaces() {
|
||||||
lines = append(lines, iface+"=kitty")
|
lines = append(lines, iface+"=kitty")
|
||||||
}
|
}
|
||||||
|
patched = true
|
||||||
} else if in_preferred {
|
} else if in_preferred {
|
||||||
remove := false
|
remove := false
|
||||||
for _, iface := range AllPortalInterfaces() {
|
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"))
|
return utils.UnsafeStringToBytes(strings.Join(lines, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,6 +469,7 @@ Exec=%s desktop-ui run-server
|
|||||||
text := patch_portals_conf(text)
|
text := patch_portals_conf(text)
|
||||||
if err = os.WriteFile(q, text, 0o644); err == nil {
|
if err = os.WriteFile(q, text, 0o644); err == nil {
|
||||||
patched_file = q
|
patched_file = q
|
||||||
|
fmt.Printf("Patched %s to use the kitty portals\n", patched_file)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,8 +482,8 @@ Exec=%s desktop-ui run-server
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
patched_file = q
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user