Skip to content

Commit

Permalink
support switch iconTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhaolei committed Aug 13, 2023
1 parent d9f2891 commit 6cbe5af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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

0 comments on commit 6cbe5af

Please sign in to comment.