summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-20 19:27:22 +0200
committerxengineering <me@xengineering.eu>2023-05-20 19:27:22 +0200
commit1a920930fe71e569eee124259b43db8e43af3c76 (patch)
treeac80fab1011e3740617396ab73edce5dd084902a
parent6713c3cc833906802acf3ef89e5ac3dd7f69e128 (diff)
downloadlimox-1a920930fe71e569eee124259b43db8e43af3c76.tar
limox-1a920930fe71e569eee124259b43db8e43af3c76.tar.zst
limox-1a920930fe71e569eee124259b43db8e43af3c76.zip
Implement last password persistence
-rw-r--r--limox.go5
-rw-r--r--persistence.go34
2 files changed, 38 insertions, 1 deletions
diff --git a/limox.go b/limox.go
index 0e8c056..620f009 100644
--- a/limox.go
+++ b/limox.go
@@ -46,6 +46,7 @@ func NewLimox() Limox {
}
l.JidEditor.SetText(getLastJid())
+ l.PwdEditor.SetText(getLastPwd())
return l
}
@@ -82,8 +83,10 @@ func (l *Limox) buttonCallback() {
case Disconnected:
log.Println("Starting connection establishment ...")
jid := l.JidEditor.Text()
+ pwd := l.PwdEditor.Text()
setLastJid(jid)
- go xmpp.Run(l.XmppConn, jid, l.PwdEditor.Text())
+ setLastPwd(pwd)
+ go xmpp.Run(l.XmppConn, jid, pwd)
l.State = Connecting
case Connecting:
log.Println("Aborted connection establishment")
diff --git a/persistence.go b/persistence.go
index 5199fc5..bc6eee4 100644
--- a/persistence.go
+++ b/persistence.go
@@ -6,9 +6,16 @@ import (
"path/filepath"
)
+type persistentString uint8
+
+const (
+ Jid persistentString = iota
+)
+
const (
RelDataPath = `/.config/limox`
RelJidPath = `/last_jid.txt`
+ RelPwdPath = `/last_pwd.txt`
)
func setLastJid(j string) {
@@ -38,6 +45,33 @@ func getLastJid() string {
return string(content)
}
+func setLastPwd(p string) {
+ data, err := assertDatadir()
+ if err != nil {
+ return
+ }
+
+ path := filepath.Join(data, RelPwdPath)
+
+ _ = ioutil.WriteFile(path, []byte(p), 0600)
+}
+
+func getLastPwd() string {
+ data, err := assertDatadir()
+ if err != nil {
+ return ""
+ }
+
+ path := filepath.Join(data, RelPwdPath)
+
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ return ""
+ }
+
+ return string(content)
+}
+
func assertDatadir() (string, error) {
home, err := os.UserHomeDir()
if err != nil {