1
0
forked from sunglocto/pi-im

Fully remove all JSON support

This commit is contained in:
2025-08-05 17:49:29 +01:00
parent 64d1c420a2
commit e15a6424bb
3 changed files with 34 additions and 32 deletions

2
.gitignore vendored
View File

@@ -26,7 +26,7 @@ go.work.sum
# env file
.env
pi.json
pi.xml
pi
# Editor/IDE
# .idea/

View File

@@ -20,28 +20,22 @@ pi is an extremely opinionated client. It aims to have as little extra windows a
When you launch pi, you will be greeted with a create account screen. You will then be able to enter your XMPP account details and then relaunch the application to log in.
If you want to add MUCs or DMs, you must configure the program. Here is the general idea:
If you want to add MUCs or DMs, you must configure the program by editing the pi.xml file. Here is the general idea:
```json
{
"Login": {
"Host": "example.com:5222",
"User": "user@example.com",
"Password": "123456",
"DisplayName": "user",
"NoTLS": false,
"StartTLS": true,
"Mucs": [
"room1@group.example.com",
"room2@group.example.com"
]
},
"DMs": [
"mike@example.com",
"louis@example.com"
],
"Notifications": false
}
```xml
<piConfig>
<Login>
<Host>example.com:5222</Host>
<User>user@example.com</User>
<Password>123456789</Password>
<DisplayName>sunglocto</DisplayName>
<TLSoff>false</TLSoff>
<StartTLS>true</StartTLS>
<MucsToJoin>room1@muc.example.com</MucsToJoin>
<MucsToJoin>room2@muc.example.com</MucsToJoin>
</Login>
<Notifications>true</Notifications>
</piConfig>
```
Edit this file as necessary.

28
main.go
View File

@@ -1,7 +1,6 @@
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
"image/color"
@@ -21,6 +20,7 @@ import (
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
catppuccin "github.com/mbaklor/fyne-catppuccin"
_ "fyne.io/x/fyne/theme"
"mellium.im/xmpp/jid"
"mellium.im/xmpp/muc"
oasisSdk "pain.agency/oasis-sdk"
@@ -142,14 +142,14 @@ func addChatTab(isMuc bool, chatJid jid.JID, nick string) {
lines := strings.Split(msgContent, "\n")
for i, line := range lines {
if strings.HasPrefix(line, ">") {
lines[i] = "\n" + line + "\n"
lines[i] = fmt.Sprintf("\n %s \n", line)
}
}
msgContent = strings.Join(lines, "\n")
content.ParseMarkdown(msgContent)
if tabData.Messages[i].ReplyID != "PICLIENT:UNAVAILABLE" {
author.SetText(fmt.Sprintf("%s %s", tabData.Messages[i].Author, jid.MustParse(tabData.Messages[i].ReplyID).Resourcepart()))
author.SetText(fmt.Sprintf("%s > %s", tabData.Messages[i].Author, jid.MustParse(tabData.Messages[i].ReplyID).Resourcepart()))
} else {
author.SetText(tabData.Messages[i].Author)
}
@@ -173,7 +173,7 @@ func dropToSignInPage(reason string) {
w = a.NewWindow("Welcome to Pi")
w.Resize(fyne.NewSize(500, 500))
rt := widget.NewRichTextFromMarkdown("# Welcome to pi\nIt appears you do not have a valid account configured. Let's create one!")
footer := widget.NewRichTextFromMarkdown(fmt.Sprintf("Reason for being dropped to the sign-in page:\n\n```%s```", reason))
footer := widget.NewRichTextFromMarkdown(fmt.Sprintf("Reason for being dropped to the sign-in page:\n\n```%s```\n\nDEBUG: %s", reason, fmt.Sprint(os.DirFS("."))))
userEntry := widget.NewEntry()
userEntry.SetPlaceHolder("Your JID")
serverEntry := widget.NewEntry()
@@ -204,14 +204,22 @@ func dropToSignInPage(reason string) {
config.Login.DisplayName = nicknameEntry.Text
config.Notifications = true
bytes, err := json.MarshalIndent(config, "", " ")
bytes, err := xml.MarshalIndent(config, "", " ")
if err != nil {
dialog.ShowError(err, w)
return
}
os.Create("pi.json")
os.WriteFile("pi.json", bytes, os.FileMode(os.O_RDWR)) // TODO: See if this works on non-unix like systems
_, err = os.Create("pi.xml")
if err != nil {
dialog.ShowError(err, w)
return
}
err = os.WriteFile("pi.xml", bytes, os.FileMode(os.O_RDWR)) // TODO: See if this works on non-unix like systems
if err != nil {
dialog.ShowError(err, w)
return
}
a.SendNotification(fyne.NewNotification("Done", "Relaunch the application"))
w.Close()
}
@@ -229,15 +237,15 @@ func main() {
config = piConfig{}
bytes, err := os.ReadFile("./pi.json")
bytes, err := os.ReadFile("./pi.xml")
if err != nil {
dropToSignInPage(err.Error())
return
}
err = json.Unmarshal(bytes, &config)
err = xml.Unmarshal(bytes, &config)
if err != nil {
dropToSignInPage(fmt.Sprintf("Your pi.json file is invalid:\n%s", err.Error()))
dropToSignInPage(fmt.Sprintf("Your pi.xml file is invalid:\n%s", err.Error()))
return
}