Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support switch iconTheme #26

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ For the extension to work, the only thing you need to do is to set in your VSCod
{
"time": "13:03",
"theme": "Material Theme",
"iconTheme": "catppuccin-latte",
},
{
"time": "12:04",
"theme": "Monokai",
"iconTheme": "catppuccin-mocha",
},
{
"time": "00:53",
"theme": "Default Dark+",
"iconTheme": "catppuccin-mocha",
},
...
],
Expand Down
13 changes: 13 additions & 0 deletions src/ConfigurationManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as code from "vscode";

export interface MappingData {
iconTheme?: string,
theme: string;
time: string;
}
Expand All @@ -12,6 +13,18 @@ export default class ConfigurationManager {
.get<MappingData[]>("mappings");
}

/**
* Sets the global workbench iconTheme setting
* @param iconTheme To be switched to
*/
static async switchIconTheme(iconTheme: string): Promise<void> {
const config = code.workspace.getConfiguration("workbench");

if (config.get("iconTheme") !== iconTheme) {
await config.update("iconTheme", iconTheme, code.ConfigurationTarget.Global);
}
}

/**
* Sets the global workbench colorTheme setting
* @param theme To be switched to
Expand Down
7 changes: 5 additions & 2 deletions src/ThemeScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ export default class ThemeScheduler {
* @param originTask Task which originated this task
*/
private async execScheduled(
{ theme, time }: MappingData,
{ iconTheme, theme, time }: MappingData,
originTask: NodeJS.Timeout
): Promise<void> {
if (iconTheme !== undefined) {
await ConfigurationManager.switchIconTheme(iconTheme);
}
await ConfigurationManager.switchTheme(theme);
this.pendingTasks = this.pendingTasks.filter((t) => t !== originTask);

this.schedule({ theme, time }, ThemeScheduler.dayMs);
this.schedule({ iconTheme, theme, time }, ThemeScheduler.dayMs);
}

/**
Expand Down