修复 Linux 端 hostnamectl 命令不可用时无法与手机端同步的问题 (#1784)

* Don't fail to sync without hostnamectl

* update

---------

Co-authored-by: lyswhut <lyswhut@qq.com>
pull/1460/merge
SamLukeYes 2024-02-15 00:00:14 +08:00 committed by GitHub
parent 79d8d79b9d
commit 15c9207542
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 3 deletions

View File

@ -31,11 +31,15 @@ export const getComputerName = () => {
name = process.env.COMPUTERNAME
break
case 'darwin':
try {
name = cp.execSync('scutil --get ComputerName').toString().trim()
} catch {}
break
case 'linux':
// Don't fail even if hostnamectl is unavailable
try {
name = cp.execSync('hostnamectl --pretty').toString().trim()
break
} catch {}
}
if (!name) name = os.hostname()
return name