forked from sunglocto/pi-im
Compare commits
7 Commits
nyx-patch-
...
master
Author | SHA1 | Date | |
---|---|---|---|
0c26b7a8cf | |||
d45ed57572 | |||
c98cbe81ed | |||
ea47f10b5c | |||
91215094e4 | |||
082d2757f6 | |||
596bd6bdba |
78
main.go
78
main.go
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "image/color"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
@@ -29,13 +28,9 @@ import (
|
|||||||
"github.com/shreve/musicwand/pkg/mpris"
|
"github.com/shreve/musicwand/pkg/mpris"
|
||||||
|
|
||||||
// xmpp - required
|
// xmpp - required
|
||||||
_ "mellium.im/xmpp/disco"
|
|
||||||
"mellium.im/xmpp/jid"
|
"mellium.im/xmpp/jid"
|
||||||
"mellium.im/xmpp/muc"
|
"mellium.im/xmpp/muc"
|
||||||
_ "mellium.im/xmpp/stanza"
|
|
||||||
oasisSdk "pain.agency/oasis-sdk"
|
oasisSdk "pain.agency/oasis-sdk"
|
||||||
// gui - optional
|
|
||||||
// catppuccin "github.com/mbaklor/fyne-catppuccin"
|
|
||||||
// TODO: integrated theme switcher
|
// TODO: integrated theme switcher
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,7 +38,9 @@ var version string = "3i"
|
|||||||
var statBar widget.Label
|
var statBar widget.Label
|
||||||
var chatInfo fyne.Container
|
var chatInfo fyne.Container
|
||||||
var chatSidebar fyne.Container
|
var chatSidebar fyne.Container
|
||||||
|
var replyNameIcon string = ">"
|
||||||
|
var replyBodyIcon string = ">"
|
||||||
|
var newlineIcon string = "|->"
|
||||||
var agreesToSendingHotFuckIntoChannel bool = false
|
var agreesToSendingHotFuckIntoChannel bool = false
|
||||||
|
|
||||||
// by sunglocto
|
// by sunglocto
|
||||||
@@ -79,6 +76,21 @@ type CustomMultiLineEntry struct {
|
|||||||
widget.Entry
|
widget.Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isUTF8Locale() bool {
|
||||||
|
localeVars := []string{"LC_ALL", "LC_CTYPE", "LANG"}
|
||||||
|
for _, envVar := range localeVars {
|
||||||
|
value := os.Getenv(envVar)
|
||||||
|
if strings.Contains(strings.ToLower(value), "utf-8") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isWindows() bool {
|
||||||
|
return os.PathSeparator == '\\' && os.PathListSeparator == ';'
|
||||||
|
}
|
||||||
|
|
||||||
func NewCustomMultiLineEntry() *CustomMultiLineEntry {
|
func NewCustomMultiLineEntry() *CustomMultiLineEntry {
|
||||||
entry := &CustomMultiLineEntry{}
|
entry := &CustomMultiLineEntry{}
|
||||||
entry.ExtendBaseWidget(entry)
|
entry.ExtendBaseWidget(entry)
|
||||||
@@ -193,7 +205,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
|
|||||||
content := vbox.Objects[2].(*widget.Label)
|
content := vbox.Objects[2].(*widget.Label)
|
||||||
btn := vbox.Objects[3].(*widget.Button)
|
btn := vbox.Objects[3].(*widget.Button)
|
||||||
if chatTabs[chatJidStr].Messages[i].Important {
|
if chatTabs[chatJidStr].Messages[i].Important {
|
||||||
//content.Importance = widget.DangerImportance TODO: Fix highlighting messages with mentions, it's currently broken
|
content.Importance = widget.DangerImportance
|
||||||
}
|
}
|
||||||
btn.Hidden = true // Hide by default
|
btn.Hidden = true // Hide by default
|
||||||
msgContent := chatTabs[chatJidStr].Messages[i].Content
|
msgContent := chatTabs[chatJidStr].Messages[i].Content
|
||||||
@@ -249,13 +261,13 @@ func CreateUITab(chatJidStr string) ChatTabUI {
|
|||||||
for i := len(chatTabs[chatJidStr].Messages) - 1; i >= 0; i-- {
|
for i := len(chatTabs[chatJidStr].Messages) - 1; i >= 0; i-- {
|
||||||
if reply.ID == chatTabs[chatJidStr].Messages[i].Raw.StanzaID.ID {
|
if reply.ID == chatTabs[chatJidStr].Messages[i].Raw.StanzaID.ID {
|
||||||
replytext.Show()
|
replytext.Show()
|
||||||
replytext.SetText(fmt.Sprintf(">%s", chatTabs[chatJidStr].Messages[i].Content))
|
replytext.SetText(fmt.Sprintf("%s %s", replyBodyIcon, strings.ReplaceAll(chatTabs[chatJidStr].Messages[i].Content, "\n", newlineIcon)))
|
||||||
guy = chatTabs[chatJidStr].Messages[i].Author
|
guy = chatTabs[chatJidStr].Messages[i].Author
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
author.SetText(fmt.Sprintf("%s > %s", chatTabs[chatJidStr].Messages[i].Author, guy))
|
author.SetText(fmt.Sprintf("%s %s %s", chatTabs[chatJidStr].Messages[i].Author, replyNameIcon, guy))
|
||||||
} else {
|
} else {
|
||||||
author.SetText(chatTabs[chatJidStr].Messages[i].Author)
|
author.SetText(chatTabs[chatJidStr].Messages[i].Author)
|
||||||
replytext.Hide()
|
replytext.Hide()
|
||||||
@@ -422,6 +434,12 @@ func main() {
|
|||||||
login = config.Login
|
login = config.Login
|
||||||
notifications = config.Notifications
|
notifications = config.Notifications
|
||||||
|
|
||||||
|
if isUTF8Locale() {
|
||||||
|
replyBodyIcon = "↱"
|
||||||
|
replyNameIcon = "→ "
|
||||||
|
newlineIcon = " ⮡ "
|
||||||
|
}
|
||||||
|
|
||||||
client, err := oasisSdk.CreateClient(
|
client, err := oasisSdk.CreateClient(
|
||||||
&login)
|
&login)
|
||||||
|
|
||||||
@@ -525,7 +543,7 @@ func main() {
|
|||||||
chatTabs[mucJidStr].Muc = muc
|
chatTabs[mucJidStr].Muc = muc
|
||||||
str := *msg.CleanedBody
|
str := *msg.CleanedBody
|
||||||
if strings.Contains(str, login.DisplayName) {
|
if strings.Contains(str, login.DisplayName) {
|
||||||
fmt.Println(str)
|
fmt.Println(str, login.DisplayName)
|
||||||
important = true
|
important = true
|
||||||
}
|
}
|
||||||
if !donotnotify && !ignore && notifications {
|
if !donotnotify && !ignore && notifications {
|
||||||
@@ -548,9 +566,7 @@ func main() {
|
|||||||
lines[i] = strings.Join(s, " ")
|
lines[i] = strings.Join(s, " ")
|
||||||
}
|
}
|
||||||
str = strings.Join(lines, " ")
|
str = strings.Join(lines, " ")
|
||||||
fmt.Println(str)
|
|
||||||
}
|
}
|
||||||
fmt.Println(msg.ID)
|
|
||||||
var replyID string
|
var replyID string
|
||||||
if msg.Reply == nil {
|
if msg.Reply == nil {
|
||||||
replyID = "PICLIENT:UNAVAILABLE"
|
replyID = "PICLIENT:UNAVAILABLE"
|
||||||
@@ -582,6 +598,7 @@ func main() {
|
|||||||
if !ignore {
|
if !ignore {
|
||||||
tab.Messages = append(tab.Messages, myMessage)
|
tab.Messages = append(tab.Messages, myMessage)
|
||||||
}
|
}
|
||||||
|
important = false
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
UITabs[mucJidStr].Scroller.Refresh()
|
UITabs[mucJidStr].Scroller.Refresh()
|
||||||
if scrollDownOnNewMessage {
|
if scrollDownOnNewMessage {
|
||||||
@@ -625,7 +642,6 @@ func main() {
|
|||||||
func(_ *oasisSdk.XmppClient, from jid.JID, id string) {
|
func(_ *oasisSdk.XmppClient, from jid.JID, id string) {
|
||||||
for _, tab := range chatTabs {
|
for _, tab := range chatTabs {
|
||||||
for i := len(tab.Messages) - 1; i >= 0; i-- {
|
for i := len(tab.Messages) - 1; i >= 0; i-- {
|
||||||
fmt.Println(tab.Messages[i])
|
|
||||||
if tab.Messages[i].Raw.StanzaID == nil {
|
if tab.Messages[i].Raw.StanzaID == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -635,7 +651,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("%s has seen %s\n", from.String(), id)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -697,7 +712,6 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
if replying {
|
if replying {
|
||||||
m := chatTabs[activeMucJid].Messages[selectedId].Raw
|
m := chatTabs[activeMucJid].Messages[selectedId].Raw
|
||||||
fmt.Println(selectedId)
|
|
||||||
err = client.ReplyToEvent(&m, text)
|
err = client.ReplyToEvent(&m, text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dialog.ShowError(err, w)
|
dialog.ShowError(err, w)
|
||||||
@@ -714,13 +728,21 @@ func main() {
|
|||||||
dialog.ShowError(err, w)
|
dialog.ShowError(err, w)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
err = client.SendText(jid.MustParse(activeMucJid).Bare(), text)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
dialog.ShowError(err, w)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, w)
|
}, w)
|
||||||
}
|
} else {
|
||||||
err = client.SendText(jid.MustParse(activeMucJid).Bare(), text)
|
err = client.SendText(jid.MustParse(activeMucJid).Bare(), text)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dialog.ShowError(err, w)
|
dialog.ShowError(err, w)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -788,14 +810,6 @@ func main() {
|
|||||||
}, w)
|
}, w)
|
||||||
})
|
})
|
||||||
|
|
||||||
mis := fyne.NewMenuItem("clear chat window", func() {
|
|
||||||
dialog.ShowConfirm("clear chat window", "are you sure you want to clear the chat window?", func(b bool) {
|
|
||||||
if b {
|
|
||||||
fmt.Println("clearing chat")
|
|
||||||
}
|
|
||||||
}, w)
|
|
||||||
})
|
|
||||||
|
|
||||||
jtb := fyne.NewMenuItem("jump to bottom", func() {
|
jtb := fyne.NewMenuItem("jump to bottom", func() {
|
||||||
selectedScroller, ok := AppTabs.Selected().Content.(*widget.List)
|
selectedScroller, ok := AppTabs.Selected().Content.(*widget.List)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -1087,7 +1101,7 @@ func main() {
|
|||||||
menu_help := fyne.NewMenu("π", mit, reconnect, licensesbtn, savedata)
|
menu_help := fyne.NewMenu("π", mit, reconnect, licensesbtn, savedata)
|
||||||
|
|
||||||
menu_changeroom := fyne.NewMenu("Α", mic, beginADM, joinARoom, leaveRoom, jbookmarks)
|
menu_changeroom := fyne.NewMenu("Α", mic, beginADM, joinARoom, leaveRoom, jbookmarks)
|
||||||
menu_configureview := fyne.NewMenu("Β", mia, mis, jtt, jtb)
|
menu_configureview := fyne.NewMenu("Β", mia, jtt, jtb)
|
||||||
hafjag := fyne.NewMenuItem("Hafjag", func() {
|
hafjag := fyne.NewMenuItem("Hafjag", func() {
|
||||||
entry.Text = "Hafjag"
|
entry.Text = "Hafjag"
|
||||||
SendCallback()
|
SendCallback()
|
||||||
@@ -1126,7 +1140,7 @@ func main() {
|
|||||||
|
|
||||||
mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() {
|
mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() {
|
||||||
// BEGIN PLATFORM SPECIFIC CODE
|
// BEGIN PLATFORM SPECIFIC CODE
|
||||||
if os.PathSeparator == '\\' && os.PathListSeparator == ';' { // Windows
|
if isWindows() {
|
||||||
dialog.ShowError(errors.New("This feature is not supported on your operating system"), w)
|
dialog.ShowError(errors.New("This feature is not supported on your operating system"), w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1147,14 +1161,14 @@ func main() {
|
|||||||
album, al_ok := player.RawMetadata()["xesam:album"]
|
album, al_ok := player.RawMetadata()["xesam:album"]
|
||||||
artists := []string{}
|
artists := []string{}
|
||||||
|
|
||||||
if a_ok{
|
if a_ok {
|
||||||
artist.Store(&artists)
|
artist.Store(&artists)
|
||||||
}
|
}
|
||||||
|
|
||||||
if t_ok && a_ok && al_ok && album.String() != "\"\""{
|
if t_ok && a_ok && al_ok && album.String() != "\"\"" {
|
||||||
newtext = fmt.Sprintf("I'm currently listening to %s by %s, in the %s album", strings.Trim(title.String(), "\""), strings.Join(artists, ","), album)
|
newtext = fmt.Sprintf("I'm currently listening to %s by %s, in the %s album", strings.Trim(title.String(), "\""), strings.Join(artists, ","), album)
|
||||||
} else if t_ok && a_ok {
|
} else if t_ok && a_ok {
|
||||||
newtext = fmt.Sprintf("I'm currently listening to %s by %s", strings.Trim(title.String(), "\""), strings.Join(artists, ",") )
|
newtext = fmt.Sprintf("I'm currently listening to %s by %s", strings.Trim(title.String(), "\""), strings.Join(artists, ","))
|
||||||
} else if t_ok {
|
} else if t_ok {
|
||||||
newtext = fmt.Sprintf("I'm currently listening to %s", strings.Trim(title.String(), "\""))
|
newtext = fmt.Sprintf("I'm currently listening to %s", strings.Trim(title.String(), "\""))
|
||||||
} else if a_ok {
|
} else if a_ok {
|
||||||
|
Reference in New Issue
Block a user