Skip to content

Commit

Permalink
Fix plugin icon URLs in electron & Fix custom icon themesSigned-off-b…
Browse files Browse the repository at this point in the history
…y: Luca Jaeger <owl.jaeger@gmail.com>
  • Loading branch information
owlJaeger committed Apr 16, 2020
1 parent f691918 commit 00f0851
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v1.1.0

- [plugin-ext] fixed custom Icon Themes & plugin Icons [#7583](https://github.com/eclipse-theia/theia/pull/7583)
- [task] fixed presentation.reveal & focus for detected tasks [#7548](https://github.com/eclipse-theia/theia/pull/7548)

Breaking changes:
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Path {
} else if (path.length >= 2 && path.charCodeAt(1) === 58 /* ':' */) {
const code = path.charCodeAt(0);
if (code >= 65 /* A */ && code <= 90 /* Z */) {
path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
path = `/${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
}
}
return path;
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/common/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/

import { URI as Uri } from 'vscode-uri';
import { isWindows } from './os';
import { Path } from './path';

export default class URI {
Expand All @@ -26,7 +27,11 @@ export default class URI {
if (uri instanceof Uri) {
this.codeUri = uri;
} else {
this.codeUri = Uri.parse(uri);
if (isWindows) {
this.codeUri = Uri.parse(new Path(uri.replace(/\\/g, '/')).toString());
} else {
this.codeUri = Uri.parse(new Path(uri).toString());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { LabelProviderContribution, DidChangeLabelEvent, LabelProvider, URIIconR
import { ThemeType } from '@theia/core/lib/browser/theming';
import { FileStatNode, DirNode, FileSystemWatcher, FileChangeEvent } from '@theia/filesystem/lib/browser';
import { WorkspaceRootNode } from '@theia/navigator/lib/browser/navigator-tree';
import { Endpoint } from '@theia/core/lib/browser/endpoint';

export interface PluginIconDefinition {
iconPath: string;
Expand Down Expand Up @@ -330,7 +331,9 @@ export class PluginIconTheme extends PluginIconThemeDefinition implements IconTh
}
const iconUri = this.locationUri.resolve(iconPath);
const relativePath = this.packageUri.path.relative(iconUri.path.normalize());
return relativePath && `url('hostedPlugin/${this.pluginId}/${encodeURIComponent(relativePath.normalize().toString())}')`;
return relativePath && `url('${new Endpoint({
path: `hostedPlugin/${this.pluginId}/${encodeURIComponent(relativePath.normalize().toString())}`
}).getRestUrl().toString()}')`;
}

protected escapeCSS(value: string): string {
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-ext/src/main/browser/plugin-shared-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposa
import { ThemeService, Theme } from '@theia/core/lib/browser/theming';
import { IconUrl } from '../../common/plugin-protocol';
import { Reference, SyncReferenceCollection } from '@theia/core/lib/common/reference';
import { Endpoint } from '@theia/core/lib/browser/endpoint';

export interface PluginIconKey {
url: IconUrl
Expand Down Expand Up @@ -101,8 +102,8 @@ export class PluginSharedStyle {
protected createPluginIcon(key: PluginIconKey): PluginIcon {
const iconUrl = key.url;
const size = key.size;
const darkIconUrl = typeof iconUrl === 'object' ? iconUrl.dark : iconUrl;
const lightIconUrl = typeof iconUrl === 'object' ? iconUrl.light : iconUrl;
const darkIconUrl = new Endpoint({ path: `${typeof iconUrl === 'object' ? iconUrl.dark : iconUrl}` }).getRestUrl().toString();
const lightIconUrl = new Endpoint({ path: `${typeof iconUrl === 'object' ? iconUrl.light : iconUrl}` }).getRestUrl().toString();
const iconClass = 'plugin-icon-' + this.iconSequence++;
const toDispose = new DisposableCollection();
toDispose.push(this.insertRule('.' + iconClass, theme => `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { injectable, inject, postConstruct } from 'inversify';
import {
ApplicationShell, ViewContainer as ViewContainerWidget, WidgetManager,
ViewContainerIdentifier, ViewContainerTitleOptions, Widget, FrontendApplicationContribution,
StatefulWidget, CommonMenus, BaseWidget
StatefulWidget, CommonMenus, BaseWidget, Endpoint
} from '@theia/core/lib/browser';
import { ViewContainer, View } from '../../../common';
import { PluginSharedStyle } from '../plugin-shared-style';
Expand Down Expand Up @@ -189,9 +189,10 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}
const toDispose = new DisposableCollection();
const iconClass = 'plugin-view-container-icon-' + viewContainer.id;
const iconUrl = new Endpoint({ path: viewContainer.iconUrl }).getRestUrl().toString();
toDispose.push(this.style.insertRule('.' + iconClass, () => `
mask: url('${viewContainer.iconUrl}') no-repeat 50% 50%;
-webkit-mask: url('${viewContainer.iconUrl}') no-repeat 50% 50%;
mask: url('${iconUrl}') no-repeat 50% 50%;
-webkit-mask: url('${iconUrl}') no-repeat 50% 50%;
`));
toDispose.push(this.doRegisterViewContainer(viewContainer.id, location, {
label: viewContainer.title,
Expand Down

0 comments on commit 00f0851

Please sign in to comment.