Skip to content

Commit 5fa6a65

Browse files
authored
Merge branch 'FlorianWoelki:main' into submenu
2 parents e2ce594 + 3fee512 commit 5fa6a65

File tree

11 files changed

+64
-25
lines changed

11 files changed

+64
-25
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-icon-folder",
33
"name": "Iconize",
4-
"version": "2.14.5",
4+
"version": "2.14.6",
55
"minAppVersion": "0.9.12",
66
"description": "Add icons to anything you desire in Obsidian, including files, folders, and text.",
77
"author": "Florian Woelki",

src/icon-pack-manager.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ export const initIconPacks = async (plugin: IconizePlugin): Promise<void> => {
508508
}
509509

510510
const prefix = createIconPackPrefix(folderName);
511-
if (!iconPacks.some(iconPack => iconPack.name === folderName)) {
511+
if (!iconPacks.some((iconPack) => iconPack.name === folderName)) {
512512
iconPacks.push({
513-
name: folderName,
514-
icons: loadedIcons,
515-
prefix,
516-
custom: true,
513+
name: folderName,
514+
icons: loadedIcons,
515+
prefix,
516+
custom: true,
517517
});
518518
logger.info(
519519
`Loaded icon pack '${folderName}' (amount of icons: ${loadedIcons.length})`,
@@ -533,12 +533,12 @@ export const initIconPacks = async (plugin: IconizePlugin): Promise<void> => {
533533
continue;
534534
}
535535

536-
if (!iconPacks.some(iconPack => iconPack.name === zipFile)) {
536+
if (!iconPacks.some((iconPack) => iconPack.name === zipFile)) {
537537
iconPacks.push({
538-
name: zipFile,
539-
icons: loadedIcons,
540-
prefix,
541-
custom: false,
538+
name: zipFile,
539+
icons: loadedIcons,
540+
prefix,
541+
custom: false,
542542
});
543543
logger.info(
544544
`Loaded icon pack '${zipFile}' (amount of icons: ${loadedIcons.length})`,

src/internal-plugins/bookmark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default class BookmarkInternalPlugin extends InternalPluginInjector {
137137

138138
if (requireApiVersion('1.7.2')) {
139139
// TODO: Might improve the performance here.
140-
this.leaf.loadIfDeferred().then(setBookmarkIcon);
140+
this.leaf?.loadIfDeferred().then(setBookmarkIcon);
141141
} else {
142142
setBookmarkIcon();
143143
}

src/internal-plugins/outline.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default class OutlineInternalPlugin extends InternalPluginInjector {
3838
}
3939

4040
const updateTreeItems = () => {
41+
if (!this.leaf?.view?.tree) {
42+
return;
43+
}
44+
4145
const treeItems = Array.from(
4246
this.leaf.view.tree.containerEl.querySelectorAll(`.${TREE_ITEM_CLASS}`),
4347
);

src/lib/custom-rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const getFileItems = async (
190190
): Promise<FileItem[]> => {
191191
const result: FileItem[] = [];
192192
for (const fileExplorer of plugin.getRegisteredFileExplorers()) {
193-
const files = Object.values(fileExplorer.fileItems);
193+
const files = Object.values(fileExplorer.fileItems || {});
194194
for (const fileItem of files) {
195195
if (await isApplicable(plugin, rule, fileItem.file.path)) {
196196
result.push(fileItem);

src/main.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,22 @@ export default class IconizePlugin extends Plugin {
9090
async onload() {
9191
console.log(`loading ${config.PLUGIN_NAME}`);
9292

93-
// Registers all modified internal plugins.
94-
// Only adds star plugin for obsidian under v0.12.6.
95-
if (!requireApiVersion('0.12.6')) {
96-
this.modifiedInternalPlugins.push(new StarredInternalPlugin(this));
97-
} else if (requireApiVersion('1.2.0')) {
98-
this.modifiedInternalPlugins.push(new BookmarkInternalPlugin(this));
99-
}
100-
101-
this.modifiedInternalPlugins.push(new OutlineInternalPlugin(this));
102-
10393
await this.loadIconFolderData();
10494
logger.toggleLogging(this.getSettings().debugMode);
10595
setPath(this.getSettings().iconPacksPath);
10696

97+
if (this.getSettings().useInternalPlugins) {
98+
// Registers all modified internal plugins.
99+
// Only adds star plugin for obsidian under v0.12.6.
100+
if (!requireApiVersion('0.12.6')) {
101+
this.modifiedInternalPlugins.push(new StarredInternalPlugin(this));
102+
} else if (requireApiVersion('1.2.0')) {
103+
this.modifiedInternalPlugins.push(new BookmarkInternalPlugin(this));
104+
}
105+
106+
this.modifiedInternalPlugins.push(new OutlineInternalPlugin(this));
107+
}
108+
107109
await createDefaultDirectory(this);
108110
await this.checkRecentlyUsedIcons();
109111

src/settings/data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ export interface IconFolderSettings {
180180
* in the console.
181181
*/
182182
debugMode?: boolean;
183+
/**
184+
* Adds icons to internal plugins such as the bookmarks and outline plugins.
185+
* This is experimental.
186+
* @default false
187+
*/
188+
useInternalPlugins?: boolean;
183189
}
184190

185191
export const DEFAULT_SETTINGS: IconFolderSettings = {
@@ -209,4 +215,5 @@ export const DEFAULT_SETTINGS: IconFolderSettings = {
209215
iconIdentifier: ':',
210216
lucideIconPackType: 'native',
211217
debugMode: false,
218+
useInternalPlugins: false,
212219
};

src/settings/ui/customIconRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default class CustomIconRuleSetting extends IconFolderSetting {
180180

181181
const addedPaths: string[] = [];
182182
for (const fileExplorer of this.plugin.getRegisteredFileExplorers()) {
183-
const files = Object.values(fileExplorer.fileItems);
183+
const files = Object.values(fileExplorer.fileItems || {});
184184
for (const rule of customRule.getSortedRules(this.plugin)) {
185185
// Removes the icon tabs from all opened files.
186186
this.updateIconTabs(rule, true, addedPaths);

src/settings/ui/emojiStyle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class EmojiStyleSetting extends IconFolderSetting {
2929

3030
private updateDOM(): void {
3131
for (const fileExplorer of this.plugin.getRegisteredFileExplorers()) {
32-
const fileItems = Object.entries(fileExplorer.fileItems);
32+
const fileItems = Object.entries(fileExplorer.fileItems || {});
3333
for (const [path, _] of fileItems) {
3434
let iconName = this.plugin.getData()[path] as string | undefined | null;
3535
if (!iconName) {

src/settings/ui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ToggleIconsInNotes from './toggleIconsInNotes';
1717
import ToggleIconsInLinks from './toggleIconsInLinks';
1818
import IconIdentifierSetting from './iconIdentifier';
1919
import DebugMode from './debugMode';
20+
import UseInternalPlugins from './useInternalPlugins';
2021

2122
export default class IconFolderSettings extends PluginSettingTab {
2223
private plugin: IconizePlugin;
@@ -37,6 +38,7 @@ export default class IconFolderSettings extends PluginSettingTab {
3738
new IconPacksBackgroundChecker(plugin, containerEl).display();
3839
new EmojiStyleSetting(plugin, containerEl).display();
3940
new IconIdentifierSetting(plugin, containerEl).display();
41+
new UseInternalPlugins(plugin, containerEl).display();
4042
new DebugMode(plugin, containerEl).display();
4143

4244
containerEl.createEl('h3', { text: 'Visibility of icons' });

0 commit comments

Comments
 (0)