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