Sync update: 2026-05-22 19:31:19
This commit is contained in:
@@ -253,12 +253,35 @@ for (const p of possiblePaths) {
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Clean Chrome Profile Locks ─────────────────────────────────────────────
|
||||
function cleanChromeLocks(sessionPath) {
|
||||
const lockFiles = [
|
||||
path.join(sessionPath, 'SingletonLock'),
|
||||
path.join(sessionPath, 'Default', 'SingletonLock')
|
||||
];
|
||||
for (const lockFile of lockFiles) {
|
||||
try {
|
||||
if (fs.existsSync(lockFile)) {
|
||||
console.log(`[CLEANUP] Removing dangling lock file: ${lockFile}`);
|
||||
fs.unlinkSync(lockFile);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(`[CLEANUP WARNING] Could not remove lock file ${lockFile}:`, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Bootstrap Slot ────────────────────────────────────────────────────────
|
||||
function bootstrapSlot(slotId) {
|
||||
if (slotId < 1 || slotId > 6) return;
|
||||
if (slots.has(slotId)) return slots.get(slotId);
|
||||
|
||||
console.log(`[BOOTSTRAP] Initializing Slot ${slotId}...`);
|
||||
|
||||
// Clean dangling lock files before launching Puppeteer
|
||||
const sessionPath = path.join(__dirname, '.wwebjs_auth', `session-slot-${slotId}`);
|
||||
cleanChromeLocks(sessionPath);
|
||||
|
||||
const { Client, LocalAuth } = require('whatsapp-web.js');
|
||||
|
||||
const client = new Client({
|
||||
@@ -778,6 +801,8 @@ server.listen(PORT, async () => {
|
||||
if (!fs.existsSync(slot1SessionPath)) {
|
||||
for (const oldPath of oldSessionPaths) {
|
||||
if (fs.existsSync(oldPath)) {
|
||||
// Clean lock files in the old session directory first
|
||||
cleanChromeLocks(oldPath);
|
||||
console.log(`[MIGRATION] Migrating active WhatsApp session from ${oldPath} to Slot 1...`);
|
||||
try {
|
||||
if (fs.cpSync) {
|
||||
@@ -786,6 +811,8 @@ server.listen(PORT, async () => {
|
||||
const { execSync } = require('child_process');
|
||||
execSync(`cp -R "${oldPath}" "${slot1SessionPath}"`);
|
||||
}
|
||||
// Clean lock files in the new slot-1 session directory too
|
||||
cleanChromeLocks(slot1SessionPath);
|
||||
console.log('[MIGRATION] Session migrated successfully! Slot 1 will load connected.');
|
||||
break;
|
||||
} catch (migrationErr) {
|
||||
|
||||
Reference in New Issue
Block a user