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

fix: make icon theme apply correctly #775

Merged
merged 1 commit into from
Apr 2, 2022
Merged
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
17 changes: 15 additions & 2 deletions packages/theme/src/browser/icon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
IconThemeInfo,
} from '../common';


import { IconThemeStore } from './icon-theme-store';

import './icon.less';
Expand Down Expand Up @@ -62,6 +61,7 @@ export class IconService implements IIconService {

public currentThemeId: string;
public currentTheme: IIconTheme;
private latestApplyTheme: string;

private iconMap: Map<string, string> = new Map();

Expand Down Expand Up @@ -321,9 +321,22 @@ export class IconService implements IIconService {
if (this.currentTheme && this.currentThemeId === themeId) {
return;
}
/**
* 这里 `applyTheme` 默认应该按照最后一个应用的主题进行加载
* 但由于 `getIconTheme` 存在时序问题,例如:
* 主题 A,E,分别由插件 A,E 贡献
* 这里先调用 applyTheme(E), 再调用 applyTheme(A)
* 旧的逻辑由于插件 A ... E 的加载顺序问题,会存在 A 比 E 快加载的情况导致最终应用了错误的主题
*
* 故这里增加额外判断,保障最后一个加载的主题应用
*/
this.latestApplyTheme = themeId;
const iconThemeData = await this.getIconTheme(themeId);
if (this.latestApplyTheme !== themeId) {
return;
}
if (!iconThemeData) {
this.logger.warn('没有检测到目标图标主题插件,使用内置图标!');
this.logger.warn('Target IconTheme extension not detected, use built-in icons.');
document.getElementsByTagName('body')[0].classList.add('default-file-icons');
return;
}
Expand Down
17 changes: 14 additions & 3 deletions packages/theme/src/browser/workbench.theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ import {
colorIdPattern,
} from '../common/theme.service';


import { ThemeData } from './theme-data';
import { ThemeStore } from './theme-store';


export const CUSTOM_WORKBENCH_COLORS_SETTING = 'workbench.colorCustomizations';
export const CUSTOM_EDITOR_COLORS_SETTING = 'editor.tokenColorCustomizations';
export const COLOR_THEME_SETTING = 'general.theme';
Expand All @@ -72,6 +70,7 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService

public currentThemeId: string;
private currentTheme?: Theme;
private latestApplyTheme: string;

private themes: Map<string, ThemeData> = new Map();
private themeContributionRegistry: Map<string, { contribution: ThemeContribution; basePath: URI }> = new Map();
Expand Down Expand Up @@ -168,8 +167,20 @@ export class WorkbenchThemeService extends WithEventBus implements IThemeService

const prevThemeType = this.currentTheme ? this.currentTheme.type : 'dark';
this.currentThemeId = themeId;

/**
* 这里 `applyTheme` 默认应该按照最后一个应用的主题进行加载
* 但由于 `getTheme` 存在时序问题,例如:
* 主题 A,E,分别由插件 A,E 贡献
* 这里先调用 applyTheme(E), 再调用 applyTheme(A)
* 旧的逻辑由于插件 A ... E 的加载顺序问题,会存在 A 比 E 快加载的情况导致最终应用了错误的主题
*
* 故这里增加额外判断,保障最后一个加载的主题应用
*/
this.latestApplyTheme = themeId;
const theme = await this.getTheme(themeId);
if (this.latestApplyTheme !== themeId) {
return;
}
const themeType = getThemeType(theme.base);

this.currentTheme = new Theme(themeType, theme);
Expand Down