🎨 Plugin uninstall
This commit is contained in:
parent
6d00914018
commit
6eb3673b6e
4 changed files with 72 additions and 60 deletions
|
@ -6,7 +6,7 @@ require (
|
|||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/css v0.1.2
|
||||
github.com/88250/gulu v1.2.3-0.20230501031728-4d62370997cd
|
||||
github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493
|
||||
github.com/88250/lute v1.7.6-0.20230506015935-ca8269ccf0ef
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ClarkThan/ahocorasick v0.0.0-20230220142845-f237b6348b3e
|
||||
|
|
|
@ -8,8 +8,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
|
|||
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20230501031728-4d62370997cd h1:PgbmnoTqfVbYyhUljovnAz6l/oWPlbM1d5yrkVDHO1w=
|
||||
github.com/88250/gulu v1.2.3-0.20230501031728-4d62370997cd/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
|
||||
github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493 h1:F6C9dVvQVwxCOAd88Ea4WchCzR6Ekr/Q4IiqLYWfDyw=
|
||||
github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20230506015935-ca8269ccf0ef h1:nNRs8oFCKPRsgnz6k2m0iDXXm9ManWyvP7K4J/OMov8=
|
||||
github.com/88250/lute v1.7.6-0.20230506015935-ca8269ccf0ef/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
|
|
@ -78,6 +78,15 @@ func UninstallBazaarPlugin(pluginName string) error {
|
|||
if nil != err {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
|
||||
}
|
||||
|
||||
petals := getPetals()
|
||||
for i, petal := range petals {
|
||||
if petal.Name == pluginName {
|
||||
petals = append(petals[:i], petals[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
savePetals(petals)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/filelock"
|
||||
|
@ -41,19 +42,7 @@ type Petal struct {
|
|||
}
|
||||
|
||||
func SetPetalEnabled(name string, enabled bool) {
|
||||
petals := []*Petal{}
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
confPath := filepath.Join(petalDir, "petals.json")
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &petals); nil != err {
|
||||
logging.LogErrorf("unmarshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
petals := getPetals()
|
||||
|
||||
plugins := bazaar.InstalledPlugins()
|
||||
var plugin *bazaar.Plugin
|
||||
|
@ -80,50 +69,7 @@ func SetPetalEnabled(name string, enabled bool) {
|
|||
petal.Enabled = enabled
|
||||
}
|
||||
|
||||
if data, err = gulu.JSON.MarshalIndentJSON(petals, "", "\t"); nil != err {
|
||||
logging.LogErrorf("marshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getPetals() (ret []*Petal) {
|
||||
ret = []*Petal{}
|
||||
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
if err := os.MkdirAll(petalDir, 0755); nil != err {
|
||||
logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
confPath := filepath.Join(petalDir, "petals.json")
|
||||
if !gulu.File.IsExist(confPath) {
|
||||
data, err := gulu.JSON.MarshalIndentJSON(ret, "", "\t")
|
||||
if nil != err {
|
||||
logging.LogErrorf("marshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
logging.LogErrorf("unmarshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
savePetals(petals)
|
||||
}
|
||||
|
||||
func LoadPetals() (ret []*Petal) {
|
||||
|
@ -172,6 +118,63 @@ func LoadPetals() (ret []*Petal) {
|
|||
return
|
||||
}
|
||||
|
||||
var petalsStoreLock = sync.Mutex{}
|
||||
|
||||
func savePetals(petals []*Petal) {
|
||||
petalsStoreLock.Lock()
|
||||
defer petalsStoreLock.Unlock()
|
||||
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
confPath := filepath.Join(petalDir, "petals.json")
|
||||
data, err := gulu.JSON.MarshalIndentJSON(petals, "", "\t")
|
||||
if nil != err {
|
||||
logging.LogErrorf("marshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getPetals() (ret []*Petal) {
|
||||
petalsStoreLock.Lock()
|
||||
defer petalsStoreLock.Unlock()
|
||||
|
||||
ret = []*Petal{}
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
if err := os.MkdirAll(petalDir, 0755); nil != err {
|
||||
logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
confPath := filepath.Join(petalDir, "petals.json")
|
||||
if !gulu.File.IsExist(confPath) {
|
||||
data, err := gulu.JSON.MarshalIndentJSON(ret, "", "\t")
|
||||
if nil != err {
|
||||
logging.LogErrorf("marshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
logging.LogErrorf("unmarshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getPetalByName(name string, petals []*Petal) (ret *Petal) {
|
||||
for _, p := range petals {
|
||||
if name == p.Name {
|
||||
|
|
Loading…
Add table
Reference in a new issue