idk
This commit is contained in:
88
main.go
88
main.go
@@ -26,12 +26,14 @@ import (
|
|||||||
oasisSdk "pain.agency/oasis-sdk"
|
oasisSdk "pain.agency/oasis-sdk"
|
||||||
|
|
||||||
// gui - optional
|
// gui - optional
|
||||||
catppuccin "github.com/mbaklor/fyne-catppuccin"
|
// catppuccin "github.com/mbaklor/fyne-catppuccin"
|
||||||
fyneVideo "github.com/metal3d/fyne-streamer/video"
|
adwaita "fyne.io/x/fyne/theme"
|
||||||
|
// TODO: integrated theme switcher
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string = "3.1a"
|
var version string = "3.1a"
|
||||||
|
var statBar widget.Label
|
||||||
|
var chatInfo fyne.Container
|
||||||
// by sunglocto
|
// by sunglocto
|
||||||
// license AGPL
|
// license AGPL
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ type MucTab struct {
|
|||||||
Messages []Message
|
Messages []Message
|
||||||
Scroller *widget.List
|
Scroller *widget.List
|
||||||
isMuc bool
|
isMuc bool
|
||||||
|
Muc *muc.Channel
|
||||||
}
|
}
|
||||||
|
|
||||||
type piConfig struct {
|
type piConfig struct {
|
||||||
@@ -72,7 +75,7 @@ var connection bool = true
|
|||||||
type myTheme struct{}
|
type myTheme struct{}
|
||||||
|
|
||||||
func (m myTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
|
func (m myTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
|
||||||
return catppuccin.New().Color(name, variant)
|
return adwaita.AdwaitaTheme().Color(name, variant)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m myTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
|
func (m myTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
|
||||||
@@ -118,8 +121,8 @@ func addChatTab(isMuc bool, chatJid jid.JID, nick string) {
|
|||||||
author.TextStyle.Bold = true
|
author.TextStyle.Bold = true
|
||||||
content := widget.NewRichTextWithText("content")
|
content := widget.NewRichTextWithText("content")
|
||||||
content.Wrapping = fyne.TextWrapWord
|
content.Wrapping = fyne.TextWrapWord
|
||||||
icon := theme.FileImageIcon()
|
icon := theme.FileVideoIcon()
|
||||||
btn := widget.NewButtonWithIcon("View image", icon, func() {
|
btn := widget.NewButtonWithIcon("View media", icon, func() {
|
||||||
|
|
||||||
})
|
})
|
||||||
return container.NewVBox(author, content, btn)
|
return container.NewVBox(author, content, btn)
|
||||||
@@ -135,7 +138,20 @@ func addChatTab(isMuc bool, chatJid jid.JID, nick string) {
|
|||||||
btn.Hidden = false
|
btn.Hidden = false
|
||||||
btn.OnTapped = func() {
|
btn.OnTapped = func() {
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
u, _ := storage.ParseURI(tabData.Messages[i].ImageURL)
|
u, err := storage.ParseURI(tabData.Messages[i].ImageURL)
|
||||||
|
if err != nil {
|
||||||
|
dialog.ShowError(err, w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(tabData.Messages[i].ImageURL, "mp4") {
|
||||||
|
url, err := url.Parse(tabData.Messages[i].ImageURL)
|
||||||
|
if err != nil {
|
||||||
|
dialog.ShowError(err, w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a.OpenURL(url)
|
||||||
|
return
|
||||||
|
}
|
||||||
image := canvas.NewImageFromURI(u)
|
image := canvas.NewImageFromURI(u)
|
||||||
image.FillMode = canvas.ImageFillOriginal
|
image.FillMode = canvas.ImageFillOriginal
|
||||||
dialog.ShowCustom("Image", "Close", image, w)
|
dialog.ShowCustom("Image", "Close", image, w)
|
||||||
@@ -177,7 +193,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```\n\nDEBUG: %s", reason, fmt.Sprint(os.DirFS("."))))
|
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()
|
||||||
@@ -277,8 +293,10 @@ func main() {
|
|||||||
for j, v := range s {
|
for j, v := range s {
|
||||||
_, err := url.Parse(v)
|
_, err := url.Parse(v)
|
||||||
if err == nil && strings.HasPrefix(v, "https://") {
|
if err == nil && strings.HasPrefix(v, "https://") {
|
||||||
img = v
|
|
||||||
s[j] = fmt.Sprintf("[%s](%s)", v, v)
|
s[j] = fmt.Sprintf("[%s](%s)", v, v)
|
||||||
|
if strings.HasSuffix(v, ".png") || strings.HasSuffix(v, ".jp") || strings.HasSuffix(v, ".webp") || strings.HasSuffix(v, ".mp4") {
|
||||||
|
img = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines[i] = strings.Join(s, " ")
|
lines[i] = strings.Join(s, " ")
|
||||||
@@ -309,11 +327,11 @@ func main() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(client *oasisSdk.XmppClient, _ *muc.Channel, msg *oasisSdk.XMPPChatMessage) {
|
func(client *oasisSdk.XmppClient, muc *muc.Channel, msg *oasisSdk.XMPPChatMessage) {
|
||||||
var ImageID string = ""
|
var ImageID string = ""
|
||||||
mucJidStr := msg.From.Bare().String()
|
mucJidStr := msg.From.Bare().String()
|
||||||
if tab, ok := chatTabs[mucJidStr]; ok {
|
if tab, ok := chatTabs[mucJidStr]; ok {
|
||||||
|
chatTabs[mucJidStr].Muc = muc
|
||||||
str := *msg.CleanedBody
|
str := *msg.CleanedBody
|
||||||
if notifications {
|
if notifications {
|
||||||
if strings.Contains(str, login.DisplayName) || (msg.Reply != nil && strings.Contains(msg.Reply.To, login.DisplayName)) {
|
if strings.Contains(str, login.DisplayName) || (msg.Reply != nil && strings.Contains(msg.Reply.To, login.DisplayName)) {
|
||||||
@@ -328,7 +346,7 @@ func main() {
|
|||||||
_, err := url.Parse(v)
|
_, err := url.Parse(v)
|
||||||
if err == nil && strings.HasPrefix(v, "https://") {
|
if err == nil && strings.HasPrefix(v, "https://") {
|
||||||
s[j] = fmt.Sprintf("[%s](%s)", v, v)
|
s[j] = fmt.Sprintf("[%s](%s)", v, v)
|
||||||
if strings.HasSuffix(v, ".png") || strings.HasSuffix(v, ".jp") || strings.HasSuffix(v, ".webp") {
|
if strings.HasSuffix(v, ".png") || strings.HasSuffix(v, ".jp") || strings.HasSuffix(v, ".webp") || strings.HasSuffix(v, ".mp4") {
|
||||||
ImageID = v
|
ImageID = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,11 +383,30 @@ func main() {
|
|||||||
func(_ *oasisSdk.XmppClient, from jid.JID, state oasisSdk.ChatState) {
|
func(_ *oasisSdk.XmppClient, from jid.JID, state oasisSdk.ChatState) {
|
||||||
switch state {
|
switch state {
|
||||||
case oasisSdk.ChatStateActive:
|
case oasisSdk.ChatStateActive:
|
||||||
|
fyne.Do(func() {
|
||||||
|
statBar.SetText(fmt.Sprintf("%s is active", from.Resourcepart()))
|
||||||
|
})
|
||||||
case oasisSdk.ChatStateComposing:
|
case oasisSdk.ChatStateComposing:
|
||||||
|
fyne.Do(func() {
|
||||||
|
statBar.SetText(fmt.Sprintf("%s is typing...", from.Resourcepart()))
|
||||||
|
})
|
||||||
case oasisSdk.ChatStatePaused:
|
case oasisSdk.ChatStatePaused:
|
||||||
|
|
||||||
|
fyne.Do(func() {
|
||||||
|
statBar.SetText(fmt.Sprintf("%s has stoped typing.", from.Resourcepart()))
|
||||||
|
})
|
||||||
case oasisSdk.ChatStateInactive:
|
case oasisSdk.ChatStateInactive:
|
||||||
|
fyne.Do(func() {
|
||||||
|
statBar.SetText(fmt.Sprintf("%s is idle", from.Resourcepart()))
|
||||||
|
})
|
||||||
case oasisSdk.ChatStateGone:
|
case oasisSdk.ChatStateGone:
|
||||||
|
fyne.Do(func() {
|
||||||
|
statBar.SetText(fmt.Sprintf("%s is gone", from.Resourcepart()))
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
|
fyne.Do(func() {
|
||||||
|
statBar.SetText(fmt.Sprint("Unknown state: ", state))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(_ *oasisSdk.XmppClient, from jid.JID, id string) {
|
func(_ *oasisSdk.XmppClient, from jid.JID, id string) {
|
||||||
@@ -379,7 +416,6 @@ func main() {
|
|||||||
fmt.Printf("%s has seen %s", from.String(), id)
|
fmt.Printf("%s has seen %s", from.String(), id)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Could not create client - " + err.Error())
|
log.Fatalln("Could not create client - " + err.Error())
|
||||||
}
|
}
|
||||||
@@ -437,7 +473,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
//TODO: Fix message hack until jjj adds message sending
|
|
||||||
if replying {
|
if replying {
|
||||||
m := chatTabs[activeMucJid].Messages[selectedId].Raw
|
m := chatTabs[activeMucJid].Messages[selectedId].Raw
|
||||||
client.ReplyToEvent(&m, text)
|
client.ReplyToEvent(&m, text)
|
||||||
@@ -680,6 +715,29 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.SetContent(container.NewVSplit(container.NewVSplit(tabs, container.NewHSplit(entry, sendbtn)), widget.NewLabel("pi")))
|
tabs.OnSelected = func(ti *container.TabItem) {
|
||||||
|
selectedScroller, ok := tabs.Selected().Content.(*widget.List)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var activeChatJid string
|
||||||
|
for jid, tabData := range chatTabs {
|
||||||
|
if tabData.Scroller == selectedScroller {
|
||||||
|
activeChatJid = jid
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tab := chatTabs[activeChatJid]
|
||||||
|
if tab.isMuc {
|
||||||
|
chatInfo = *container.NewHBox(widget.NewLabel(tab.Muc.Addr().String()))
|
||||||
|
} else {
|
||||||
|
chatInfo = *container.NewHBox(widget.NewLabel(tab.Jid.String()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
statBar.SetText("nothing seems to be happening right now...")
|
||||||
|
w.SetContent(container.NewVSplit(container.NewVSplit(tabs, container.NewHSplit(entry, sendbtn)), container.NewHSplit(&statBar,&chatInfo)))
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user