29 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-01 17:15:44 +08:00
/*
Commands for handling configuration read and write
*/
import * as vscode from 'vscode';
import { regInMessage, regOutMessage } from '../util/reg_messages';
import { MessageHandler } from './messageHandler';
import { DevChatConfig } from '../util/config';
regInMessage({command: 'readConfig', key: ['A','B']}); // when key is "", it will get all config values
regOutMessage({command: 'readConfig', key: ['A', 'B'], value: 'any'});
2024-04-01 17:15:44 +08:00
export async function readConfig(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
if (message.key === '' || message.key === '*' || message.key.length === 0 || message.key[1] === '*') {
const config = DevChatConfig.getInstance().getAll();
2024-04-01 17:15:44 +08:00
MessageHandler.sendMessage(panel, {command: 'readConfig', key: message.key, value: config});
} else {
const config = DevChatConfig.getInstance().get(message.key);
2024-04-01 17:15:44 +08:00
MessageHandler.sendMessage(panel, {command: 'readConfig', key: message.key, value: config});
}
}
regInMessage({command: 'writeConfig', key: ['A', 'B'], value: 'any'}); // when key is "", it will rewrite all config values
2024-04-01 17:15:44 +08:00
export async function writeConfig(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
if (message.key === '' || message.key === '*' || message.key.length === 0 || message.key[1] === '*') {
DevChatConfig.getInstance().setAll(message.value);
2024-04-01 17:15:44 +08:00
} else {
DevChatConfig.getInstance().set(message.key, message.value);
2024-04-01 17:15:44 +08:00
}
}