Format code
This commit is contained in:
115
main.go
115
main.go
@@ -169,59 +169,59 @@ func addChatTab(isMuc bool, chatJid jid.JID, nick string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dropToSignInPage(reason string) {
|
func dropToSignInPage(reason string) {
|
||||||
a = app.New()
|
a = app.New()
|
||||||
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```", reason))
|
||||||
userEntry := widget.NewEntry()
|
userEntry := widget.NewEntry()
|
||||||
userEntry.SetPlaceHolder("Your JID")
|
userEntry.SetPlaceHolder("Your JID")
|
||||||
serverEntry := widget.NewEntry()
|
serverEntry := widget.NewEntry()
|
||||||
serverEntry.SetPlaceHolder("Server and port")
|
serverEntry.SetPlaceHolder("Server and port")
|
||||||
passwordEntry := widget.NewPasswordEntry()
|
passwordEntry := widget.NewPasswordEntry()
|
||||||
passwordEntry.SetPlaceHolder("Your Password")
|
passwordEntry.SetPlaceHolder("Your Password")
|
||||||
nicknameEntry := widget.NewEntry()
|
nicknameEntry := widget.NewEntry()
|
||||||
nicknameEntry.SetPlaceHolder("Your Nickname")
|
nicknameEntry.SetPlaceHolder("Your Nickname")
|
||||||
|
|
||||||
userView := widget.NewFormItem("", userEntry)
|
userView := widget.NewFormItem("", userEntry)
|
||||||
serverView := widget.NewFormItem("", serverEntry)
|
serverView := widget.NewFormItem("", serverEntry)
|
||||||
passwordView := widget.NewFormItem("", passwordEntry)
|
passwordView := widget.NewFormItem("", passwordEntry)
|
||||||
nicknameView := widget.NewFormItem("", nicknameEntry)
|
nicknameView := widget.NewFormItem("", nicknameEntry)
|
||||||
items := []*widget.FormItem{
|
items := []*widget.FormItem{
|
||||||
serverView,
|
serverView,
|
||||||
userView,
|
userView,
|
||||||
passwordView,
|
passwordView,
|
||||||
nicknameView,
|
nicknameView,
|
||||||
}
|
}
|
||||||
|
|
||||||
btn := widget.NewButton("Create an account", func() {
|
btn := widget.NewButton("Create an account", func() {
|
||||||
dialog.ShowForm("Create an account", "Create", "Dismiss", items, func(b bool) {
|
dialog.ShowForm("Create an account", "Create", "Dismiss", items, func(b bool) {
|
||||||
if b {
|
if b {
|
||||||
config := piConfig{}
|
config := piConfig{}
|
||||||
config.Login.Host = serverEntry.Text
|
config.Login.Host = serverEntry.Text
|
||||||
config.Login.User = userEntry.Text
|
config.Login.User = userEntry.Text
|
||||||
config.Login.Password = passwordEntry.Text
|
config.Login.Password = passwordEntry.Text
|
||||||
config.Login.DisplayName = nicknameEntry.Text
|
config.Login.DisplayName = nicknameEntry.Text
|
||||||
config.Notifications = true
|
config.Notifications = true
|
||||||
|
|
||||||
bytes, err := json.MarshalIndent(config, "", " ")
|
bytes, err := json.MarshalIndent(config, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dialog.ShowError(err, w)
|
dialog.ShowError(err, w)
|
||||||
return
|
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
|
|
||||||
a.SendNotification(fyne.NewNotification("Done", "Relaunch the application"))
|
|
||||||
w.Close()
|
|
||||||
}
|
}
|
||||||
}, w)
|
|
||||||
})
|
os.Create("pi.json")
|
||||||
btn2 := widget.NewButton("Close pi", func() {
|
os.WriteFile("pi.json", bytes, os.FileMode(os.O_RDWR)) // TODO: See if this works on non-unix like systems
|
||||||
w.Close()
|
a.SendNotification(fyne.NewNotification("Done", "Relaunch the application"))
|
||||||
})
|
w.Close()
|
||||||
w.SetContent(container.NewVBox(rt, btn, btn2,footer))
|
}
|
||||||
w.ShowAndRun()
|
}, w)
|
||||||
|
})
|
||||||
|
btn2 := widget.NewButton("Close pi", func() {
|
||||||
|
w.Close()
|
||||||
|
})
|
||||||
|
w.SetContent(container.NewVBox(rt, btn, btn2, footer))
|
||||||
|
w.ShowAndRun()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +235,8 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err = json.Unmarshal(bytes, &config)
|
err = json.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.json file is invalid:\n%s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -335,11 +334,11 @@ func main() {
|
|||||||
replyID = msg.Reply.To
|
replyID = msg.Reply.To
|
||||||
}
|
}
|
||||||
myMessage := Message{
|
myMessage := Message{
|
||||||
Author: msg.From.Resourcepart(),
|
Author: msg.From.Resourcepart(),
|
||||||
Content: str,
|
Content: str,
|
||||||
ID: msg.ID,
|
ID: msg.ID,
|
||||||
ReplyID: replyID,
|
ReplyID: replyID,
|
||||||
Raw: *msg,
|
Raw: *msg,
|
||||||
ImageURL: ImageID,
|
ImageURL: ImageID,
|
||||||
}
|
}
|
||||||
tab.Messages = append(tab.Messages, myMessage)
|
tab.Messages = append(tab.Messages, myMessage)
|
||||||
@@ -458,10 +457,10 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
reconnect := fyne.NewMenuItem("reconnect", func() {
|
reconnect := fyne.NewMenuItem("reconnect", func() {
|
||||||
go func(){
|
go func() {
|
||||||
err := client.Connect()
|
err := client.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fyne.Do(func(){
|
fyne.Do(func() {
|
||||||
dialog.ShowError(err, w)
|
dialog.ShowError(err, w)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user