From 8bdae74ebe172239573bab9fca634cf350cbd29d Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Mon, 16 Sep 2024 20:31:15 +0900 Subject: final: refactor for removal of system package and reduction of interactions to state package State query command has been moved to main where it belongs, "system" information are now fetched in app.New and stored in *App with accessors for relevant values. Exit (cleanup-related) functions are separated into its dedicated "final" package. Signed-off-by: Ophestra Umiker --- internal/app/pulse.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'internal/app/pulse.go') diff --git a/internal/app/pulse.go b/internal/app/pulse.go index d7e08ba9..4b67ff2e 100644 --- a/internal/app/pulse.go +++ b/internal/app/pulse.go @@ -3,13 +3,13 @@ package app import ( "errors" "fmt" + "git.ophivana.moe/cat/fortify/internal/final" "io/fs" "os" "path" "git.ophivana.moe/cat/fortify/internal/acl" "git.ophivana.moe/cat/fortify/internal/state" - "git.ophivana.moe/cat/fortify/internal/system" "git.ophivana.moe/cat/fortify/internal/util" "git.ophivana.moe/cat/fortify/internal/verbose" ) @@ -18,46 +18,46 @@ func (a *App) SharePulse() { a.setEnablement(state.EnablePulse) // ensure PulseAudio directory ACL (e.g. `/run/user/%d/pulse`) - pulse := path.Join(system.V.Runtime, "pulse") + pulse := path.Join(a.runtimePath, "pulse") pulseS := path.Join(pulse, "native") if s, err := os.Stat(pulse); err != nil { if !errors.Is(err, fs.ErrNotExist) { - state.Fatal("Error accessing PulseAudio directory:", err) + final.Fatal("Error accessing PulseAudio directory:", err) } - state.Fatal(fmt.Sprintf("PulseAudio dir '%s' not found", pulse)) + final.Fatal(fmt.Sprintf("PulseAudio dir '%s' not found", pulse)) } else { // add environment variable for new process a.AppendEnv(util.PulseServer, "unix:"+pulseS) if err = acl.UpdatePerm(pulse, a.UID(), acl.Execute); err != nil { - state.Fatal("Error preparing PulseAudio:", err) + final.Fatal("Error preparing PulseAudio:", err) } else { - state.RegisterRevertPath(pulse) + final.RegisterRevertPath(pulse) } // ensure PulseAudio socket permission (e.g. `/run/user/%d/pulse/native`) if s, err = os.Stat(pulseS); err != nil { if errors.Is(err, fs.ErrNotExist) { - state.Fatal("PulseAudio directory found but socket does not exist") + final.Fatal("PulseAudio directory found but socket does not exist") } - state.Fatal("Error accessing PulseAudio socket:", err) + final.Fatal("Error accessing PulseAudio socket:", err) } else { if m := s.Mode(); m&0o006 != 0o006 { - state.Fatal(fmt.Sprintf("Unexpected permissions on '%s':", pulseS), m) + final.Fatal(fmt.Sprintf("Unexpected permissions on '%s':", pulseS), m) } } // Publish current user's pulse-cookie for target user pulseCookieSource := util.DiscoverPulseCookie() - pulseCookieFinal := path.Join(system.V.Share, "pulse-cookie") + pulseCookieFinal := path.Join(a.sharePath, "pulse-cookie") a.AppendEnv(util.PulseCookie, pulseCookieFinal) verbose.Printf("Publishing PulseAudio cookie '%s' to '%s'\n", pulseCookieSource, pulseCookieFinal) if err = util.CopyFile(pulseCookieFinal, pulseCookieSource); err != nil { - state.Fatal("Error copying PulseAudio cookie:", err) + final.Fatal("Error copying PulseAudio cookie:", err) } if err = acl.UpdatePerm(pulseCookieFinal, a.UID(), acl.Read); err != nil { - state.Fatal("Error publishing PulseAudio cookie:", err) + final.Fatal("Error publishing PulseAudio cookie:", err) } else { - state.RegisterRevertPath(pulseCookieFinal) + final.RegisterRevertPath(pulseCookieFinal) } verbose.Printf("PulseAudio dir '%s' configured\n", pulse) -- cgit v1.3.1