diff --git a/package.json b/package.json index 2243916..bd9535b 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ "title": "Multi-Build: Reconnect" }, { - "command": "multiBuild.showRoomId", - "title": "Multi-Build: Show/Edit Room ID" + "command": "multiBuild.configure", + "title": "Multi-Build: Configure" } ], "configuration": { diff --git a/src/extension.ts b/src/extension.ts index fa312a4..8b37174 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,7 +11,7 @@ const serverConfigKey = "multiBuild.server"; const syncDataConfigKey = "multiBuild.syncData"; const reconnectCommand = `multiBuild.reconnect`; const syncCommand = `multiBuild.sync`; -const showRoomIdCommand = "multiBuild.showRoomId"; +const configureCommand = "multiBuild.configure"; const defaultBaseUrl = "wss://multi-build-server.symless.workers.dev"; const keepAliveIntervalMillis = 10000; // 10 seconds @@ -20,6 +20,11 @@ var activeSocket: WebSocket | undefined; var keepAlive: NodeJS.Timeout | undefined; var connected = false; +interface ServerConfig { + baseUrl: string; + roomId: string | null; +} + export function activate(context: vscode.ExtensionContext) { init().catch((error) => { handleError(error); @@ -49,18 +54,21 @@ export function activate(context: vscode.ExtensionContext) { // Register command to show and edit the current room ID context.subscriptions.push( - vscode.commands.registerCommand(showRoomIdCommand, async () => { - const config = await getServerConfig(); - const roomId = await showRoomIdPrompt(config.roomId); - if (roomId !== config.roomId) { - await updateServerConfig({ ...config, roomId }); - } else { - vscode.window.showInformationMessage(`${extensionName}: Room ID did not change`); - } + vscode.commands.registerCommand(configureCommand, async () => { + await configure(await getServerConfig()); }), ); } +async function configure(config: ServerConfig) { + const roomId = await showRoomIdPrompt(config.roomId); + if (roomId) { + await updateServerConfig({ ...config, roomId }); + } else { + vscode.window.showErrorMessage(`${extensionName}: No room ID provided`); + } +} + export function deactivate() { try { stopConfigWatcher(); @@ -82,8 +90,7 @@ async function init() { console.log(`${logTag} Server config:`, config); if (!config.roomId) { - const roomId = await showRoomIdPrompt(config.roomId); - await updateServerConfig({ ...config, roomId }); + await configure(config); } else { console.log(`${logTag} Using existing room ID: ${config.roomId}`); }