This commit is contained in:
2026-01-17 13:19:23 +00:00
parent 2312c48f67
commit 154d275c21

82
main.go
View File

@@ -75,7 +75,12 @@ var ProfileSelectionDone bool = false
var ProfileSelectionProfile *HashbangProfile
// The visibility that the post is going to be posted with
var PostVisibility string
var PostVisibility string = "public"
var ReplyIDEntry *widget.Entry
// The current page of the home timeline
var HomePage int = 1
// This function saves the config in memory to disk.
func SaveConfigToDisk() error {
@@ -262,15 +267,27 @@ func ProfileLaunch() {
)
for _, v := range Profiles {
ext := ""
btn := widget.NewButton("Log in", func() {
ProfileSelectionDone = true
ProfileSelectionProfile = v
MainWindow.Close()
})
if v.InternalName == LoadedConfig.ProfileName {
ext = "🚪 "
btn.Importance = widget.DangerImportance
} else {
btn.Importance = widget.HighImportance
}
btn.Text = ext + btn.Text
ProfileSelection.Add(
container.NewHBox(
widget.NewLabel(v.Name),
widget.NewButton("Log in", func() {
ProfileSelectionDone = true
ProfileSelectionProfile = v
MainWindow.Close()
}),
btn,
),
)
}
@@ -396,20 +413,57 @@ func main() {
App = app.New()
MainWindow = App.NewWindow("Hashbang")
TootEntry := widget.NewMultiLineEntry()
ReplyIDEntry := widget.NewEntry()
ReplyIDEntry = widget.NewEntry()
ReplyIDLabel := widget.NewLabel("In reply to")
ReplyBox := container.NewGridWithColumns(2, ReplyIDLabel, ReplyIDEntry)
Timeline := container.NewGridWithColumns(4)
PostTimeline := container.NewVBox(widget.NewLabel("Posts"))
VisibilitySelector := widget.NewSelect([]string{"public", "unlisted", "private", "direct"}, func(value string) {
PostVisibility = value
})
VisibilitySelector.Selected = "public"
ShowTimeline := func() {
PostTimeline.RemoveAll()
pg := new(mastodon.Pagination)
posts, err := Client.GetTimelineHome(context.Background(), pg)
if err != nil {
PostTimeline.Objects[0] = widget.NewLabel(fmt.Sprintf("Error getting posts: %s", err.Error()))
return
}
for _, status := range posts {
avatar_uri := status.Account.AvatarStatic
log.Println(avatar_uri)
u, err := storage.ParseURI(avatar_uri)
if err != nil {
continue
}
im := canvas.NewImageFromURI(u)
im.Resize(fyne.NewSize(25,25))
im.FillMode = canvas.ImageFillContain
lab := widget.NewLabel(fmt.Sprintf("%s: %s", status.Account.Username, html2text.HTML2Text(status.Content)))
lab.Selectable = true
actions := container.NewHBox()
actions.Add(widget.NewButton("Favorite", func() {}))
actions.Add(widget.NewButton("Boost", func() {}))
actions.Add(widget.NewButton("Reply", func() {
ReplyIDEntry.SetText(string(status.ID))
}))
actions.Add(widget.NewButton("Bookmark", func() {}))
lab.Wrapping = fyne.TextWrapWord
PostTimeline.Add(container.NewGridWithColumns(3, im, lab, actions))
}
}
ShowNotifications := func() {
Timeline.RemoveAll()
pg := new(mastodon.Pagination)
//NewTimeline := container.NewVBox(widget.NewLabel("Notifications"))
notis, err := Client.GetNotifications(context.Background(), pg)
if err != nil {
Timeline.Objects[0] = widget.NewLabel(fmt.Sprintf("Error getting notifications: %s", err.Error()))
@@ -428,7 +482,6 @@ func main() {
} else {
label = widget.NewLabel("No content set")
}
//label.Truncation = fyne.TextTruncateClip
label.Wrapping = fyne.TextWrapWord
avatar_uri := v.Account.Avatar
u, err := storage.ParseURI(avatar_uri)
@@ -453,10 +506,15 @@ func main() {
}
go ShowNotifications()
go ShowTimeline()
RefreshNotis := widget.NewButton("Refresh", ShowNotifications)
RefreshAll := widget.NewButton("Refresh", func(){
ShowNotifications()
ShowTimeline()
})
MainWindow.SetContent(container.NewHSplit(container.NewVBox(TootEntry, ReplyBox, VisibilitySelector, widget.NewButton("Post", func() {
MainWindow.SetContent(container.NewVSplit(container.NewVScroll(PostTimeline), container.NewHSplit(container.NewVBox(TootEntry, ReplyBox, VisibilitySelector, widget.NewButton("Post", func() {
toot := mastodon.Toot{
Status: TootEntry.Text,
Visibility: PostVisibility,
@@ -467,6 +525,6 @@ func main() {
if err != nil {
dialog.ShowError(err, MainWindow)
}
}), RefreshNotis), container.NewVScroll(Timeline)))
}), RefreshAll), container.NewVScroll(Timeline))))
MainWindow.ShowAndRun()
}