* 解析 .desktop 文件,返回 [Desktop Entry] 部分的键值对
(content: string)
| 26 | * 解析 .desktop 文件,返回 [Desktop Entry] 部分的键值对 |
| 27 | */ |
| 28 | function 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 | * 获取本地化的应用名称 |
no outgoing calls
no test coverage detected