mirror of
https://github.com/Apologieze/Benri.git
synced 2026-01-18 17:17:21 +01:00
Start of discord rich presence
This commit is contained in:
@@ -3,16 +3,18 @@ package config
|
||||
import "fyne.io/fyne/v2"
|
||||
|
||||
type Config struct {
|
||||
preference fyne.Preferences
|
||||
SkipOpening bool `json:"skip_opening"`
|
||||
SkipEnding bool `json:"skip_ending"`
|
||||
TrayIcon bool `json:"tray_icon"`
|
||||
preference fyne.Preferences
|
||||
SkipOpening bool `json:"skip_opening"`
|
||||
SkipEnding bool `json:"skip_ending"`
|
||||
TrayIcon bool `json:"tray_icon"`
|
||||
DiscordPresence bool
|
||||
}
|
||||
|
||||
const (
|
||||
SkipOpeningKey = "skip_opening"
|
||||
SkipEndingKey = "skip_ending"
|
||||
TrayIconKey = "tray_icon"
|
||||
SkipOpeningKey = "skip_opening"
|
||||
SkipEndingKey = "skip_ending"
|
||||
TrayIconKey = "tray_icon"
|
||||
DiscordPresence = "discord_presence"
|
||||
)
|
||||
|
||||
var Setting Config
|
||||
@@ -20,10 +22,11 @@ var Setting Config
|
||||
// NewConfig returns a new Config struct
|
||||
func CreateConfig(app fyne.Preferences) {
|
||||
Setting = Config{
|
||||
preference: app,
|
||||
SkipOpening: app.Bool(SkipOpeningKey),
|
||||
SkipEnding: app.Bool(SkipEndingKey),
|
||||
TrayIcon: app.Bool(TrayIconKey),
|
||||
preference: app,
|
||||
SkipOpening: app.Bool(SkipOpeningKey),
|
||||
SkipEnding: app.Bool(SkipEndingKey),
|
||||
TrayIcon: app.Bool(TrayIconKey),
|
||||
DiscordPresence: app.Bool(DiscordPresence),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +38,8 @@ func SetBool(key string, value bool) {
|
||||
Setting.SkipEnding = value
|
||||
case TrayIconKey:
|
||||
Setting.TrayIcon = value
|
||||
case DiscordPresence:
|
||||
Setting.DiscordPresence = value
|
||||
}
|
||||
Setting.preference.SetBool(key, value)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
curd "AnimeGUI/curdInteg"
|
||||
"AnimeGUI/src/anilist"
|
||||
"AnimeGUI/src/config"
|
||||
"AnimeGUI/src/richPresence"
|
||||
"AnimeGUI/verniy"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
@@ -60,6 +61,8 @@ func main() {
|
||||
|
||||
go dowloadMPV()
|
||||
|
||||
richPresence.InitDiscordRichPresence()
|
||||
|
||||
window = appW.NewWindow(AppName)
|
||||
window.Resize(fyne.NewSize(1000, 700))
|
||||
window.CenterOnScreen()
|
||||
|
||||
@@ -20,16 +20,19 @@ func initSettingDialog() {
|
||||
config.SetBool(config.TrayIconKey, b)
|
||||
fmt.Println(config.Setting.TrayIcon)
|
||||
})
|
||||
checkDiscordPresence := widget.NewCheck("", func(b bool) { config.SetBool(config.DiscordPresence, b) })
|
||||
|
||||
checkSkipOpening.SetChecked(config.Setting.SkipOpening)
|
||||
checkSkipEnding.SetChecked(config.Setting.SkipEnding)
|
||||
checkTrayIcon.SetChecked(config.Setting.TrayIcon)
|
||||
checkDiscordPresence.SetChecked(config.Setting.DiscordPresence)
|
||||
toggleTrayFeature()
|
||||
|
||||
rowSkipOpening := container.New(layout.NewFormLayout(),
|
||||
widget.NewLabelWithStyle("Automatically skip Opening", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}), checkSkipOpening,
|
||||
widget.NewLabelWithStyle("Automatically skip Ending", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}), checkSkipEnding,
|
||||
widget.NewLabelWithStyle("Add a tray icon for Benri", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}), checkTrayIcon,
|
||||
widget.NewLabelWithStyle("Show Discord Activity", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}), checkDiscordPresence,
|
||||
)
|
||||
//form := container.New(layout.NewFormLayout(), rowSkipOpening)
|
||||
menuOption := container.NewBorder(nil, nil, nil, nil, rowSkipOpening)
|
||||
|
||||
94
src/richPresence/richPresence.go
Normal file
94
src/richPresence/richPresence.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package richPresence
|
||||
|
||||
import (
|
||||
"AnimeGUI/src/config"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/hugolgst/rich-go/client"
|
||||
"time"
|
||||
)
|
||||
|
||||
var timeNow = time.Now()
|
||||
|
||||
func ResetTime() {
|
||||
timeNow = time.Now()
|
||||
}
|
||||
func InitDiscordRichPresence() {
|
||||
if !config.Setting.DiscordPresence {
|
||||
return
|
||||
}
|
||||
err := client.Login("1046397185467621418")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
SetMenuActivity()
|
||||
}
|
||||
|
||||
func SetMenuActivity() {
|
||||
err := client.SetActivity(client.Activity{
|
||||
Details: "In Main Menu",
|
||||
State: "Free, open-source, crossplatform Anime streaming app :D",
|
||||
LargeImage: "https://apologize.fr/benri/icon.jpg",
|
||||
LargeText: "Free, open-source, crossplatform Anime streaming app :D",
|
||||
/*SmallImage: "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx170942-B77wUSM1jQTu.jpg",
|
||||
SmallText: "And this is the small image",*/
|
||||
/*Party: &client.Party{
|
||||
ID: "-1",
|
||||
Players: 15,
|
||||
MaxPlayers: 24,
|
||||
},*/
|
||||
Buttons: []*client.Button{
|
||||
&client.Button{
|
||||
Label: "Try Benri", // Button label
|
||||
Url: "https://uwu.apologize.fr/preview",
|
||||
},
|
||||
/*&client.Button{
|
||||
Label: "Try 2Benri", // Button label
|
||||
Url: "https://uwu.apologize.fr/preview",
|
||||
},*/
|
||||
},
|
||||
Timestamps: &client.Timestamps{
|
||||
Start: &timeNow,
|
||||
//End: &then,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func SetActivity() {
|
||||
err := client.SetActivity(client.Activity{
|
||||
State: "Episode 12/24 - 12min 3s",
|
||||
Details: "Blue Box",
|
||||
LargeImage: "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx170942-B77wUSM1jQTu.jpg",
|
||||
LargeText: "This is the large image :D",
|
||||
/*SmallImage: "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx170942-B77wUSM1jQTu.jpg",
|
||||
SmallText: "And this is the small image",*/
|
||||
/*Party: &client.Party{
|
||||
ID: "-1",
|
||||
Players: 15,
|
||||
MaxPlayers: 24,
|
||||
},*/
|
||||
Buttons: []*client.Button{
|
||||
&client.Button{
|
||||
Label: "Try Benri", // Button label
|
||||
Url: "https://uwu.apologize.fr/preview",
|
||||
},
|
||||
/*&client.Button{
|
||||
Label: "Try 2Benri", // Button label
|
||||
Url: "https://uwu.apologize.fr/preview",
|
||||
},*/
|
||||
},
|
||||
Timestamps: &client.Timestamps{
|
||||
Start: &timeNow,
|
||||
//End: &then,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user