Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
- Fixed for collapsed folders
- Enable for mobile
  • Loading branch information
valentine195 committed Sep 22, 2021
1 parent c30d769 commit 1fcede3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "obsidian-prominent-starred-files",
"name": "Prominent Starred Files",
"version": "0.0.1",
"version": "0.0.2",
"minAppVersion": "0.12.15",
"description": "Prominently display starred notes in the file explorer",
"author": "Jeremy Valentine",
"authorUrl": "",
"isDesktopOnly": true
"isDesktopOnly": false
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-prominent-starred-files",
"version": "0.0.1",
"version": "0.0.2",
"description": "Prominently display starred files in Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
47 changes: 33 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { App, Notice, Plugin, setIcon } from "obsidian";
import {
Notice,
Plugin,
setIcon,
TAbstractFile,
View,
WorkspaceLeaf
} from "obsidian";
import { around } from "monkey-around";

import "./main.css";
Expand Down Expand Up @@ -37,14 +44,22 @@ declare module "obsidian" {
loadPlugin(...args: any[]): any;
};
}
interface WorkspaceLeaf {
containerEl: HTMLElement;
interface TAbstractFile {
titleEl: HTMLElement;
}
}
interface FileExplorerWorkspaceLeaf extends WorkspaceLeaf {
containerEl: HTMLElement;
view: FileExplorerView;
}

interface FileExplorerView extends View {
fileItems: { [path: string]: TAbstractFile };
}

export default class ProminentStarredFiles extends Plugin {
handler: () => void;
files: Set<StarredFile> = new Set();
files: Set<string> = new Set();
get enabled() {
return this.app.internalPlugins.getPluginById("starred").enabled;
}
Expand All @@ -56,7 +71,9 @@ export default class ProminentStarredFiles extends Plugin {
return this.starred.instance;
}
get fileExplorers() {
return this.app.workspace.getLeavesOfType("file-explorer");
return this.app.workspace.getLeavesOfType(
"file-explorer"
) as FileExplorerWorkspaceLeaf[];
}
async onload() {
console.log("Prominent Starred Files plugin loaded");
Expand Down Expand Up @@ -151,31 +168,33 @@ export default class ProminentStarredFiles extends Plugin {
});
this.register(this.handler);
}
applyStar(file: StarredFile) {
applyStar(file: StarredFile, el?: HTMLElement) {
if (!this.fileExplorers.length) return;
if (this.files.has(file)) return;

this.files.add(file);
if (this.files.has(file.path)) return;

for (let explorer of this.fileExplorers) {
const element = explorer.containerEl.querySelector(
`.nav-file-title[data-path="${file.path}"]`
);
const element =
el ??
explorer.view?.fileItems?.[file.path]?.titleEl ??
explorer.containerEl.querySelector(
`.nav-file-title[data-path="${file}"]`
);
if (!element) continue;

this.files.add(file.path);

setIcon(element.createDiv("prominent-star"), "star-glyph");
}
}
removeStar(file: StarredFile) {
if (!this.fileExplorers.length) return;

this.files.delete(file);

for (let explorer of this.fileExplorers) {
const element = explorer.containerEl.querySelector(
`.nav-file-title[data-path="${file.path}"]`
);
if (!element) continue;
this.files.delete(file.path);

const stars = element.querySelectorAll(".prominent-star");
if (stars.length) stars.forEach((star) => star.detach());
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.0.1": "0.11.0"
"0.0.2": "0.11.0"
}

0 comments on commit 1fcede3

Please sign in to comment.