Skip to content

Commit

Permalink
fix: use sha256 generate desktop name
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers authored and deepin-bot[bot] committed Jan 29, 2024
1 parent 16ad67d commit 0eadeba
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions keybinding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
package keybinding

import (
"crypto/sha256"
"encoding/hex"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -1139,10 +1140,17 @@ func (m *Manager) execCmd(cmd string, viaStartdde bool) error {

if m.useNewAppManager {
desktopExt := ".desktop"
name := strings.TrimSuffix(filepath.Base(cmd), path.Ext(cmd))
sha256Hasher := sha256.New()
_, err := sha256Hasher.Write([]byte(cmd))
if err != nil {
logger.Warning("generate sha256 hash failed with error: ", err)
return err
}
desktopPre := sha256Hasher.Sum(nil)
name := hex.EncodeToString(desktopPre)
desktopFileName := "daemon-keybinding-" + name + desktopExt

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

0 comments on commit 0eadeba

Please sign in to comment.