mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-27 21:11:11 -07:00
update config when exit
This commit is contained in:
parent
41863c3945
commit
165c4a4a70
28
config.go
28
config.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
config "github.com/spf13/viper"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -27,7 +26,7 @@ func configInit() {
|
||||
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
||||
os.Mkdir(defaultConfigPath, os.ModePerm)
|
||||
}
|
||||
config.SafeWriteConfig();
|
||||
config.SafeWriteConfig()
|
||||
}
|
||||
|
||||
// setup
|
||||
@ -36,3 +35,28 @@ func configInit() {
|
||||
translator.src_lang = config.GetString("source_language")
|
||||
translator.dst_lang = config.GetString("destination_language")
|
||||
}
|
||||
|
||||
func updateConfig() {
|
||||
changed := false
|
||||
|
||||
if config.GetString("theme") != theme {
|
||||
changed = true
|
||||
config.Set("theme", theme)
|
||||
}
|
||||
if config.GetBool("transparent") != transparent {
|
||||
changed = true
|
||||
config.Set("transparent", transparent)
|
||||
}
|
||||
if config.GetString("source_language") != translator.src_lang {
|
||||
changed = true
|
||||
config.Set("source_language", translator.src_lang)
|
||||
}
|
||||
if config.GetString("destination_language") != translator.dst_lang {
|
||||
changed = true
|
||||
config.Set("destination_language", translator.dst_lang)
|
||||
}
|
||||
|
||||
if changed {
|
||||
config.WriteConfig()
|
||||
}
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -18,6 +19,7 @@ var (
|
||||
pages = tview.NewPages()
|
||||
window Window
|
||||
// config
|
||||
config = viper.New()
|
||||
theme string
|
||||
transparent bool
|
||||
)
|
||||
@ -47,4 +49,6 @@ func main() {
|
||||
EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer updateConfig()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user