Skip to content

Commit 0eadeba

Browse files
Decodetalkersdeepin-bot[bot]
authored andcommitted
fix: use sha256 generate desktop name
Issue: linuxdeepin/developer-center#7088 Log:
1 parent 16ad67d commit 0eadeba

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

keybinding/manager.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
package keybinding
66

77
import (
8+
"crypto/sha256"
9+
"encoding/hex"
810
"os"
911
"os/exec"
10-
"path"
1112
"path/filepath"
1213
"strings"
1314
"time"
@@ -1139,10 +1140,17 @@ func (m *Manager) execCmd(cmd string, viaStartdde bool) error {
11391140

11401141
if m.useNewAppManager {
11411142
desktopExt := ".desktop"
1142-
name := strings.TrimSuffix(filepath.Base(cmd), path.Ext(cmd))
1143+
sha256Hasher := sha256.New()
1144+
_, err := sha256Hasher.Write([]byte(cmd))
1145+
if err != nil {
1146+
logger.Warning("generate sha256 hash failed with error: ", err)
1147+
return err
1148+
}
1149+
desktopPre := sha256Hasher.Sum(nil)
1150+
name := hex.EncodeToString(desktopPre)
11431151
desktopFileName := "daemon-keybinding-" + name + desktopExt
11441152

1145-
_, err := os.Stat(basedir.GetUserDataDir() + "/applications/" + desktopFileName)
1153+
_, err = os.Stat(basedir.GetUserDataDir() + "/applications/" + desktopFileName)
11461154
// 如果对应命令的desktop文件不存在,需要新建desktop文件
11471155
if os.IsNotExist(err) {
11481156
desktopInfoMap := map[string]dbus.Variant{

0 commit comments

Comments
 (0)