mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 08:48:49 +01:00
🎨 One-click upgrade of downloaded marketplace packages https://github.com/siyuan-note/siyuan/issues/8390
This commit is contained in:
parent
4817bc0812
commit
2120637c06
9 changed files with 144 additions and 11 deletions
|
|
@ -19,17 +19,100 @@ package model
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
"time"
|
||||
|
||||
"github.com/siyuan-note/siyuan/kernel/bazaar"
|
||||
)
|
||||
|
||||
func BatchUpdateBazaarPackages(frontend string) {
|
||||
plugins, widgets, icons, themes, templates := UpdatedPackages(frontend)
|
||||
|
||||
total := len(plugins) + len(widgets) + len(icons) + len(themes) + len(templates)
|
||||
if 1 > total {
|
||||
return
|
||||
}
|
||||
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.language(235), 1, total))
|
||||
defer util.PushClearProgress()
|
||||
count := 1
|
||||
for _, plugin := range plugins {
|
||||
err := bazaar.InstallPlugin(plugin.RepoURL, plugin.RepoHash, filepath.Join(util.DataDir, "plugins", plugin.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("update plugin [%s] failed: %s", plugin.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
}
|
||||
|
||||
count++
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, plugin.Name))
|
||||
}
|
||||
|
||||
for _, widget := range widgets {
|
||||
err := bazaar.InstallWidget(widget.RepoURL, widget.RepoHash, filepath.Join(util.DataDir, "widgets", widget.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("update widget [%s] failed: %s", widget.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
}
|
||||
|
||||
count++
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, widget.Name))
|
||||
}
|
||||
|
||||
for _, icon := range icons {
|
||||
err := bazaar.InstallIcon(icon.RepoURL, icon.RepoHash, filepath.Join(util.IconsPath, icon.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("update icon [%s] failed: %s", icon.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
}
|
||||
|
||||
count++
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, icon.Name))
|
||||
}
|
||||
|
||||
for _, template := range templates {
|
||||
err := bazaar.InstallTemplate(template.RepoURL, template.RepoHash, filepath.Join(util.DataDir, "templates", template.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("update template [%s] failed: %s", template.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
}
|
||||
|
||||
count++
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, template.Name))
|
||||
}
|
||||
|
||||
for _, theme := range themes {
|
||||
err := bazaar.InstallTheme(theme.RepoURL, theme.RepoHash, filepath.Join(util.ThemesPath, theme.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("update theme [%s] failed: %s", theme.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
}
|
||||
|
||||
count++
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, theme.Name))
|
||||
}
|
||||
|
||||
util.ReloadUI()
|
||||
|
||||
go func() {
|
||||
util.WaitForUILoaded()
|
||||
time.Sleep(500)
|
||||
util.PushMsg(fmt.Sprintf(Conf.language(237), total), 5000)
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func UpdatedPackages(frontend string) (plugins []*bazaar.Plugin, widgets []*bazaar.Widget, icons []*bazaar.Icon, themes []*bazaar.Theme, templates []*bazaar.Template) {
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue