forked from sunglocto/pi-im
Compare commits
7 Commits
nyx-patch-
...
master
Author | SHA1 | Date | |
---|---|---|---|
0c26b7a8cf | |||
d45ed57572 | |||
c98cbe81ed | |||
ea47f10b5c | |||
91215094e4 | |||
082d2757f6 | |||
596bd6bdba |
76
main.go
76
main.go
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
_ "image/color"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand/v2"
|
||||
@@ -29,13 +28,9 @@ import (
|
||||
"github.com/shreve/musicwand/pkg/mpris"
|
||||
|
||||
// xmpp - required
|
||||
_ "mellium.im/xmpp/disco"
|
||||
"mellium.im/xmpp/jid"
|
||||
"mellium.im/xmpp/muc"
|
||||
_ "mellium.im/xmpp/stanza"
|
||||
oasisSdk "pain.agency/oasis-sdk"
|
||||
// gui - optional
|
||||
// catppuccin "github.com/mbaklor/fyne-catppuccin"
|
||||
// TODO: integrated theme switcher
|
||||
)
|
||||
|
||||
@@ -43,7 +38,9 @@ var version string = "3i"
|
||||
var statBar widget.Label
|
||||
var chatInfo fyne.Container
|
||||
var chatSidebar fyne.Container
|
||||
|
||||
var replyNameIcon string = ">"
|
||||
var replyBodyIcon string = ">"
|
||||
var newlineIcon string = "|->"
|
||||
var agreesToSendingHotFuckIntoChannel bool = false
|
||||
|
||||
// by sunglocto
|
||||
@@ -79,6 +76,21 @@ type CustomMultiLineEntry struct {
|
||||
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 {
|
||||
entry := &CustomMultiLineEntry{}
|
||||
entry.ExtendBaseWidget(entry)
|
||||
@@ -193,7 +205,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
|
||||
content := vbox.Objects[2].(*widget.Label)
|
||||
btn := vbox.Objects[3].(*widget.Button)
|
||||
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
|
||||
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-- {
|
||||
if reply.ID == chatTabs[chatJidStr].Messages[i].Raw.StanzaID.ID {
|
||||
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
|
||||
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 {
|
||||
author.SetText(chatTabs[chatJidStr].Messages[i].Author)
|
||||
replytext.Hide()
|
||||
@@ -422,6 +434,12 @@ func main() {
|
||||
login = config.Login
|
||||
notifications = config.Notifications
|
||||
|
||||
if isUTF8Locale() {
|
||||
replyBodyIcon = "↱"
|
||||
replyNameIcon = "→ "
|
||||
newlineIcon = " ⮡ "
|
||||
}
|
||||
|
||||
client, err := oasisSdk.CreateClient(
|
||||
&login)
|
||||
|
||||
@@ -525,7 +543,7 @@ func main() {
|
||||
chatTabs[mucJidStr].Muc = muc
|
||||
str := *msg.CleanedBody
|
||||
if strings.Contains(str, login.DisplayName) {
|
||||
fmt.Println(str)
|
||||
fmt.Println(str, login.DisplayName)
|
||||
important = true
|
||||
}
|
||||
if !donotnotify && !ignore && notifications {
|
||||
@@ -548,9 +566,7 @@ func main() {
|
||||
lines[i] = strings.Join(s, " ")
|
||||
}
|
||||
str = strings.Join(lines, " ")
|
||||
fmt.Println(str)
|
||||
}
|
||||
fmt.Println(msg.ID)
|
||||
var replyID string
|
||||
if msg.Reply == nil {
|
||||
replyID = "PICLIENT:UNAVAILABLE"
|
||||
@@ -582,6 +598,7 @@ func main() {
|
||||
if !ignore {
|
||||
tab.Messages = append(tab.Messages, myMessage)
|
||||
}
|
||||
important = false
|
||||
fyne.Do(func() {
|
||||
UITabs[mucJidStr].Scroller.Refresh()
|
||||
if scrollDownOnNewMessage {
|
||||
@@ -625,7 +642,6 @@ func main() {
|
||||
func(_ *oasisSdk.XmppClient, from jid.JID, id string) {
|
||||
for _, tab := range chatTabs {
|
||||
for i := len(tab.Messages) - 1; i >= 0; i-- {
|
||||
fmt.Println(tab.Messages[i])
|
||||
if tab.Messages[i].Raw.StanzaID == nil {
|
||||
continue
|
||||
}
|
||||
@@ -635,7 +651,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s has seen %s\n", from.String(), id)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -697,7 +712,6 @@ func main() {
|
||||
go func() {
|
||||
if replying {
|
||||
m := chatTabs[activeMucJid].Messages[selectedId].Raw
|
||||
fmt.Println(selectedId)
|
||||
err = client.ReplyToEvent(&m, text)
|
||||
if err != nil {
|
||||
dialog.ShowError(err, w)
|
||||
@@ -714,14 +728,22 @@ func main() {
|
||||
dialog.ShowError(err, w)
|
||||
}
|
||||
return
|
||||
}
|
||||
}, w)
|
||||
}
|
||||
} else {
|
||||
err = client.SendText(jid.MustParse(activeMucJid).Bare(), text)
|
||||
|
||||
if err != nil {
|
||||
dialog.ShowError(err, w)
|
||||
}
|
||||
|
||||
}
|
||||
}, w)
|
||||
} else {
|
||||
err = client.SendText(jid.MustParse(activeMucJid).Bare(), text)
|
||||
|
||||
if err != nil {
|
||||
dialog.ShowError(err, w)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if !isMuc {
|
||||
@@ -788,14 +810,6 @@ func main() {
|
||||
}, 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() {
|
||||
selectedScroller, ok := AppTabs.Selected().Content.(*widget.List)
|
||||
if !ok {
|
||||
@@ -1087,7 +1101,7 @@ func main() {
|
||||
menu_help := fyne.NewMenu("π", mit, reconnect, licensesbtn, savedata)
|
||||
|
||||
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() {
|
||||
entry.Text = "Hafjag"
|
||||
SendCallback()
|
||||
@@ -1126,7 +1140,7 @@ func main() {
|
||||
|
||||
mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() {
|
||||
// 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)
|
||||
return
|
||||
}
|
||||
@@ -1147,14 +1161,14 @@ func main() {
|
||||
album, al_ok := player.RawMetadata()["xesam:album"]
|
||||
artists := []string{}
|
||||
|
||||
if a_ok{
|
||||
if a_ok {
|
||||
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)
|
||||
} 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 {
|
||||
newtext = fmt.Sprintf("I'm currently listening to %s", strings.Trim(title.String(), "\""))
|
||||
} else if a_ok {
|
||||
|
Reference in New Issue
Block a user