mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-15 22:48:16 +08:00
new room gui
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
const (
|
||||
ProgramName = "卡西米尔唱片机"
|
||||
Version = "beta 0.9.2"
|
||||
Version = "beta 0.9.3"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,6 +22,17 @@ func GetAssetPath(name string) string {
|
||||
|
||||
type Config interface {
|
||||
Name() string
|
||||
OnLoad()
|
||||
OnSave()
|
||||
}
|
||||
|
||||
type BaseConfig struct {
|
||||
}
|
||||
|
||||
func (c *BaseConfig) OnLoad() {
|
||||
}
|
||||
|
||||
func (c *BaseConfig) OnSave() {
|
||||
}
|
||||
|
||||
var ConfigFile *ini.File
|
||||
@@ -32,6 +43,7 @@ func LoadConfig(cfg Config) {
|
||||
if err == nil {
|
||||
_ = sec.MapTo(cfg)
|
||||
}
|
||||
cfg.OnLoad()
|
||||
Configs = append(Configs, cfg)
|
||||
return
|
||||
}
|
||||
@@ -43,7 +55,7 @@ func init() {
|
||||
fmt.Println("config not found, using default config")
|
||||
ConfigFile = ini.Empty()
|
||||
}
|
||||
for _, cfg := range []Config{Log, LiveRoom, Player, Provider, General} {
|
||||
for _, cfg := range []Config{Log, Player, Provider, General} {
|
||||
LoadConfig(cfg)
|
||||
}
|
||||
}
|
||||
@@ -51,6 +63,7 @@ func init() {
|
||||
func SaveToConfigFile(filename string) error {
|
||||
cfgFile := ini.Empty()
|
||||
for _, cfg := range Configs {
|
||||
cfg.OnSave()
|
||||
if err := cfgFile.Section(cfg.Name()).ReflectFrom(cfg); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
type _GeneralConfig struct {
|
||||
BaseConfig
|
||||
Language string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package config
|
||||
|
||||
type _LiveRoomConfig struct {
|
||||
History []string
|
||||
}
|
||||
|
||||
func (c *_LiveRoomConfig) Name() string {
|
||||
return "LiveRoom"
|
||||
}
|
||||
|
||||
var LiveRoom = &_LiveRoomConfig{History: []string{"9076804", "3819533"}}
|
||||
@@ -8,6 +8,12 @@ type _LogConfig struct {
|
||||
RedirectStderr bool
|
||||
}
|
||||
|
||||
func (c *_LogConfig) OnLoad() {
|
||||
}
|
||||
|
||||
func (c *_LogConfig) OnSave() {
|
||||
}
|
||||
|
||||
func (c *_LogConfig) Name() string {
|
||||
return "Log"
|
||||
}
|
||||
|
||||
@@ -1,25 +1,55 @@
|
||||
package config
|
||||
|
||||
type _PlayerConfig struct {
|
||||
Playlists []string
|
||||
PlaylistsProvider []string
|
||||
PlaylistIndex int
|
||||
PlaylistRandom bool
|
||||
AudioDevice string
|
||||
Volume float64
|
||||
SkipPlaylist bool
|
||||
PlaylistData string
|
||||
Playlists []*PlayerPlaylist `ini:"-"`
|
||||
//PlaylistsProvider []string
|
||||
PlaylistIndex int
|
||||
PlaylistRandom bool
|
||||
UserPlaylistRandom bool
|
||||
AudioDevice string
|
||||
Volume float64
|
||||
SkipPlaylist bool
|
||||
}
|
||||
|
||||
type PlayerPlaylist struct {
|
||||
ID string
|
||||
Provider string
|
||||
}
|
||||
|
||||
func (c *_PlayerConfig) Name() string {
|
||||
return "Player"
|
||||
}
|
||||
|
||||
var Player = &_PlayerConfig{
|
||||
Playlists: []string{"2382819181", "4987059624", "list1"},
|
||||
PlaylistsProvider: []string{"netease", "netease", "local"},
|
||||
PlaylistIndex: 0,
|
||||
PlaylistRandom: true,
|
||||
AudioDevice: "auto",
|
||||
Volume: 100,
|
||||
SkipPlaylist: false,
|
||||
func (c *_PlayerConfig) OnLoad() {
|
||||
//c.Playlists = make([]*PlayerPlaylist, 0)
|
||||
_ = LoadJson(c.PlaylistData, &c.Playlists)
|
||||
}
|
||||
|
||||
func (c *_PlayerConfig) OnSave() {
|
||||
_ = SaveJson(c.PlaylistData, &c.Playlists)
|
||||
}
|
||||
|
||||
var Player = &_PlayerConfig{
|
||||
PlaylistData: "playlists.json",
|
||||
Playlists: []*PlayerPlaylist{
|
||||
{
|
||||
"2382819181",
|
||||
"netease",
|
||||
},
|
||||
{
|
||||
"4987059624",
|
||||
"netease",
|
||||
},
|
||||
{
|
||||
"list1",
|
||||
"local",
|
||||
},
|
||||
},
|
||||
PlaylistIndex: 0,
|
||||
PlaylistRandom: true,
|
||||
UserPlaylistRandom: false,
|
||||
AudioDevice: "auto",
|
||||
Volume: 100,
|
||||
SkipPlaylist: false,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
type _ProviderConfig struct {
|
||||
BaseConfig
|
||||
Priority []string
|
||||
LocalDir string
|
||||
}
|
||||
|
||||
23
config/jsonconfig.go
Normal file
23
config/jsonconfig.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LoadJson(path string, dst any) error {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal(data, dst)
|
||||
}
|
||||
|
||||
func SaveJson(path string, dst any) error {
|
||||
data, err := json.MarshalIndent(dst, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.WriteFile(path, data, 0666)
|
||||
}
|
||||
Reference in New Issue
Block a user