Skip to content

Commit

Permalink
feat: Allow customizing theme (#29)
Browse files Browse the repository at this point in the history
Issue:linuxdeepin/developer-center#7332
Log: Allow customizing theme
  • Loading branch information
ArchieMeng authored Mar 19, 2024
1 parent ea514d6 commit f525b24
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions pkg/config/upgrader/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Target struct {
Backup_list []string `yaml:"backup_list"`
Hold_list []string `yaml:"hold_list"`
After_run string `yaml:"after_run"`
Plymouth_theme string `yaml:"plymouth_theme"`
}

type CommitTarget struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/upgrader/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type RepoConfig struct {
ConfigDir string `json:"config_dir"`
StageDir string `json:"stage_dir"`
AfterRun string `json:"Afer_Run"`
PlymouthTheme string `json:"Plymouth_Theme"`

SubscribeList []string `json:"subscribe_list"`
FilterList []string `json:"filter_list"`
Expand Down Expand Up @@ -200,6 +201,7 @@ func (c *Config) LoadData(path string) {
c.AppendCommit(dataCf.Target.Backup_list, true)
c.AppendFilter(dataCf.Target.Hold_list, true)
c.RepoList[0].AfterRun = dataCf.Target.After_run
c.RepoList[0].PlymouthTheme = dataCf.Target.Plymouth_theme
const versionManager = "/var/lib/deepin-boot-kit"
for _, v := range c.RepoList[0].SubscribeList {
if strings.HasPrefix(c.RepoList[0].RepoMountPoint, v) {
Expand Down
32 changes: 14 additions & 18 deletions pkg/upgrader/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func NewUpgrader(conf *config.Config,
return &info, nil
}

func setPlymouthTheme() error {
func setPlymouthTheme(theme string) error {
path := "/var/cache/system-rollback-theme"
if _, err := os.Stat(path); err != nil {
err = os.Mkdir(path, 0755)
Expand Down Expand Up @@ -249,7 +249,7 @@ func setPlymouthTheme() error {
if err != nil {
return err
}
out, err := exec.Command("/usr/sbin/plymouth-set-default-theme", "-R", "deepin-recovery").CombinedOutput()
out, err := exec.Command("/usr/sbin/plymouth-set-default-theme", "-R", theme).CombinedOutput()
if err != nil {
logger.Warning("failed to set upgrade plymouth theme:", string(out))
return err
Expand Down Expand Up @@ -347,6 +347,7 @@ func (c *Upgrader) Commit(newVersion, subject string, useSysData bool,
evHandler func(op, state int32, target, desc string)) (excode int, err error) {
exitCode := _STATE_TY_SUCCESS
var isClean bool
var theme string
c.SendingSignal(evHandler, _OP_TY_COMMIT_START, _STATE_TY_RUNING, newVersion, "")

if len(newVersion) == 0 {
Expand All @@ -366,7 +367,11 @@ func (c *Upgrader) Commit(newVersion, subject string, useSysData bool,
subject = fmt.Sprintf("Release %s", newVersion)
}
logger.Info("the version number of this submission is:", newVersion)
err = setPlymouthTheme()
theme = c.conf.RepoList[0].PlymouthTheme
if len(theme) == 0 {
theme = "deepin-recovery"
}
err = setPlymouthTheme(theme)
if err != nil {
logger.Warning("failed to set plymouth theme:", err)
}
Expand Down Expand Up @@ -1556,21 +1561,12 @@ func (c *Upgrader) AfterRollbackOper(backVersion string, isSuccessful bool) erro
}

func (c *Upgrader) UpdateProgress(progress int) {
upgrade_tool_theme := "/usr/share/plymouth/themes/deepin-recovery"
var theme progressTheme
if util.IsExists(upgrade_tool_theme) {
theme = _UPGRADE_TOOL
} else {
theme = _NO_THEME
}
if theme == _UPGRADE_TOOL {
if progress == 0 {
logger.Debugf("activate the upgrade roll back progress theme")
util.ExecCommand("/usr/bin/plymouth", []string{"change-mode", "--system-upgrade"})
}
logger.Infof("update progress %d", progress)
plymouth.UpdateProgress(progress)
}
if progress == 0 {
logger.Debugf("activate the upgrade roll back progress theme")
util.ExecCommand("/usr/bin/plymouth", []string{"change-mode", "--system-upgrade"})
}
logger.Infof("update progress %d", progress)
plymouth.UpdateProgress(progress)
fmt.Println("update progress:", progress)
}

Expand Down

0 comments on commit f525b24

Please sign in to comment.