From 6bec359bf651e0d590638331b85c255d95e050bf Mon Sep 17 00:00:00 2001 From: shaobeichen Date: Tue, 29 Oct 2024 15:22:30 +0800 Subject: [PATCH] feat: support user custom gradient theme --- package.json | 19 +++++++++++++++++-- src/extension.js | 18 ++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6dbd90e..59a6108 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,22 @@ "command": "extension.disable", "title": "Gradient Theme: Disable Gradient" } - ] + ], + "configuration": { + "title": "Gradient Theme", + "properties": { + "gradientTheme.css": { + "type": "array", + "default": [ + { + "enable": false, + "css": "" + } + ], + "description": "custom css for the gradient theme" + } + } + } }, "activationEvents": [ "onCommand:extension.enable", @@ -91,4 +106,4 @@ "vsce": { "dependencies": false } -} +} \ No newline at end of file diff --git a/src/extension.js b/src/extension.js index a0d0a19..1fdae02 100644 --- a/src/extension.js +++ b/src/extension.js @@ -69,12 +69,26 @@ function reset() { } function install() { + const themeConfig = vscode.workspace.getConfiguration('gradientTheme') + const css = themeConfig ? themeConfig.css : [] + const customCssOutHtml = css + .filter((item) => item.enable) + .reduce((prev, cur) => { + return ( + prev + + ` + + ` + ) + }, '') + const distIndexHtmlFile = path.join(__dirname, '../dist/index.html') const html = getResetContent() const styleHtml = fs.readFileSync(distIndexHtmlFile, 'utf-8') - const output = html.replace('', '') + styleHtml + '' + const output = html.replace('', '') + customCssOutHtml + styleHtml + '' fs.writeFileSync(htmlFile, output, 'utf-8') - showReloadMessage(enableMessage) }