From df0ff2035e264c5a7f58b9ae49ab9968f370bb8b Mon Sep 17 00:00:00 2001 From: FIGBERT Date: Tue, 8 Aug 2023 23:57:35 -0700 Subject: [PATCH] Rework headless public message API --- headless/headless.go | 22 +++++++++++----------- headless/msg.go | 42 ++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/headless/headless.go b/headless/headless.go index e5b398f..b618ab7 100644 --- a/headless/headless.go +++ b/headless/headless.go @@ -22,10 +22,10 @@ type Config struct { MxID id.UserID } -func Init(conf Config, updates chan fmt.Stringer) error { +func Init(conf Config, updates chan fmt.Stringer) Completed { // setup package dir os.Setenv("GOMUKS_ROOT", conf.OutputDir) - updates <- ExportDirSetMsg{dir: conf.OutputDir} + updates <- exportDirSet{dir: conf.OutputDir} // init boilerplate configDir, dataDir, cacheDir, downloadDir, err := initDirs() @@ -38,7 +38,7 @@ func Init(conf Config, updates chan fmt.Stringer) error { if err != nil { return err } - updates <- InitializedGomuksMsg{} + updates <- initializedGomuks{} // login section _, hs, err := conf.MxID.Parse() @@ -52,7 +52,7 @@ func Init(conf Config, updates chan fmt.Stringer) error { } else if err = gmx.Matrix().Login(conf.MxID.String(), conf.MxPassword); err != nil { return err } - updates <- LoggedInMsg{account: conf.MxID} + updates <- loggedIn{account: conf.MxID} // key import data, err := os.ReadFile(conf.KeyPath) @@ -64,7 +64,7 @@ func Init(conf Config, updates chan fmt.Stringer) error { if err != nil { return fmt.Errorf("Failed to import sessions: %v", err) } - updates <- ImportedKeysMsg{imported: imported, total: total} + updates <- importedKeys{imported: imported, total: total} // verify (fetch) key, err := getSSSS(mach, conf.RecoveryPhrase) @@ -76,7 +76,7 @@ func Init(conf Config, updates chan fmt.Stringer) error { if err != nil { return fmt.Errorf("Error fetching cross-signing keys: %v", err) } - updates <- FetchedVerificationKeysMsg{} + updates <- fetchedVerificationKeys{} // verify (sign) if mach.CrossSigningKeys == nil { @@ -87,14 +87,14 @@ func Init(conf Config, updates chan fmt.Stringer) error { if err != nil { return fmt.Errorf("Failed to self-sign: %v", err) } - updates <- SuccessfullyVerifiedMsg{} + updates <- successfullyVerified{} // display mode gmx.Config().Preferences.DisplayMode = config.DisplayModeModern - updates <- ConfiguredDisplayModeMsg{} + updates <- configuredDisplayMode{} // sync - updates <- BeginningSyncMsg{} + updates <- beginningSync{} resp, err := gmx.Matrix().Client().FullSyncRequest(mautrix.ReqSync{ Timeout: 30000, Since: "", @@ -107,10 +107,10 @@ func Init(conf Config, updates chan fmt.Stringer) error { if err != nil { return err } - updates <- FetchedSyncDataMsg{} + updates <- fetchedSyncData{} gmx.Matrix().(*matrix.Container).InitSyncer() - updates <- ProcessingSyncMsg{} + updates <- processingSync{} err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "") return err diff --git a/headless/msg.go b/headless/msg.go index 23bde4d..5e749ce 100644 --- a/headless/msg.go +++ b/headless/msg.go @@ -2,62 +2,64 @@ package headless import "fmt" -type ExportDirSetMsg struct{ dir string } +type exportDirSet struct{ dir string } -func (msg ExportDirSetMsg) String() string { +func (msg exportDirSet) String() string { return fmt.Sprintf("Set gomuks root directory to %s…", msg.dir) } -type InitializedGomuksMsg struct{} +type initializedGomuks struct{} -func (msg InitializedGomuksMsg) String() string { +func (msg initializedGomuks) String() string { return "Initialized gomuks…" } -type LoggedInMsg struct{ account fmt.Stringer } +type loggedIn struct{ account fmt.Stringer } -func (msg LoggedInMsg) String() string { +func (msg loggedIn) String() string { return fmt.Sprintf("Logged in to %s…", msg.account) } -type ImportedKeysMsg struct{ imported, total int } +type importedKeys struct{ imported, total int } -func (msg ImportedKeysMsg) String() string { +func (msg importedKeys) String() string { return fmt.Sprintf("Successfully imported %d/%d sessions", msg.imported, msg.total) } -type FetchedVerificationKeysMsg struct{} +type fetchedVerificationKeys struct{} -func (msg FetchedVerificationKeysMsg) String() string { +func (msg fetchedVerificationKeys) String() string { return "Successfully unlocked cross-signing keys…" } -type SuccessfullyVerifiedMsg struct{} +type successfullyVerified struct{} -func (msg SuccessfullyVerifiedMsg) String() string { +func (msg successfullyVerified) String() string { return "Successfully self-signed. This device is now trusted by other devices…" } -type ConfiguredDisplayModeMsg struct{} +type configuredDisplayMode struct{} -func (msg ConfiguredDisplayModeMsg) String() string { +func (msg configuredDisplayMode) String() string { return "Configured display mode…" } -type BeginningSyncMsg struct{} +type beginningSync struct{} -func (msg BeginningSyncMsg) String() string { +func (msg beginningSync) String() string { return "Beginning the sync process…" } -type FetchedSyncDataMsg struct{} +type fetchedSyncData struct{} -func (msg FetchedSyncDataMsg) String() string { +func (msg fetchedSyncData) String() string { return "Fetched sync data…" } -type ProcessingSyncMsg struct{} +type processingSync struct{} -func (msg ProcessingSyncMsg) String() string { +func (msg processingSync) String() string { return "Processing sync response…" } + +type Completed error