chore(window): avoid reduce error when no candidates

This commit is contained in:
SiriusXT 2025-12-29 16:08:29 +08:00
parent 0af7b8b145
commit 2e30683b7b

View File

@ -144,10 +144,12 @@ export default class TabManager extends Component {
// Filter out the oldest entry (excluding the main window)
if (savedWindows?.length >= MAX_SAVED_WINDOWS) {
const candidates = savedWindows.filter(w => w.windowId !== "main");
const oldest = candidates.reduce((a, b) =>
a.createdAt < b.createdAt ? a : b
);
savedWindows.splice(savedWindows.indexOf(oldest), 1);
if (candidates.length > 0) {
const oldest = candidates.reduce((a, b) =>
a.createdAt < b.createdAt ? a : b
);
savedWindows.splice(savedWindows.indexOf(oldest), 1);
}
}
savedWindows.push({
windowId: appContext.windowId,