Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
167 changes: 161 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DEFAULT_SETTINGS } from '../defaultSettings';

import { writeShowMoreItemsInSelectMenus } from './showMoreItemsInSelectMenus';
import { writeThemes } from './themes';
import { writeSettingsTheme } from './settingsTheme';
import { writeContextLimit } from './contextLimit';
import { writeInputBoxBorder } from './inputBorderBox';
import { writeThinkerFormat } from './thinkerFormat';
Expand Down Expand Up @@ -212,6 +213,12 @@ const PATCH_DEFINITIONS = [
group: PatchGroup.MISC_CONFIGURABLE,
description: 'Your custom themes will be available via /theme',
},
{
id: 'settings-theme-schema',
name: 'Settings theme schema',
group: PatchGroup.MISC_CONFIGURABLE,
description: 'Allows custom theme IDs to persist in settings.json',
},
{
id: 'thinking-verbs',
name: 'Thinking verbs',
Expand Down Expand Up @@ -695,6 +702,15 @@ export const applyCustomization = async (
JSON.stringify(DEFAULT_SETTINGS.themes)
),
},
'settings-theme-schema': {
fn: c => writeSettingsTheme(c),
condition: !!(
config.settings.themes &&
config.settings.themes.length > 0 &&
JSON.stringify(config.settings.themes) !==
JSON.stringify(DEFAULT_SETTINGS.themes)
),
},
'thinking-verbs': {
fn: c => writeThinkingVerbs(c, config.settings.thinkingVerbs!.verbs),
condition: !!config.settings.thinkingVerbs,
Expand Down
38 changes: 38 additions & 0 deletions src/patches/settingsTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { globalReplace } from './index';

/**
* Widens the settings.json `theme` field schema to accept arbitrary theme IDs.
*
* CC validates the theme field against built-in IDs (enum) or a `"custom:"` prefix.
* Tweakcc custom themes use plain IDs (e.g. `"winter"`) that fail both checks;
* the `.catch(void 0)` silently resets the field on every startup, so the theme
* never persists. This patch replaces the union validator with `z.string()`.
*
* Applies to both user-settings and managed-settings schema instances (two occurrences).
*
* CC 2.1.x diff (per occurrence):
* ```
* -theme:h.union([h.enum(k7$),h.string().startsWith("custom:").transform((q)=>q)]).optional().catch(void 0)
* +theme:h.string().optional().catch(void 0)
* ```
*
* @param file - The CC bundle source as a string
* @returns The modified bundle, or null if the schema pattern was not found
*/
export const writeSettingsTheme = (file: string): string | null => {
const pattern =
/,theme:([$\w]+)\.union\(\[\1\.enum\([$\w$]+\),\1\.string\(\)\.startsWith\("[^"]*"\)\.transform\(\([^)]+\)=>[^)]+\)\]\)\.optional\(\)\.catch\(void 0\)/;

let patched = 0;
const newFile = globalReplace(file, pattern, (match, zodVar) => {
patched++;
return `,theme:${zodVar as string}.string().optional().catch(void 0)`;
});

if (patched === 0) {
console.error('patch: settingsTheme: failed to find theme schema pattern');
return null;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

return newFile;
};