vscode: update for cli rewrite
This commit is contained in:
parent
038e0b60ef
commit
17dabd8a47
3 changed files with 11 additions and 15 deletions
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
|||
"name": "caelestia-vscode-integration",
|
||||
"displayName": "caelestia-vscode-integration",
|
||||
"description": "VSCode integration for caelestia dotfiles",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"publisher": "soramanew",
|
||||
"engines": {
|
||||
"vscode": "^1.96.0"
|
||||
|
|
|
|||
|
|
@ -5,23 +5,20 @@ import { join } from "path";
|
|||
import { ConfigurationTarget, extensions, RelativePattern, workspace, type ExtensionContext } from "vscode";
|
||||
import theme from "./theme";
|
||||
|
||||
const statedir = () => process.env.XDG_STATE_HOME ?? join(homedir(), ".local", "state");
|
||||
const schemedir = () => join(statedir(), "caelestia", "scheme");
|
||||
const getSchemeDir = () => join(process.env.XDG_STATE_HOME ?? join(homedir(), ".local", "state"), "caelestia");
|
||||
const getSchemePath = () => join(getSchemeDir(), "scheme.json");
|
||||
|
||||
const update = async () => {
|
||||
if (!existsSync(join(schemedir(), "current.txt"))) {
|
||||
const schemePath = getSchemePath();
|
||||
|
||||
if (!existsSync(schemePath)) {
|
||||
console.log("No current scheme.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Update theme colours with scheme
|
||||
const scheme = await readFile(join(schemedir(), "current.txt"), "utf-8");
|
||||
const colours = scheme.split("\n").reduce((acc, l) => {
|
||||
const [name, hex] = l.split(" ");
|
||||
acc[name] = `#${hex}`;
|
||||
return acc;
|
||||
}, {} as { [k: string]: string });
|
||||
|
||||
const scheme = JSON.parse(await readFile(schemePath, "utf-8"));
|
||||
const colours = Object.fromEntries(Object.entries(scheme.colours).map(([n, c]) => [n, `#${c}`]));
|
||||
await writeFile(join(__dirname, "..", "themes", "caelestia.json"), JSON.stringify(theme(colours)));
|
||||
|
||||
// Sync icon theme
|
||||
|
|
@ -31,10 +28,9 @@ const update = async () => {
|
|||
/catppuccin-(latte|frappe|macchiato|mocha)/.test(workbench.get("iconTheme") ?? "") &&
|
||||
extensions.getExtension("catppuccin.catppuccin-vsc-icons")
|
||||
) {
|
||||
const colourMode = await readFile(join(schemedir(), "current-mode.txt"), "utf-8");
|
||||
workbench.update(
|
||||
"iconTheme",
|
||||
`catppuccin-${colourMode === "light" ? "latte" : "mocha"}`,
|
||||
`catppuccin-${scheme.mode === "light" ? "latte" : "mocha"}`,
|
||||
ConfigurationTarget.Global
|
||||
);
|
||||
}
|
||||
|
|
@ -44,7 +40,7 @@ const update = async () => {
|
|||
|
||||
export const activate = (context: ExtensionContext) => {
|
||||
update();
|
||||
const watcher = workspace.createFileSystemWatcher(new RelativePattern(schemedir(), "current.txt"));
|
||||
const watcher = workspace.createFileSystemWatcher(new RelativePattern(getSchemeDir(), "scheme.json"));
|
||||
context.subscriptions.push(watcher, watcher.onDidCreate(update), watcher.onDidChange(update));
|
||||
console.log(`Watching for changes to ${join(schemedir(), "current.txt")}`);
|
||||
console.log(`Watching for changes to ${getSchemePath()}`);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue