mirror of
				https://github.com/SikongJueluo/cc-utils.git
				synced 2025-11-04 19:27:50 +08:00 
			
		
		
		
	fix: save failed
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
import * as dkjson from "@sikongjueluo/dkjson-types";
 | 
			
		||||
// import * as dkjson from "@sikongjueluo/dkjson-types";
 | 
			
		||||
 | 
			
		||||
interface ToastConfig {
 | 
			
		||||
  title: MinecraftTextComponent;
 | 
			
		||||
@@ -131,9 +131,12 @@ function loadConfig(filepath: string): AccessConfig {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function saveConfig(config: AccessConfig, filepath: string) {
 | 
			
		||||
  const configJson = dkjson.encode(config, { indent: true }) as string;
 | 
			
		||||
  // const configJson = dkjson.encode(config, { indent: true }) as string;
 | 
			
		||||
  // Not use external lib
 | 
			
		||||
  // const configJson = textutils.serializeJSON(config, { unicode_strings: true });
 | 
			
		||||
  const configJson = textutils.serializeJSON(config, {
 | 
			
		||||
    allow_repetitions: true,
 | 
			
		||||
    unicode_strings: true,
 | 
			
		||||
  });
 | 
			
		||||
  if (configJson == undefined) {
 | 
			
		||||
    print("Failed to save config");
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
 * A text-based user interface for configuring access control settings
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { context } from "@/lib/ccTUI/context";
 | 
			
		||||
import {
 | 
			
		||||
  createSignal,
 | 
			
		||||
  createStore,
 | 
			
		||||
@@ -46,8 +47,11 @@ interface ErrorState {
 | 
			
		||||
 * Main TUI Application Component
 | 
			
		||||
 */
 | 
			
		||||
const AccessControlTUI = () => {
 | 
			
		||||
  // Load configuration on initialization
 | 
			
		||||
  const configFilepath = `${shell.dir()}/access.config.json`;
 | 
			
		||||
  const loadedConfig = loadConfig(configFilepath);
 | 
			
		||||
  // Configuration state
 | 
			
		||||
  const [config, setConfig] = createStore<AccessConfig>({} as AccessConfig);
 | 
			
		||||
  const [config, setConfig] = createStore<AccessConfig>(loadedConfig);
 | 
			
		||||
 | 
			
		||||
  // UI state
 | 
			
		||||
  const [currentTab, setCurrentTab] = createSignal<TabIndex>(TABS.BASIC);
 | 
			
		||||
@@ -60,11 +64,6 @@ const AccessControlTUI = () => {
 | 
			
		||||
  // New user input for group management
 | 
			
		||||
  const [newUserName, setNewUserName] = createSignal("");
 | 
			
		||||
 | 
			
		||||
  // Load configuration on initialization
 | 
			
		||||
  const configFilepath = `${shell.dir()}/access.config.json`;
 | 
			
		||||
  const loadedConfig = loadConfig(configFilepath);
 | 
			
		||||
  setConfig(() => loadedConfig);
 | 
			
		||||
 | 
			
		||||
  // Tab navigation functions
 | 
			
		||||
  const tabNames = ["Basic", "Groups", "Welcome", "Warn", "Notice"];
 | 
			
		||||
 | 
			
		||||
@@ -165,6 +164,9 @@ const AccessControlTUI = () => {
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // Save configuration
 | 
			
		||||
      context.logger?.debug(
 | 
			
		||||
        `Configuration : ${textutils.serialise(currentConfig, { allow_repetitions: true })}`,
 | 
			
		||||
      );
 | 
			
		||||
      saveConfig(currentConfig, configFilepath);
 | 
			
		||||
      showError("Configuration saved successfully!");
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user