Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 18 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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}`);
}
Expand Down