mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Support one-click enable/disable of all downloaded plugins https://github.com/siyuan-note/siyuan/issues/8523
This commit is contained in:
parent
6fa4245819
commit
d54195a943
3 changed files with 74 additions and 0 deletions
|
|
@ -40,6 +40,34 @@ type Petal struct {
|
|||
I18n map[string]interface{} `json:"i18n"` // i18n text
|
||||
}
|
||||
|
||||
type PetalConf struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
func (conf *PetalConf) Save() {
|
||||
if util.ReadOnly {
|
||||
return
|
||||
}
|
||||
|
||||
petalsStoreLock.Lock()
|
||||
defer petalsStoreLock.Unlock()
|
||||
|
||||
data, _ := gulu.JSON.MarshalIndentJSON(Conf, "", " ")
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
if err := os.MkdirAll(petalDir, 0777); nil != err {
|
||||
logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
confPath := filepath.Join(petalDir, "conf.json")
|
||||
if err := filelock.WriteFile(confPath, data); nil != err {
|
||||
logging.LogErrorf("write petal conf [%s] failed: %s", confPath, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, err error) {
|
||||
petals := getPetals()
|
||||
|
||||
|
|
@ -71,6 +99,25 @@ func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, er
|
|||
|
||||
func LoadPetals(frontend string) (ret []*Petal) {
|
||||
ret = []*Petal{}
|
||||
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
confPath := filepath.Join(petalDir, "conf.json")
|
||||
if gulu.File.IsExist(confPath) {
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read petal conf [%s] failed: %s", confPath, err)
|
||||
} else {
|
||||
petalConf := &PetalConf{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, petalConf); nil != err {
|
||||
logging.LogErrorf("unmarshal petal conf [%s] failed: %s", confPath, err)
|
||||
} else {
|
||||
if !petalConf.Enabled {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
petals := getPetals()
|
||||
for _, petal := range petals {
|
||||
_, petal.Incompatible = bazaar.IsIncompatibleInstalledPlugin(petal.Name, frontend)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue