|
1 | | -import {ServiceManager} from './ServiceManager'; |
2 | | -import {ofetch} from 'ofetch'; |
| 1 | +import { ServiceManager } from './ServiceManager'; |
| 2 | +import { ofetch } from 'ofetch'; |
3 | 3 | import { |
4 | 4 | iconfiy_public_url, |
5 | 5 | iconify_collection_endpoint, |
6 | 6 | } from '../constants/icons'; |
7 | | -import {IconifyIconsType} from '../types/icon'; |
8 | | -import {BaseService} from './BaseService'; |
9 | | -import {applySnapshot, IDisposer, onSnapshot} from 'mobx-state-tree'; |
10 | | -import {EventEmitter, Uri, window, workspace} from 'vscode'; |
11 | | -import {escapeColor} from '../utils'; |
12 | | -import {EXTENSION_ID} from '../constants'; |
13 | | -import {IconType} from '../stores'; |
| 7 | +import { IconifyIconsType } from '../types/icon'; |
| 8 | +import { BaseService } from './BaseService'; |
| 9 | +import { applySnapshot, IDisposer, onSnapshot } from 'mobx-state-tree'; |
| 10 | +import { EventEmitter, Uri, window, workspace } from 'vscode'; |
| 11 | +import { escapeColor } from '../utils'; |
| 12 | +import { EXTENSION_ID } from '../constants'; |
| 13 | +import { IconType } from '../stores'; |
14 | 14 |
|
15 | 15 | /** |
16 | 16 | * @zh 装饰器和树上的图标服务类 |
@@ -41,7 +41,7 @@ export class IconsService extends BaseService { |
41 | 41 | // 监听插件的的`icons`的变化, 更新存储 |
42 | 42 | this._disposers.push( |
43 | 43 | onSnapshot(this.configure.configure.icons, snapshot => { |
44 | | - const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} = |
| 44 | + const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } = |
45 | 45 | this.configure.configure; |
46 | 46 | Object.entries(snapshot).forEach(([key, value], index) => { |
47 | 47 | if (!this.store.icons.find(it => it.id === value)) { |
@@ -70,7 +70,7 @@ export class IconsService extends BaseService { |
70 | 70 | ev.affectsConfiguration(`${EXTENSION_ID}.defaultBookmarkIcon`) || |
71 | 71 | ev.affectsConfiguration(`${EXTENSION_ID}.defaultLabeledBookmarkIcon`) |
72 | 72 | ) { |
73 | | - const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} = |
| 73 | + const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } = |
74 | 74 | this.configure.configure; |
75 | 75 | if (!this.store.icons.find(it => it.id === defaultBookmarkIcon)) { |
76 | 76 | this.downloadIcon(defaultBookmarkIcon, 'default:bookmark'); |
@@ -112,6 +112,10 @@ export class IconsService extends BaseService { |
112 | 112 | const response = await this.download( |
113 | 113 | `${iconfiy_public_url}/${prefix}.json?icons=${name}`, |
114 | 114 | ); |
| 115 | + if (response.name === 'FetchError') { |
| 116 | + window.showInformationMessage('Icon download failed!'); |
| 117 | + return; |
| 118 | + } |
115 | 119 | window.showInformationMessage('Icon downloaded successfully!'); |
116 | 120 | const svgBody = (response as IconifyIconsType).icons[name].body; |
117 | 121 | this.store.addNewIcon(prefix, name, svgBody, customName); |
@@ -176,7 +180,7 @@ export class IconsService extends BaseService { |
176 | 180 | for (let [key, value] of iconsValues) { |
177 | 181 | // 下载配置需要存在但不存在本地的图标数据 |
178 | 182 | if (!this.sm.store.icons.find(it => it.id === value)) { |
179 | | - toDownloadIcons.push({key, value}); |
| 183 | + toDownloadIcons.push({ key, value }); |
180 | 184 | } |
181 | 185 | } |
182 | 186 |
|
@@ -206,7 +210,7 @@ export class IconsService extends BaseService { |
206 | 210 | if (!configure) { |
207 | 211 | return; |
208 | 212 | } |
209 | | - const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} = |
| 213 | + const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } = |
210 | 214 | configure.configure; |
211 | 215 |
|
212 | 216 | await this.downloadIcon(defaultBookmarkIcon, 'default:bookmark'); |
@@ -239,7 +243,7 @@ export class IconsService extends BaseService { |
239 | 243 | } |
240 | 244 |
|
241 | 245 | let color = |
242 | | - this.store.colors.find(it => it.label === colorLabel)?.value || |
| 246 | + this.store.colors.get(colorLabel)?.value || |
243 | 247 | this.configure.configure.defaultBookmarkIconColor; |
244 | 248 |
|
245 | 249 | color = color.startsWith('#') ? escapeColor(color) : color; |
|
0 commit comments