fix: report gateway restart progress after weixin login
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { execFileSync } = require('child_process');
|
const { execFileSync, spawnSync } = require('child_process');
|
||||||
const log = require('../logger');
|
const log = require('../logger');
|
||||||
|
|
||||||
// ── Constants (from reference script) ────────────────────────────────────────
|
// ── Constants (from reference script) ────────────────────────────────────────
|
||||||
@@ -69,6 +69,29 @@ function _ensureWeixinStateOwnership() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _restartGateway() {
|
||||||
|
try {
|
||||||
|
const result = spawnSync('openclaw gateway restart', { shell: true, stdio: 'inherit' });
|
||||||
|
if (result.status !== 0) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
code: result.status,
|
||||||
|
message: `openclaw gateway restart exited with code ${result.status}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
log.info('weixin', 'gateway restarted after login success');
|
||||||
|
return { ok: true };
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('weixin', `gateway restart after login success failed: ${err.message}`);
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
code: 1,
|
||||||
|
message: err.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _resolveWeixinStateDir() { return path.join(_resolveStateDir(), 'openclaw-weixin'); }
|
function _resolveWeixinStateDir() { return path.join(_resolveStateDir(), 'openclaw-weixin'); }
|
||||||
function _resolveAccountIndexPath(){ return path.join(_resolveWeixinStateDir(), 'accounts.json'); }
|
function _resolveAccountIndexPath(){ return path.join(_resolveWeixinStateDir(), 'accounts.json'); }
|
||||||
function _resolveAccountsDir() { return path.join(_resolveWeixinStateDir(), 'accounts'); }
|
function _resolveAccountsDir() { return path.join(_resolveWeixinStateDir(), 'accounts'); }
|
||||||
@@ -443,8 +466,23 @@ async function _runLogin({ callId, timeoutMs, botType, emit, isAborted }) {
|
|||||||
_registerAccountId(accountId);
|
_registerAccountId(accountId);
|
||||||
if (status.ilink_user_id) _clearStaleAccountsForUserId(accountId, status.ilink_user_id);
|
if (status.ilink_user_id) _clearStaleAccountsForUserId(accountId, status.ilink_user_id);
|
||||||
_bumpOpenClawConfigTimestamp();
|
_bumpOpenClawConfigTimestamp();
|
||||||
|
_ensureWeixinStateOwnership();
|
||||||
log.info('weixin', `callId=${callId} login success accountId=${accountId} file=${filePath}`);
|
log.info('weixin', `callId=${callId} login success accountId=${accountId} file=${filePath}`);
|
||||||
emit({ action: 'finish', event: 'success', data: { accountId } });
|
emit({ action: 'finish', event: 'success', data: { accountId } });
|
||||||
|
emit({
|
||||||
|
action: 'progress',
|
||||||
|
event: 'gateway_restarting',
|
||||||
|
data: {
|
||||||
|
status: 'restarting',
|
||||||
|
message: 'OpenClaw 正在重启,请稍候。',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const gatewayRestart = _restartGateway();
|
||||||
|
emit({
|
||||||
|
action: 'event',
|
||||||
|
event: gatewayRestart.ok ? 'gateway_restart_succeeded' : 'gateway_restart_failed',
|
||||||
|
data: gatewayRestart,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user