Files
clawd/lib/config.js
stswangzhiping 8f5a8ec896 fix(led): swap WiFi(play)/LAN(wifi+eth), LAN carrier via CLAWD_ETH_IFACE, faster alarm
- WifiLed drives play; LanLed drives wifi+eth pair (matches panel silkscreen)
- hasLanCableCarrier(): CLAWD_ETH_IFACE-only carrier when set (reliable unplug)
- LAN poll 1s; config.activated persisted for immediate setApps on boot/reconnect
- setApps double vfdOn alarm after 50ms for slow OpenVFD
- Clear activated + setSetup on credential errors
- install.sh env comment for CLAWD_ETH_IFACE

Made-with: Cursor
2026-03-28 21:50:56 +08:00

52 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const fs = require('fs');
const path = require('path');
const os = require('os');
// 生产环境用 /etc/clawd/,开发环境用 ~/.clawd/
const CONFIG_DIR = process.env.CLAWD_CONFIG_DIR
|| (process.getuid && process.getuid() === 0
? '/etc/clawd'
: path.join(os.homedir(), '.clawd'));
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
const DEFAULTS = {
server: 'wss://claw.cutos.ai/ws',
claw_id: null,
token: null,
heartbeat_interval: 30, // 秒
/** 云端已激活:用于启动/重连时立即点亮 alarmpwr不等首包 connected */
activated: false,
};
function load() {
try {
if (fs.existsSync(CONFIG_FILE)) {
const raw = fs.readFileSync(CONFIG_FILE, 'utf8');
return Object.assign({}, DEFAULTS, JSON.parse(raw));
}
} catch (e) {
const log = require('./logger');
log.error('config', '读取配置失败,使用默认值:', e.message);
}
return Object.assign({}, DEFAULTS);
}
function save(data) {
try {
fs.mkdirSync(CONFIG_DIR, { recursive: true });
fs.writeFileSync(CONFIG_FILE, JSON.stringify(data, null, 2), 'utf8');
} catch (e) {
const log = require('./logger');
log.error('config', '写入配置失败:', e.message);
}
}
function getConfigPath() {
return CONFIG_FILE;
}
module.exports = { load, save, getConfigPath };