Skip to content

Commit

Permalink
feat: add new grub theme
Browse files Browse the repository at this point in the history
      add new grub theme

Log:  add new grub theme
  • Loading branch information
xinpeng wang committed Sep 25, 2024
1 parent bac8779 commit 57e9d8e
Show file tree
Hide file tree
Showing 32 changed files with 115 additions and 27 deletions.
88 changes: 87 additions & 1 deletion adjust-grub-theme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func adjustThemeFallback() error {
}
copyThemeFiles(themeInputDir, themeOutputDir)

bgImg, err := loadBackgroundImage()
bgImg, themeBgImg, err := loadV25BackgroundImage()
if err != nil {
return err
}
Expand All @@ -419,6 +419,18 @@ func adjustThemeFallback() error {
if err != nil {
return err
}
if themeBgImg != nil {
err = saveJpeg(themeBgImg, filepath.Join(themeOutputDir, "background_in_theme.jpg"))
if err != nil {
return err
}
} else {
_, err = copyFile(filepath.Join(themeOutputDir, "background.jpg"),
filepath.Join(themeOutputDir, "background_in_theme.jpg"))
if err != nil {
return err
}
}

themeFile := filepath.Join(themeInputDir, "theme.txt.tpl")
theme, err := tt.ParseThemeFile(themeFile)
Expand Down Expand Up @@ -476,6 +488,80 @@ func adjustThemeFallback() error {
return err
}

// getSystemNameFromOSVersionFile parses the /etc/os-version file and returns the
// value of SystemName,which is used to determine whether it is a community version.
func getSystemNameFromOSVersionFile(filePath string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()

var systemName string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "SystemName=") {
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
systemName = parts[1]
break
}
}
}

if err := scanner.Err(); err != nil {
return "", err
}

return systemName, nil
}

// The v25 theme has 2 background images
func loadV25BackgroundImage() (image.Image, image.Image, error) {
img, err := loadImage(filepath.Join(optThemeOutputDir, themeNameNormal, "background_source"))
if err == nil {
return img, nil, nil
}
logger.Warning("failed to load image background_source:", err)

systemName, err := getSystemNameFromOSVersionFile("/etc/os-version")
if err != nil || systemName == "" {
logger.Warningf("error get systemName %s: %v\n", systemName, err)
return nil, nil, err
}

var backgroundFilename, themeBackgroundFilename string
if strings.Contains(strings.ToLower(systemName), "deepin") {
backgroundFilename = "deepin_background.jpg"
themeBackgroundFilename = "deepin_background_in_theme.jpg"
} else {
backgroundFilename = "uos_background.jpg"
themeBackgroundFilename = "uos_background_in_theme.jpg"
}

backgroundFile := filepath.Join(optThemeInputDir, themeNameFallback, backgroundFilename)
themeBackgroundFile := filepath.Join(optThemeInputDir, themeNameFallback, themeBackgroundFilename)
img, err = loadImage(backgroundFile)
if err == nil {
cmdImg, err := loadImage(themeBackgroundFile)
if err == nil {
return img, cmdImg, nil
}
logger.Warning(err)
} else {
logger.Warning(err)
}

originDesktopImageFile := filepath.Join(optThemeInputDir, themeNameNormal, "background.origin.jpg")
img, err = loadImage(originDesktopImageFile)
if err != nil {
logger.Warning(err)
return nil, nil, err
}
return img, nil, nil
}

func main() {
flag.Parse()
if optVersion {
Expand Down
2 changes: 1 addition & 1 deletion adjust-grub-theme/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

package main

const VERSION int = 17
const VERSION int = 18
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dde-api (6.0.13) unstable; urgency=medium

* feat: add new grub theme.

-- xinpeng.wang <[email protected]> Wed, 25 Sep 2024 11:15:16 +0800

dde-api (6.0.12) unstable; urgency=medium

* fix: no logout sound (linuxdeepin/developer-center#9370)
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Build-Depends:
golang-gopkg-check.v1-dev,
libcairo2-dev,
libcanberra-dev,
libfreetype-dev,
libfreetype-dev | libfreetype6-dev,
libgdk-pixbuf2.0-dev,
libgtk-3-dev,
libpoppler-glib-dev,
Expand Down
2 changes: 1 addition & 1 deletion debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ adjustGrubTheme () {
fi
echo themeCurrentVersion: $themeCurrentVersion

if [ $themeToolVersion -gt $themeCurrentVersion ]; then
if [ $themeToolVersion -gt $themeCurrentVersion ] || [ ! -d "$fallbackThemeDir" ]; then
echo need adjust grub theme
$adjustGrubThemeBin -log-sys || true
update-grub || true
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed misc/data/grub-themes/deepin-fallback/menu_e.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_c.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_e.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_n.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_ne.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_nw.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_s.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_se.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_sw.png
Binary file not shown.
Binary file removed misc/data/grub-themes/deepin-fallback/select_w.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 19 additions & 23 deletions misc/data/grub-themes/deepin-fallback/theme.txt.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

# Global Property
title-text: ""
desktop-image: "background.jpg"
desktop-image: "background_in_theme.jpg"
desktop-color: "#000000"
terminal-font: "Unifont Regular 16"
terminal-font: "Unifont Regular 14"
terminal-box: "terminal_box_*.png"
terminal-left: "0"
terminal-top: "0"
Expand All @@ -15,45 +15,41 @@ terminal-border: "0"

# Show the boot menu
+ boot_menu {
left = 15%
top = 20%
width = 70%
height = 60%
left = 34%
top = 51%
width = 32%
height = 50%
item_font = "Unifont Regular 16"
item_color = "#cccccc"
selected_item_color = "#0099ff"
item_height = 24
item_spacing = 12
selected_item_pixmap_style = "select_*.png"
scrollbar_thumb = "scrollbar_thumb_*.png"
scrollbar_width = 6
menu_pixmap_style = "menu_*.png"
item_color = "#dddddd"
selected_item_color = "#ffffff"
item_height = 18
item_spacing = 25
selected_item_pixmap_style = "selected_item_*.png"
}

# Show a countdown message using the label component
+ label {
left = 0
top = 97%
width = 100%
align = "center"
id = "__timeout__"
left = 0
top = 97%
width = 100%
align = "center"
id = "__timeout__"
_text_en = "Booting in %d seconds"
# zh_CN
_text_zh_CN = "在 %d 秒内启动"
# zh_TW
_text_zh_TW = "在 %d 秒內啟動"
# zh_HK
_text_zh_HK = "在 %d 秒內啟動"
color = "#99E53E"
font = "Unifont Regular 16"
color = "#7d7d7d"
font = "Unifont Regular 16"
}

+ label {
left = 0
top = 94%
width = 100%
align = "center"
color = "#99E53E"
color = "#7d7d7d"
font = "Unifont Regular 16"
# EN
_text_en = "Use ↑ and ↓ keys to change selection, Enter to confirm, E to edit the commands before booting or C for a command-line"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57e9d8e

Please sign in to comment.