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 file
.env .env
pi.json pi.xml
pi pi
# Editor/IDE # Editor/IDE
# .idea/ # .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. 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 ```xml
{ <piConfig>
"Login": { <Login>
"Host": "example.com:5222", <Host>example.com:5222</Host>
"User": "user@example.com", <User>user@example.com</User>
"Password": "123456", <Password>123456789</Password>
"DisplayName": "user", <DisplayName>sunglocto</DisplayName>
"NoTLS": false, <TLSoff>false</TLSoff>
"StartTLS": true, <StartTLS>true</StartTLS>
"Mucs": [ <MucsToJoin>room1@muc.example.com</MucsToJoin>
"room1@group.example.com", <MucsToJoin>room2@muc.example.com</MucsToJoin>
"room2@group.example.com" </Login>
] <Notifications>true</Notifications>
}, </piConfig>
"DMs": [
"mike@example.com",
"louis@example.com"
],
"Notifications": false
}
``` ```
Edit this file as necessary. Edit this file as necessary.

28
main.go
View File

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