diff --git a/src/renderer/platform/desktop.js b/src/renderer/platform/desktop.js index 363d7ea..018d144 100644 --- a/src/renderer/platform/desktop.js +++ b/src/renderer/platform/desktop.js @@ -31,9 +31,12 @@ export function openHelp() { export function runCmd(cmd) { return new Promise((resolve, reject) => { + console.log('[runCmd] exec:', cmd) exec(cmd, (err, stdout, stderr) => { - // 仅按退出码判定失败;Qt 等工具常向 stderr 打警告(如 QStandardPaths) + console.log('[runCmd] done', { err: err && (err.message || err), stdout, stderr }) if (err) reject(err.message || err) + // sudo 失败常在 stderr 且 exit 0(后台 & 时) + else if (stderr && /sudo:\s*no password was provided/i.test(stderr)) reject(stderr.trim()) else resolve(stdout || '') }) }) diff --git a/src/renderer/utils/console/consoleActions.js b/src/renderer/utils/console/consoleActions.js index 6d175c0..6ba6f54 100644 --- a/src/renderer/utils/console/consoleActions.js +++ b/src/renderer/utils/console/consoleActions.js @@ -75,18 +75,31 @@ export function stopService(vm) { } export function handleActive(vm) { + const platform = vm.$platform || require('@/platform').default + const activePath = getActivePath(platform) + console.log('[激活] 点击前往激活, activePath=', activePath, 'appRoot=', platform.getAppRoot && platform.getAppRoot()) vm.$prompt('请输入管理员密码并点击确定以前往激活设备', '温馨提示', { confirmButtonText: '确定', cancelButtonText: '取消', inputType: 'password' }) .then(({ value }) => { - const activePath = getActivePath(vm.$platform || require('@/platform').default) - vm.$runCmd(`bash "${activePath}" '${String(value).replace(/'/g, `'\\''`)}'`).catch((err) => { - vm.$message({ message: err, type: 'error' }) - }) + // regist.sh 内 sudo -S 从 stdin 读密码;后台 & 会导致 stdin 为空(sudo: no password was provided) + const pass = String(value).replace(/'/g, `'\\''`) + const cmd = `( echo '${pass}' | bash ${activePath} '${pass}' ) &` + console.log('[激活] 确认密码, len=', (value || '').length, 'cmd=', cmd) + vm.$runCmd(cmd) + .then((res) => { + console.log('[激活] runCmd 成功', res) + }) + .catch((err) => { + console.log('[激活] runCmd 失败', err) + vm.$message({ message: err, type: 'error' }) + }) + }) + .catch((e) => { + console.log('[激活] 取消或关闭弹窗', e) }) - .catch(() => {}) } export function openWork(vm, platform) { diff --git a/src/renderer/views/dashboard/index.vue b/src/renderer/views/dashboard/index.vue index 8aeb6ca..a9234a2 100644 --- a/src/renderer/views/dashboard/index.vue +++ b/src/renderer/views/dashboard/index.vue @@ -897,6 +897,7 @@ export default { // 激活设备 handleActive() { let that = this + console.log('[激活] 点击前往激活, activePath=', that.activePath, 'appRoot=', platform.getAppRoot && platform.getAppRoot()) that .$prompt('请输入管理员密码并点击确定以前往激活设备', '温馨提示', { confirmButtonText: '确定', @@ -904,19 +905,25 @@ export default { inputType: 'password' }) .then(({ value }) => { + // regist.sh 内 sudo -S 从 stdin 读密码;后台 & 会导致 stdin 为空(sudo: no password was provided) + const pass = String(value).replace(/'/g, `'\\''`) + const cmd = `( echo '${pass}' | bash ${that.activePath} '${pass}' ) &` + console.log('[激活] 确认密码, len=', (value || '').length, 'cmd=', cmd) that - .$runCmd(`bash "${that.activePath}" '${String(value).replace(/'/g, `'\\''`)}'`) + .$runCmd(cmd) .then((res) => { - + console.log('[激活] runCmd 成功', res) }) .catch((err) => { + console.log('[激活] runCmd 失败', err) that.$message({ message: err, type: 'error' }) }) }) - .catch(() => { + .catch((e) => { + console.log('[激活] 取消或关闭弹窗', e) }) }, // 执行