-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: hide explorer arrows customization (#79)
- Loading branch information
Showing
13 changed files
with
195 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defu } from 'defu' | ||
import type { Theme } from '~/types' | ||
import { defaults } from '~/defaults' | ||
|
||
export function mergeTheme(configTheme: Partial<Theme>): Theme { | ||
const theme = defu(configTheme, defaults) | ||
|
||
return theme | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { window } from 'vscode' | ||
import { flavorEntries } from '@catppuccin/palette' | ||
import type { IconDefinitions, Theme, ThemePaths } from '~/types' | ||
import { createVscTheme } from '~/hooks/generateTheme' | ||
import { promptToReload, writeFile } from '~/utils/vscode' | ||
|
||
export async function updateThemes(theme: Theme, paths: ThemePaths, iconDefinitions: IconDefinitions) { | ||
const flavors = flavorEntries.map(([f]) => f) | ||
|
||
return Promise.all(flavors.map(async flavor => | ||
writeFile( | ||
paths[flavor].theme, | ||
createVscTheme(theme, iconDefinitions), | ||
), | ||
)).then(async () => { | ||
await promptToReload() | ||
}).catch((error: Error) => { | ||
window.showErrorMessage( | ||
`Failed to save re-compiled theme: \n${error.message}`, | ||
) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ConfigurationTarget, type ExtensionContext, commands, workspace } from 'vscode' | ||
import { iconDefinitionsPath, themePaths } from './utils/paths' | ||
import type { IconDefinitions } from './types' | ||
import { getConfiguration } from './utils/vscode' | ||
import { updateThemes } from './hooks/updateThemes' | ||
import { mergeTheme } from './hooks/mergeTheme' | ||
|
||
export async function activate(context: ExtensionContext) { | ||
const paths = themePaths(context) | ||
|
||
context.subscriptions.push( | ||
// TODO centralize commands and factorize reset | ||
commands.registerCommand('catppuccin-icons.reset', async () => { | ||
const iconDefinitions = await workspace.fs | ||
.readFile(iconDefinitionsPath(context)) | ||
.then(b => JSON.parse(b.toString()) as IconDefinitions) | ||
|
||
await updateThemes(mergeTheme({}), paths, iconDefinitions) | ||
|
||
const config = workspace.getConfiguration('catppuccin-icons') | ||
await config.update('hidesExplorerArrows', undefined, ConfigurationTarget.Global) | ||
}), | ||
) | ||
|
||
context.subscriptions.push( | ||
workspace.onDidChangeConfiguration(async (event) => { | ||
if (event.affectsConfiguration('catppuccin-icons')) { | ||
const iconDefinitions = await workspace.fs | ||
.readFile(iconDefinitionsPath(context)) | ||
.then(b => JSON.parse(b.toString()) as IconDefinitions) | ||
|
||
const configuration = getConfiguration() | ||
const theme = mergeTheme(configuration) | ||
|
||
await updateThemes(theme, paths, iconDefinitions) | ||
} | ||
}), | ||
) | ||
} | ||
|
||
export function deactivate() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Paths from extension context/runtime | ||
*/ | ||
import type { ExtensionContext } from 'vscode' | ||
import { Uri } from 'vscode' | ||
import type { Flavor, ThemePaths } from '~/types' | ||
|
||
function flavorThemePath(root: Uri, flavor: Flavor) { | ||
return { | ||
theme: Uri.joinPath(root, flavor, 'theme.json'), | ||
icons: Uri.joinPath(root, flavor, 'icons'), | ||
} | ||
} | ||
|
||
function rootPath(context: ExtensionContext) { | ||
return Uri.joinPath(context.extensionUri, 'dist') | ||
} | ||
|
||
export function themePaths(context: ExtensionContext): ThemePaths { | ||
const root = rootPath(context) | ||
return { | ||
frappe: flavorThemePath(root, 'frappe'), | ||
latte: flavorThemePath(root, 'latte'), | ||
macchiato: flavorThemePath(root, 'macchiato'), | ||
mocha: flavorThemePath(root, 'mocha'), | ||
} | ||
} | ||
|
||
export function iconDefinitionsPath(context: ExtensionContext) { | ||
const root = rootPath(context) | ||
return Uri.joinPath(root, 'iconDefinitions.json') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Functions to interact with VSCode window/workspace | ||
*/ | ||
import { Buffer } from 'node:buffer' | ||
import type { Uri } from 'vscode' | ||
import { commands, window, workspace } from 'vscode' | ||
import type { Config } from '~/types' | ||
|
||
export async function writeFile(uri: Uri, content: unknown) { | ||
return workspace.fs | ||
.writeFile(uri, Buffer.from(JSON.stringify(content, null, 2))) | ||
.then( | ||
() => {}, | ||
(error: Error) => { | ||
window.showErrorMessage(error.message) | ||
}, | ||
) | ||
} | ||
|
||
export async function promptToReload() { | ||
const message = `Catppuccin Icons: Theme changed - Reload required.` | ||
const action = 'Reload window' | ||
await window.showInformationMessage(message, action).then(async (selectedAction) => { | ||
if (selectedAction === action) | ||
commands.executeCommand('workbench.action.reloadWindow') | ||
}) | ||
}; | ||
|
||
export function getConfiguration(): Config { | ||
const config = workspace.getConfiguration('catppuccin-icons') | ||
|
||
return { | ||
hidesExplorerArrows: config.get('hidesExplorerArrows', false), | ||
} | ||
} |