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';
|
|
|
|
|
2024-04-01 17:15:44 +08:00
|
|
|
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> {
|
2024-04-01 17:15:44 +08:00
|
|
|
if (message.key === '' || message.key === '*' || message.key.length === 0 || message.key[1] === '*') {
|
2024-04-17 00:07:09 +08:00
|
|
|
const config = DevChatConfig.getInstance().getAll();
|
2024-04-01 17:15:44 +08:00
|
|
|
MessageHandler.sendMessage(panel, {command: 'readConfig', key: message.key, value: config});
|
|
|
|
} else {
|
2024-04-17 00:07:09 +08:00
|
|
|
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});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-01 17:15:44 +08:00
|
|
|
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> {
|
2024-04-01 17:15:44 +08:00
|
|
|
if (message.key === '' || message.key === '*' || message.key.length === 0 || message.key[1] === '*') {
|
2024-04-17 00:07:09 +08:00
|
|
|
DevChatConfig.getInstance().setAll(message.value);
|
2024-04-01 17:15:44 +08:00
|
|
|
} else {
|
2024-04-17 00:07:09 +08:00
|
|
|
DevChatConfig.getInstance().set(message.key, message.value);
|
2024-04-01 17:15:44 +08:00
|
|
|
}
|
|
|
|
}
|