Skip to content

Commit

Permalink
Merge branch 'FlorianWoelki:main' into submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li authored Dec 4, 2024
2 parents e2ce594 + 3fee512 commit 5fa6a65
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-icon-folder",
"name": "Iconize",
"version": "2.14.5",
"version": "2.14.6",
"minAppVersion": "0.9.12",
"description": "Add icons to anything you desire in Obsidian, including files, folders, and text.",
"author": "Florian Woelki",
Expand Down
20 changes: 10 additions & 10 deletions src/icon-pack-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ export const initIconPacks = async (plugin: IconizePlugin): Promise<void> => {
}

const prefix = createIconPackPrefix(folderName);
if (!iconPacks.some(iconPack => iconPack.name === folderName)) {
if (!iconPacks.some((iconPack) => iconPack.name === folderName)) {
iconPacks.push({
name: folderName,
icons: loadedIcons,
prefix,
custom: true,
name: folderName,
icons: loadedIcons,
prefix,
custom: true,
});
logger.info(
`Loaded icon pack '${folderName}' (amount of icons: ${loadedIcons.length})`,
Expand All @@ -533,12 +533,12 @@ export const initIconPacks = async (plugin: IconizePlugin): Promise<void> => {
continue;
}

if (!iconPacks.some(iconPack => iconPack.name === zipFile)) {
if (!iconPacks.some((iconPack) => iconPack.name === zipFile)) {
iconPacks.push({
name: zipFile,
icons: loadedIcons,
prefix,
custom: false,
name: zipFile,
icons: loadedIcons,
prefix,
custom: false,
});
logger.info(
`Loaded icon pack '${zipFile}' (amount of icons: ${loadedIcons.length})`,
Expand Down
2 changes: 1 addition & 1 deletion src/internal-plugins/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default class BookmarkInternalPlugin extends InternalPluginInjector {

if (requireApiVersion('1.7.2')) {
// TODO: Might improve the performance here.
this.leaf.loadIfDeferred().then(setBookmarkIcon);
this.leaf?.loadIfDeferred().then(setBookmarkIcon);
} else {
setBookmarkIcon();
}
Expand Down
4 changes: 4 additions & 0 deletions src/internal-plugins/outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class OutlineInternalPlugin extends InternalPluginInjector {
}

const updateTreeItems = () => {
if (!this.leaf?.view?.tree) {
return;
}

const treeItems = Array.from(
this.leaf.view.tree.containerEl.querySelectorAll(`.${TREE_ITEM_CLASS}`),
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/custom-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const getFileItems = async (
): Promise<FileItem[]> => {
const result: FileItem[] = [];
for (const fileExplorer of plugin.getRegisteredFileExplorers()) {
const files = Object.values(fileExplorer.fileItems);
const files = Object.values(fileExplorer.fileItems || {});
for (const fileItem of files) {
if (await isApplicable(plugin, rule, fileItem.file.path)) {
result.push(fileItem);
Expand Down
22 changes: 12 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,22 @@ export default class IconizePlugin extends Plugin {
async onload() {
console.log(`loading ${config.PLUGIN_NAME}`);

// Registers all modified internal plugins.
// Only adds star plugin for obsidian under v0.12.6.
if (!requireApiVersion('0.12.6')) {
this.modifiedInternalPlugins.push(new StarredInternalPlugin(this));
} else if (requireApiVersion('1.2.0')) {
this.modifiedInternalPlugins.push(new BookmarkInternalPlugin(this));
}

this.modifiedInternalPlugins.push(new OutlineInternalPlugin(this));

await this.loadIconFolderData();
logger.toggleLogging(this.getSettings().debugMode);
setPath(this.getSettings().iconPacksPath);

if (this.getSettings().useInternalPlugins) {
// Registers all modified internal plugins.
// Only adds star plugin for obsidian under v0.12.6.
if (!requireApiVersion('0.12.6')) {
this.modifiedInternalPlugins.push(new StarredInternalPlugin(this));
} else if (requireApiVersion('1.2.0')) {
this.modifiedInternalPlugins.push(new BookmarkInternalPlugin(this));
}

this.modifiedInternalPlugins.push(new OutlineInternalPlugin(this));
}

await createDefaultDirectory(this);
await this.checkRecentlyUsedIcons();

Expand Down
7 changes: 7 additions & 0 deletions src/settings/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export interface IconFolderSettings {
* in the console.
*/
debugMode?: boolean;
/**
* Adds icons to internal plugins such as the bookmarks and outline plugins.
* This is experimental.
* @default false
*/
useInternalPlugins?: boolean;
}

export const DEFAULT_SETTINGS: IconFolderSettings = {
Expand Down Expand Up @@ -209,4 +215,5 @@ export const DEFAULT_SETTINGS: IconFolderSettings = {
iconIdentifier: ':',
lucideIconPackType: 'native',
debugMode: false,
useInternalPlugins: false,
};
2 changes: 1 addition & 1 deletion src/settings/ui/customIconRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class CustomIconRuleSetting extends IconFolderSetting {

const addedPaths: string[] = [];
for (const fileExplorer of this.plugin.getRegisteredFileExplorers()) {
const files = Object.values(fileExplorer.fileItems);
const files = Object.values(fileExplorer.fileItems || {});
for (const rule of customRule.getSortedRules(this.plugin)) {
// Removes the icon tabs from all opened files.
this.updateIconTabs(rule, true, addedPaths);
Expand Down
2 changes: 1 addition & 1 deletion src/settings/ui/emojiStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class EmojiStyleSetting extends IconFolderSetting {

private updateDOM(): void {
for (const fileExplorer of this.plugin.getRegisteredFileExplorers()) {
const fileItems = Object.entries(fileExplorer.fileItems);
const fileItems = Object.entries(fileExplorer.fileItems || {});
for (const [path, _] of fileItems) {
let iconName = this.plugin.getData()[path] as string | undefined | null;
if (!iconName) {
Expand Down
2 changes: 2 additions & 0 deletions src/settings/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ToggleIconsInNotes from './toggleIconsInNotes';
import ToggleIconsInLinks from './toggleIconsInLinks';
import IconIdentifierSetting from './iconIdentifier';
import DebugMode from './debugMode';
import UseInternalPlugins from './useInternalPlugins';

export default class IconFolderSettings extends PluginSettingTab {
private plugin: IconizePlugin;
Expand All @@ -37,6 +38,7 @@ export default class IconFolderSettings extends PluginSettingTab {
new IconPacksBackgroundChecker(plugin, containerEl).display();
new EmojiStyleSetting(plugin, containerEl).display();
new IconIdentifierSetting(plugin, containerEl).display();
new UseInternalPlugins(plugin, containerEl).display();
new DebugMode(plugin, containerEl).display();

containerEl.createEl('h3', { text: 'Visibility of icons' });
Expand Down
24 changes: 24 additions & 0 deletions src/settings/ui/useInternalPlugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Notice, Setting } from 'obsidian';
import IconFolderSetting from './iconFolderSetting';
import config from '@app/config';

export default class UseInternalPlugins extends IconFolderSetting {
public display(): void {
new Setting(this.containerEl)
.setName('EXPERIMENTAL: Use internal plugins')
.setDesc(
'Toggles whether to try to add icons to the bookmark and outline internal plugins.',
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.getSettings().useInternalPlugins)
.onChange(async (enabled) => {
this.plugin.getSettings().useInternalPlugins = enabled;
await this.plugin.saveIconFolderData();
new Notice(
`[${config.PLUGIN_NAME}] Obsidian has to be restarted for this change to take effect.`,
);
});
});
}
}

0 comments on commit 5fa6a65

Please sign in to comment.