diff --git a/CHANGELOG.md b/CHANGELOG.md index 112973b..ec2c4da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### Added + +- `AutoRun` option can now restore multiple sessions ([#28](https://github.com/argon-rbx/argon-vscode/pull/28)) + ## [2.0.8] - 2024-07-19 ### Added diff --git a/src/extension.ts b/src/extension.ts index 3869401..c15ebb0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -37,15 +37,19 @@ export async function activate(context: vscode.ExtensionContext) { state.show() if (config.autoRun()) { - const session = new RestorableSession( - context.workspaceState.get("lastSession"), - ) + const lastSessions = context.workspaceState.get("lastSessions") - if (session.isRestorable()) { - menu.restoreSession(session, state) + if (Array.isArray(lastSessions)) { + for (const lastSession of lastSessions) { + const session = new RestorableSession(lastSession) - if (config.autoLaunchStudio()) { - argon.studio(true) + if (session.isRestorable()) { + menu.restoreSession(session, state) + + if (session.needsStudio() && config.autoLaunchStudio()) { + argon.studio(true) + } + } } } } diff --git a/src/session.ts b/src/session.ts index 07c7bfb..ce0a9f1 100644 --- a/src/session.ts +++ b/src/session.ts @@ -23,7 +23,7 @@ export class Session { return this } - public equals(other: Session) { + public isSimilar(other: Session) { return this.type === other.type && this.project === other.project } } @@ -58,4 +58,8 @@ export class RestorableSession { public isRestorable() { return this.isComplete } + + public needsStudio() { + return this.type === "Serve" || this.type === "Build" + } } diff --git a/src/state.ts b/src/state.ts index a83e892..50ec9d4 100644 --- a/src/state.ts +++ b/src/state.ts @@ -28,7 +28,7 @@ export class State { } public addSession(session: Session) { - if (this.sessions.find((s) => session.equals(s))) { + if (this.sessions.find((s) => session.isSimilar(s))) { logger.warn( `Session with type: ${session.type} and project: ${session.project} is already running. Ignore this message if this is desired behavior`, ) @@ -37,30 +37,27 @@ export class State { this.sessions.push(session) this.updateItem() - this.context.workspaceState.update("lastSession", session) + this.context.workspaceState.update("lastSessions", this.sessions) } public removeSessions(ids: number[]) { - const lastSession = this.context.workspaceState.get("lastSession") + const lastSessions = this.context.workspaceState.get("lastSessions") this.sessions = this.sessions.filter((session) => { const matches = ids.includes(session.id) - if ( - matches && - lastSession instanceof Session && - session.equals(lastSession) - ) { - this.context.workspaceState.update("lastSession", undefined) + if (matches && Array.isArray(lastSessions)) { + const index = lastSessions.findIndex((s) => s === session) + + if (index > -1) { + lastSessions[index] = undefined + } } return !matches }) - if (this.sessions[0]) { - this.context.workspaceState.update("lastSession", this.sessions[0]) - } - + this.context.workspaceState.update("lastSessions", lastSessions) this.updateItem() }