MCPcopy Create free account
hub / github.com/ZToolsCenter/ZTools / parseDesktopFile

Function parseDesktopFile

src/main/core/commandScanner/linuxScanner.ts:28–56  ·  view source on GitHub ↗

* 解析 .desktop 文件,返回 [Desktop Entry] 部分的键值对

(content: string)

Source from the content-addressed store, hash-verified

26 * 解析 .desktop 文件,返回 [Desktop Entry] 部分的键值对
27 */
28function parseDesktopFile(content: string): DesktopEntry {
29 const result: DesktopEntry = {}
30 let inDesktopEntry = false
31
32 for (const rawLine of content.split('\n')) {
33 const line = rawLine.trim()
34
35 if (line === '[Desktop Entry]') {
36 inDesktopEntry = true
37 continue
38 }
39
40 // 遇到下一个 section 停止解析
41 if (line.startsWith('[') && line.endsWith(']') && inDesktopEntry) {
42 break
43 }
44
45 if (!inDesktopEntry || !line || line.startsWith('#')) continue
46
47 const eqIdx = line.indexOf('=')
48 if (eqIdx === -1) continue
49
50 const key = line.slice(0, eqIdx).trim()
51 const value = line.slice(eqIdx + 1).trim()
52 result[key] = value
53 }
54
55 return result
56}
57
58/**
59 * 获取本地化的应用名称

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected