mirror of
https://github.com/eeeXun/GTT.git
synced 2025-06-03 00:10:12 -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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
config "github.com/spf13/viper"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ func configInit() {
|
|||||||
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
||||||
os.Mkdir(defaultConfigPath, os.ModePerm)
|
os.Mkdir(defaultConfigPath, os.ModePerm)
|
||||||
}
|
}
|
||||||
config.SafeWriteConfig();
|
config.SafeWriteConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
@ -36,3 +35,28 @@ func configInit() {
|
|||||||
translator.src_lang = config.GetString("source_language")
|
translator.src_lang = config.GetString("source_language")
|
||||||
translator.dst_lang = config.GetString("destination_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 (
|
import (
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -18,6 +19,7 @@ var (
|
|||||||
pages = tview.NewPages()
|
pages = tview.NewPages()
|
||||||
window Window
|
window Window
|
||||||
// config
|
// config
|
||||||
|
config = viper.New()
|
||||||
theme string
|
theme string
|
||||||
transparent bool
|
transparent bool
|
||||||
)
|
)
|
||||||
@ -47,4 +49,6 @@ func main() {
|
|||||||
EnableMouse(true).Run(); err != nil {
|
EnableMouse(true).Run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer updateConfig()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user