2024-09-08 02:24:01 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2024-09-17 13:48:42 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal"
|
2024-09-12 21:07:05 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/verbose"
|
2024-09-16 20:32:07 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/xcb"
|
2024-09-08 02:24:01 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const display = "DISPLAY"
|
|
|
|
|
|
|
|
func (a *App) ShareX() {
|
2024-09-17 13:48:42 +09:00
|
|
|
a.setEnablement(internal.EnableX)
|
2024-09-08 02:24:01 +09:00
|
|
|
|
|
|
|
// discovery X11 and grant user permission via the `ChangeHosts` command
|
|
|
|
if d, ok := os.LookupEnv(display); !ok {
|
2024-09-17 13:48:42 +09:00
|
|
|
internal.Fatal("X11: DISPLAY not set")
|
2024-09-08 02:24:01 +09:00
|
|
|
} else {
|
|
|
|
// add environment variable for new process
|
|
|
|
a.AppendEnv(display, d)
|
|
|
|
|
2024-09-12 21:07:05 +09:00
|
|
|
verbose.Printf("X11: Adding XHost entry SI:localuser:%s to display '%s'\n", a.Username, d)
|
2024-09-08 02:24:01 +09:00
|
|
|
if err := xcb.ChangeHosts(xcb.HostModeInsert, xcb.FamilyServerInterpreted, "localuser\x00"+a.Username); err != nil {
|
2024-09-17 13:48:42 +09:00
|
|
|
internal.Fatal(fmt.Sprintf("Error adding XHost entry to '%s':", d), err)
|
2024-09-08 02:24:01 +09:00
|
|
|
} else {
|
2024-09-17 13:48:42 +09:00
|
|
|
a.exit.XcbActionComplete()
|
2024-09-08 02:24:01 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|