mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-13 22:29:48 +08:00
fix(baoyu-post-to-x): fix Chrome launch on macOS and cover image path resolution
Use open -na on macOS to avoid process blocking; resolve relative cover image paths to absolute paths.
This commit is contained in:
@@ -109,7 +109,7 @@ export async function publishArticle(options: ArticleOptions): Promise<void> {
|
|||||||
console.log(`[x-article] Reusing existing Chrome instance on port ${port}`);
|
console.log(`[x-article] Reusing existing Chrome instance on port ${port}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`[x-article] Launching Chrome...`);
|
console.log(`[x-article] Launching Chrome...`);
|
||||||
spawn(chromePath, [
|
const chromeArgs = [
|
||||||
`--remote-debugging-port=${port}`,
|
`--remote-debugging-port=${port}`,
|
||||||
`--user-data-dir=${profileDir}`,
|
`--user-data-dir=${profileDir}`,
|
||||||
'--no-first-run',
|
'--no-first-run',
|
||||||
@@ -117,7 +117,13 @@ export async function publishArticle(options: ArticleOptions): Promise<void> {
|
|||||||
'--disable-blink-features=AutomationControlled',
|
'--disable-blink-features=AutomationControlled',
|
||||||
'--start-maximized',
|
'--start-maximized',
|
||||||
X_ARTICLES_URL,
|
X_ARTICLES_URL,
|
||||||
], { stdio: 'ignore' });
|
];
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
const appPath = chromePath.replace(/\/Contents\/MacOS\/Google Chrome$/, '');
|
||||||
|
spawn('open', ['-na', appPath, '--args', ...chromeArgs], { stdio: 'ignore' });
|
||||||
|
} else {
|
||||||
|
spawn(chromePath, chromeArgs, { stdio: 'ignore' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cdp: CdpConnection | null = null;
|
let cdp: CdpConnection | null = null;
|
||||||
@@ -732,7 +738,8 @@ async function main(): Promise<void> {
|
|||||||
if (arg === '--title' && args[i + 1]) {
|
if (arg === '--title' && args[i + 1]) {
|
||||||
title = args[++i];
|
title = args[++i];
|
||||||
} else if (arg === '--cover' && args[i + 1]) {
|
} else if (arg === '--cover' && args[i + 1]) {
|
||||||
coverImage = args[++i];
|
const raw = args[++i]!;
|
||||||
|
coverImage = path.isAbsolute(raw) ? raw : path.resolve(process.cwd(), raw);
|
||||||
} else if (arg === '--submit') {
|
} else if (arg === '--submit') {
|
||||||
submit = true;
|
submit = true;
|
||||||
} else if (arg === '--profile' && args[i + 1]) {
|
} else if (arg === '--profile' && args[i + 1]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user