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

cache icon data optimistically like color themes #38683

Merged
merged 1 commit into from
Nov 20, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,39 @@ export class FileIconThemeData implements IFileIconTheme {
}
return themeData;
}

static fromStorageData(input: string): FileIconThemeData {
try {
let data = JSON.parse(input);
let theme = new FileIconThemeData();
for (let key in data) {
switch (key) {
case 'id':
case 'label':
case 'description':
case 'settingsId':
case 'extensionData':
case 'path':
theme[key] = data[key];
break;
}
}
return theme;
} catch (e) {
return null;
}
}

toStorageData() {
return JSON.stringify({
id: this.id,
label: this.label,
description: this.description,
settingsId: this.settingsId,
path: this.path,
extensionData: this.extensionData
});
}
}

interface IconDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json';
const DEFAULT_THEME_SETTING_VALUE = 'Default Dark+';

const PERSISTED_THEME_STORAGE_KEY = 'colorThemeData';
const PERSISTED_ICON_THEME_STORAGE_KEY = 'iconThemeData';

const defaultThemeExtensionId = 'vscode-theme-defaults';
const oldDefaultThemeExtensionId = 'vscode-theme-colorful-defaults';
Expand Down Expand Up @@ -132,6 +133,20 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.updateDynamicCSSRules(themeData);
this.applyTheme(themeData, null, true);

let iconData: FileIconThemeData = null;
let persistedIconThemeData = this.storageService.get(PERSISTED_ICON_THEME_STORAGE_KEY);
if (persistedIconThemeData) {
iconData = FileIconThemeData.fromStorageData(persistedIconThemeData);

if (iconData) {
_applyIconTheme(iconData, () => {
this.doSetFileIconTheme(iconData);

return TPromise.wrap(iconData);
});
}
}

this.initialize().then(null, errors.onUnexpectedError).then(_ => {
this.installConfigurationListener();
});
Expand Down Expand Up @@ -353,23 +368,15 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.writeFileIconConfiguration(settingsTarget);
}
let onApply = (newIconTheme: FileIconThemeData) => {
this.doSetFileIconTheme(newIconTheme);

// remember theme data for a quick restore
if (newIconTheme) {
this.currentIconTheme = newIconTheme;
this.storageService.store(PERSISTED_ICON_THEME_STORAGE_KEY, newIconTheme.toStorageData());
} else {
this.currentIconTheme = FileIconThemeData.noIconTheme();
this.storageService.remove(PERSISTED_ICON_THEME_STORAGE_KEY);
}

if (this.container) {
if (newIconTheme) {
$(this.container).addClass(fileIconsEnabledClass);
} else {
$(this.container).removeClass(fileIconsEnabledClass);
}
}
if (newIconTheme) {
this.sendTelemetry(newIconTheme.id, newIconTheme.extensionData, 'fileIcon');
}
this.onFileIconThemeChange.fire(this.currentIconTheme);
return this.writeFileIconConfiguration(settingsTarget);
};

Expand All @@ -378,6 +385,27 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
});
}

private doSetFileIconTheme(iconThemeData: FileIconThemeData): void {
if (iconThemeData) {
this.currentIconTheme = iconThemeData;
} else {
this.currentIconTheme = FileIconThemeData.noIconTheme();
}

if (this.container) {
if (iconThemeData) {
$(this.container).addClass(fileIconsEnabledClass);
} else {
$(this.container).removeClass(fileIconsEnabledClass);
}
}
if (iconThemeData) {
this.sendTelemetry(iconThemeData.id, iconThemeData.extensionData, 'fileIcon');
}
this.onFileIconThemeChange.fire(this.currentIconTheme);

}

private writeFileIconConfiguration(settingsTarget: ConfigurationTarget): TPromise<IFileIconTheme> {
if (!types.isUndefinedOrNull(settingsTarget)) {
return this.configurationWriter.writeConfiguration(ICON_THEME_SETTING, this.currentIconTheme.settingsId, settingsTarget).then(_ => this.currentIconTheme);
Expand Down