forked from Mirrors/gomuks
Add update channel to headless initialization
This commit is contained in:
parent
7d139c50d6
commit
ab18e4c28d
2 changed files with 76 additions and 14 deletions
|
@ -11,10 +11,10 @@ import (
|
||||||
"maunium.net/go/mautrix/crypto/ssss"
|
"maunium.net/go/mautrix/crypto/ssss"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
|
"maunium.net/go/gomuks/config"
|
||||||
"maunium.net/go/gomuks/initialize"
|
"maunium.net/go/gomuks/initialize"
|
||||||
"maunium.net/go/gomuks/matrix"
|
"maunium.net/go/gomuks/matrix"
|
||||||
"maunium.net/go/gomuks/ui"
|
"maunium.net/go/gomuks/ui"
|
||||||
"maunium.net/go/gomuks/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HeadlessConfig struct {
|
type HeadlessConfig struct {
|
||||||
|
@ -22,9 +22,10 @@ type HeadlessConfig struct {
|
||||||
MxID id.UserID
|
MxID id.UserID
|
||||||
}
|
}
|
||||||
|
|
||||||
func HeadlessInit(conf HeadlessConfig) error {
|
func HeadlessInit(conf HeadlessConfig, updates chan fmt.Stringer) error {
|
||||||
// setup package dir
|
// setup package dir
|
||||||
os.Setenv("GOMUKS_ROOT", conf.OutputDir)
|
os.Setenv("GOMUKS_ROOT", conf.OutputDir)
|
||||||
|
updates <- ExportDirSetMsg{dir: conf.OutputDir}
|
||||||
|
|
||||||
// init boilerplate
|
// init boilerplate
|
||||||
configDir, dataDir, cacheDir, downloadDir, err := initDirs()
|
configDir, dataDir, cacheDir, downloadDir, err := initDirs()
|
||||||
|
@ -37,6 +38,7 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
updates <- InitializedGomuksMsg{}
|
||||||
|
|
||||||
// login section
|
// login section
|
||||||
_, hs, err := conf.MxID.Parse()
|
_, hs, err := conf.MxID.Parse()
|
||||||
|
@ -50,6 +52,7 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
} else if err = gmx.Matrix().Login(conf.MxID.String(), conf.MxPassword); err != nil {
|
} else if err = gmx.Matrix().Login(conf.MxID.String(), conf.MxPassword); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
updates <- LoggedInMsg{account: conf.MxID}
|
||||||
|
|
||||||
// key import
|
// key import
|
||||||
data, err := os.ReadFile(conf.KeyPath)
|
data, err := os.ReadFile(conf.KeyPath)
|
||||||
|
@ -57,10 +60,11 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mach := gmx.Matrix().Crypto().(*crypto.OlmMachine)
|
mach := gmx.Matrix().Crypto().(*crypto.OlmMachine)
|
||||||
_, _, err = mach.ImportKeys(conf.KeyPassword, data)
|
imported, total, err := mach.ImportKeys(conf.KeyPassword, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to import sessions: %v", err)
|
return fmt.Errorf("Failed to import sessions: %v", err)
|
||||||
}
|
}
|
||||||
|
updates <- ImportedKeysMsg{imported: imported, total: total}
|
||||||
|
|
||||||
// verify (fetch)
|
// verify (fetch)
|
||||||
key, err := getSSSS(mach, conf.RecoveryPhrase)
|
key, err := getSSSS(mach, conf.RecoveryPhrase)
|
||||||
|
@ -72,6 +76,7 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error fetching cross-signing keys: %v", err)
|
return fmt.Errorf("Error fetching cross-signing keys: %v", err)
|
||||||
}
|
}
|
||||||
|
updates <- FetchedVerificationKeysMsg{}
|
||||||
|
|
||||||
// verify (sign)
|
// verify (sign)
|
||||||
if mach.CrossSigningKeys == nil {
|
if mach.CrossSigningKeys == nil {
|
||||||
|
@ -82,22 +87,14 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to self-sign: %v", err)
|
return fmt.Errorf("Failed to self-sign: %v", err)
|
||||||
}
|
}
|
||||||
|
updates <- SuccessfullyVerifiedMsg{}
|
||||||
|
|
||||||
// display mode
|
// display mode
|
||||||
gmx.Config().Preferences.DisplayMode = config.DisplayModeModern
|
gmx.Config().Preferences.DisplayMode = config.DisplayModeModern
|
||||||
|
updates <- ConfiguredDisplayModeMsg{}
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
// how?
|
updates <- BeginningSyncMsg{}
|
||||||
// this does too much: gmx.Matrix().Start()
|
|
||||||
//
|
|
||||||
// figbert:
|
|
||||||
// just looking to perform the initial sync. is gmx.Matrix().Client().Sync()
|
|
||||||
// the way to go? should i copy+paste the synce initialization from Start()
|
|
||||||
// and OnLogin()?
|
|
||||||
//
|
|
||||||
// tulir:
|
|
||||||
// not sure if there's any easy way to run a single sync, maybe calling
|
|
||||||
// Client.FullSyncRequest + Syncer.ProcessSync manually
|
|
||||||
resp, err := gmx.Matrix().Client().FullSyncRequest(mautrix.ReqSync{
|
resp, err := gmx.Matrix().Client().FullSyncRequest(mautrix.ReqSync{
|
||||||
Timeout: 30000,
|
Timeout: 30000,
|
||||||
Since: "",
|
Since: "",
|
||||||
|
@ -110,8 +107,10 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
updates <- FetchedSyncDataMsg{}
|
||||||
|
|
||||||
gmx.Matrix().(*matrix.Container).InitSyncer()
|
gmx.Matrix().(*matrix.Container).InitSyncer()
|
||||||
|
updates <- ProcessingSyncMsg{}
|
||||||
err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "")
|
err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "")
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
63
headless/msg.go
Normal file
63
headless/msg.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
package headless
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type ExportDirSetMsg struct{ dir string }
|
||||||
|
|
||||||
|
func (msg ExportDirSetMsg) String() string {
|
||||||
|
return fmt.Sprintf("Set gomuks root directory to %s…", msg.dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
type InitializedGomuksMsg struct{}
|
||||||
|
|
||||||
|
func (msg InitializedGomuksMsg) String() string {
|
||||||
|
return "Initialized gomuks…"
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoggedInMsg struct{ account fmt.Stringer }
|
||||||
|
|
||||||
|
func (msg LoggedInMsg) String() string {
|
||||||
|
return fmt.Sprintf("Logged in to %s…", msg.account)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImportedKeysMsg struct{ imported, total int }
|
||||||
|
|
||||||
|
func (msg ImportedKeysMsg) String() string {
|
||||||
|
return fmt.Sprintf("Successfully imported %d/%d sessions", msg.imported, msg.total)
|
||||||
|
}
|
||||||
|
|
||||||
|
type FetchedVerificationKeysMsg struct{}
|
||||||
|
|
||||||
|
func (msg FetchedVerificationKeysMsg) String() string {
|
||||||
|
return "Successfully unlocked cross-signing keys…"
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuccessfullyVerifiedMsg struct{}
|
||||||
|
|
||||||
|
func (msg SuccessfullyVerifiedMsg) String() string {
|
||||||
|
return "Successfully self-signed. This device is now trusted by other devices…"
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConfiguredDisplayModeMsg struct{}
|
||||||
|
|
||||||
|
func (msg ConfiguredDisplayModeMsg) String() string {
|
||||||
|
return "Configured display mode…"
|
||||||
|
}
|
||||||
|
|
||||||
|
type BeginningSyncMsg struct{}
|
||||||
|
|
||||||
|
func (msg BeginningSyncMsg) String() string {
|
||||||
|
return "Beginning the sync process…"
|
||||||
|
}
|
||||||
|
|
||||||
|
type FetchedSyncDataMsg struct{}
|
||||||
|
|
||||||
|
func (msg FetchedSyncDataMsg) String() string {
|
||||||
|
return "Fetched sync data…"
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProcessingSyncMsg struct{}
|
||||||
|
|
||||||
|
func (msg ProcessingSyncMsg) String() string {
|
||||||
|
return "Processing sync response…"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue