mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
dock:: fix gtk gets theme icon failed.
gtk will get theme icon failed sometimes for unknown reason. just skip this error and return the icon and frontend must make a validity check for icon. Change-Id: I1ba3a1d0c420d1d50ff53f558f13fe42a557ef46
This commit is contained in:
parent
632cb1c318
commit
ffe9c0e7c7
@ -640,7 +640,8 @@ char* icon_name_to_path(const char* name, int size)
|
||||
char* pic_name = g_strndup(name, pic_name_len);
|
||||
GtkIconTheme* them = gtk_icon_theme_get_default(); //do not ref or unref it
|
||||
if (them == NULL) {
|
||||
g_debug("get theme failed");
|
||||
// NOTE: the g_message won't be recorded on log,
|
||||
g_message("error get default icon theme failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,8 @@ func get_theme_icon(name string, size int) string {
|
||||
}()
|
||||
cPath := C.icon_name_to_path(iconName, C.int(size))
|
||||
defer C.free(unsafe.Pointer(cPath))
|
||||
return C.GoString(cPath)
|
||||
path := C.GoString(cPath)
|
||||
return path
|
||||
}
|
||||
|
||||
func initDeepin() {
|
||||
|
16
dock/util.go
16
dock/util.go
@ -47,30 +47,36 @@ func getAppIcon(core *gio.DesktopAppInfo) string {
|
||||
icon := gioIcon.ToString()
|
||||
logger.Debug("GetIcon:", icon)
|
||||
if icon == "" {
|
||||
logger.Warning("get icon from theme failed")
|
||||
logger.Warning("gioIcon to string failed")
|
||||
return ""
|
||||
}
|
||||
|
||||
iconPath := get_theme_icon(icon, 48)
|
||||
if iconPath == "" {
|
||||
logger.Warning("get icon from theme failed")
|
||||
return ""
|
||||
// return a empty string might be a better idea here.
|
||||
// However, gtk will get theme icon failed sometimes for unknown reason.
|
||||
// frontend must make a validity check for icon.
|
||||
iconPath = icon
|
||||
}
|
||||
|
||||
logger.Debug("get_theme_icon:", icon)
|
||||
ext := filepath.Ext(iconPath)
|
||||
if ext == "" {
|
||||
logger.Info("get app icon:", icon)
|
||||
return icon
|
||||
}
|
||||
// the filepath.Ext return ".xxx"
|
||||
|
||||
// strip the '.' before extension name,
|
||||
// filepath.Ext function will return ".xxx"
|
||||
ext = ext[1:]
|
||||
logger.Debug("ext:", ext)
|
||||
if strings.EqualFold(ext, "xpm") {
|
||||
logger.Debug("change xpm to data uri")
|
||||
logger.Info("change xpm to data uri")
|
||||
return xpm_to_dataurl(iconPath)
|
||||
}
|
||||
|
||||
logger.Debug("get_theme_icon:", icon)
|
||||
logger.Info("get app icon:", icon)
|
||||
return icon
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user