feat: unify cron delivery account and target selection (#642)
This commit is contained in:
committed by
GitHub
Unverified
parent
9aea3c9441
commit
9d40e1fa05
@@ -2,11 +2,14 @@
|
||||
* Path Utilities
|
||||
* Cross-platform path resolution helpers
|
||||
*/
|
||||
import { app } from 'electron';
|
||||
import { createRequire } from 'node:module';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { existsSync, mkdirSync, readFileSync, realpathSync } from 'fs';
|
||||
import { logger } from './logger';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
type ElectronAppLike = Pick<typeof import('electron').app, 'isPackaged' | 'getPath' | 'getAppPath'>;
|
||||
|
||||
export {
|
||||
quoteForCmd,
|
||||
@@ -16,6 +19,24 @@ export {
|
||||
appendNodeRequireToNodeOptions,
|
||||
} from './win-shell';
|
||||
|
||||
function getElectronApp() {
|
||||
if (process.versions?.electron) {
|
||||
return (require('electron') as typeof import('electron')).app;
|
||||
}
|
||||
|
||||
const fallbackUserData = process.env.CLAWX_USER_DATA_DIR?.trim() || join(homedir(), '.clawx');
|
||||
const fallbackAppPath = process.cwd();
|
||||
const fallbackApp: ElectronAppLike = {
|
||||
isPackaged: false,
|
||||
getPath: (name) => {
|
||||
if (name === 'userData') return fallbackUserData;
|
||||
return fallbackUserData;
|
||||
},
|
||||
getAppPath: () => fallbackAppPath,
|
||||
};
|
||||
return fallbackApp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand ~ to home directory
|
||||
*/
|
||||
@@ -51,14 +72,14 @@ export function getClawXConfigDir(): string {
|
||||
* Get ClawX logs directory
|
||||
*/
|
||||
export function getLogsDir(): string {
|
||||
return join(app.getPath('userData'), 'logs');
|
||||
return join(getElectronApp().getPath('userData'), 'logs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ClawX data directory
|
||||
*/
|
||||
export function getDataDir(): string {
|
||||
return app.getPath('userData');
|
||||
return getElectronApp().getPath('userData');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +95,7 @@ export function ensureDir(dir: string): void {
|
||||
* Get resources directory (for bundled assets)
|
||||
*/
|
||||
export function getResourcesDir(): string {
|
||||
if (app.isPackaged) {
|
||||
if (getElectronApp().isPackaged) {
|
||||
return join(process.resourcesPath, 'resources');
|
||||
}
|
||||
return join(__dirname, '../../resources');
|
||||
@@ -93,7 +114,7 @@ export function getPreloadPath(): string {
|
||||
* - Development: from node_modules/openclaw
|
||||
*/
|
||||
export function getOpenClawDir(): string {
|
||||
if (app.isPackaged) {
|
||||
if (getElectronApp().isPackaged) {
|
||||
return join(process.resourcesPath, 'openclaw');
|
||||
}
|
||||
// Development: use node_modules/openclaw
|
||||
@@ -127,7 +148,7 @@ export function getOpenClawEntryPath(): string {
|
||||
* Get ClawHub CLI entry script path (clawdhub.js)
|
||||
*/
|
||||
export function getClawHubCliEntryPath(): string {
|
||||
return join(app.getAppPath(), 'node_modules', 'clawhub', 'bin', 'clawdhub.js');
|
||||
return join(getElectronApp().getAppPath(), 'node_modules', 'clawhub', 'bin', 'clawdhub.js');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +156,7 @@ export function getClawHubCliEntryPath(): string {
|
||||
*/
|
||||
export function getClawHubCliBinPath(): string {
|
||||
const binName = process.platform === 'win32' ? 'clawhub.cmd' : 'clawhub';
|
||||
return join(app.getAppPath(), 'node_modules', '.bin', binName);
|
||||
return join(getElectronApp().getAppPath(), 'node_modules', '.bin', binName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,6 +213,11 @@ export function getOpenClawStatus(): OpenClawStatus {
|
||||
version,
|
||||
};
|
||||
|
||||
logger.info('OpenClaw status:', status);
|
||||
try {
|
||||
const { logger } = require('./logger') as typeof import('./logger');
|
||||
logger.info('OpenClaw status:', status);
|
||||
} catch {
|
||||
// Ignore logger bootstrap issues in non-Electron contexts such as unit tests.
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto';
|
||||
import { chmod, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { join } from 'node:path';
|
||||
import { deflateSync } from 'node:zlib';
|
||||
import { normalizeOpenClawAccountId } from './channel-alias';
|
||||
import { getOpenClawResolvedDir } from './paths';
|
||||
@@ -18,9 +18,22 @@ const WECHAT_STATE_DIR = join(OPENCLAW_DIR, 'openclaw-weixin');
|
||||
const WECHAT_ACCOUNT_INDEX_FILE = join(WECHAT_STATE_DIR, 'accounts.json');
|
||||
const WECHAT_ACCOUNTS_DIR = join(WECHAT_STATE_DIR, 'accounts');
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
type QrCodeMatrix = {
|
||||
addData(input: string): void;
|
||||
make(): void;
|
||||
getModuleCount(): number;
|
||||
isDark(row: number, col: number): boolean;
|
||||
};
|
||||
|
||||
type QrCodeConstructor = new (typeNumber: number, errorCorrectionLevel: unknown) => QrCodeMatrix;
|
||||
type QrErrorCorrectLevelModule = {
|
||||
L: unknown;
|
||||
};
|
||||
|
||||
type QrRenderDeps = {
|
||||
QRCode: typeof import('qrcode-terminal/vendor/QRCode/index.js');
|
||||
QRErrorCorrectLevel: typeof import('qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js');
|
||||
QRCode: QrCodeConstructor;
|
||||
QRErrorCorrectLevel: QrErrorCorrectLevelModule;
|
||||
};
|
||||
|
||||
let qrRenderDeps: QrRenderDeps | null = null;
|
||||
@@ -31,10 +44,11 @@ function getQrRenderDeps(): QrRenderDeps {
|
||||
}
|
||||
|
||||
const openclawRequire = createRequire(join(getOpenClawResolvedDir(), 'package.json'));
|
||||
const qrcodeTerminalPath = dirname(openclawRequire.resolve('qrcode-terminal/package.json'));
|
||||
const qrCodeModulePath = openclawRequire.resolve('qrcode-terminal/vendor/QRCode/index.js');
|
||||
const qrErrorCorrectLevelPath = openclawRequire.resolve('qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js');
|
||||
qrRenderDeps = {
|
||||
QRCode: require(join(qrcodeTerminalPath, 'vendor', 'QRCode', 'index.js')),
|
||||
QRErrorCorrectLevel: require(join(qrcodeTerminalPath, 'vendor', 'QRCode', 'QRErrorCorrectLevel.js')),
|
||||
QRCode: require(qrCodeModulePath),
|
||||
QRErrorCorrectLevel: require(qrErrorCorrectLevelPath),
|
||||
};
|
||||
return qrRenderDeps;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ function resolveOpenClawPackageJson(packageName: string): string {
|
||||
}
|
||||
|
||||
const baileysPath = dirname(resolveOpenClawPackageJson('@whiskeysockets/baileys'));
|
||||
const qrcodeTerminalPath = dirname(resolveOpenClawPackageJson('qrcode-terminal'));
|
||||
const qrCodeModulePath = openclawRequire.resolve('qrcode-terminal/vendor/QRCode/index.js');
|
||||
const qrErrorCorrectLevelPath = openclawRequire.resolve('qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js');
|
||||
|
||||
// Load Baileys dependencies dynamically
|
||||
const {
|
||||
@@ -39,8 +40,8 @@ const {
|
||||
} = require(baileysPath);
|
||||
|
||||
// Load QRCode dependencies dynamically
|
||||
const QRCodeModule = require(join(qrcodeTerminalPath, 'vendor', 'QRCode', 'index.js'));
|
||||
const QRErrorCorrectLevelModule = require(join(qrcodeTerminalPath, 'vendor', 'QRCode', 'QRErrorCorrectLevel.js'));
|
||||
const QRCodeModule = require(qrCodeModulePath);
|
||||
const QRErrorCorrectLevelModule = require(qrErrorCorrectLevelPath);
|
||||
|
||||
// Types from Baileys (approximate since we don't have types for dynamic require)
|
||||
interface BaileysError extends Error {
|
||||
@@ -438,4 +439,4 @@ export class WhatsAppLoginManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
export const whatsAppLoginManager = new WhatsAppLoginManager();
|
||||
export const whatsAppLoginManager = new WhatsAppLoginManager();
|
||||
|
||||
Reference in New Issue
Block a user