|
1 | | -import { App, TFile, setTooltip, setIcon, addIcon, WorkspaceLeaf, MarkdownView, Editor } from "obsidian"; |
| 1 | +import { App, TFile, setTooltip, setIcon, addIcon, WorkspaceLeaf, MarkdownView, Editor, Platform } from "obsidian"; |
2 | 2 | import familyModal from "./familyModal"; |
3 | 3 | import { NewFileLocation } from '../util/enums'; |
4 | 4 | import deleteActiveNoteModal from "./deleteActiveNoteModal"; |
5 | 5 | import { createClustersAndOrphansFolder } from "./createClustersAndOrphansFolder"; |
| 6 | +import { puzzleTemplate } from "./templates"; |
6 | 7 |
|
7 | 8 | const clusters = "CLUSTERS" |
8 | 9 | const orphans = "ORPHANS" |
9 | 10 | let Vars = {} |
10 | 11 | export async function buttonsLine(app: App, file: TFile, settings?: any) { |
11 | 12 | this.app = app |
12 | 13 | Vars = settings |
13 | | - let LEAF: WorkspaceLeaf | null = null; |
14 | | - this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => { |
15 | | - if (leaf.getViewState().type == "markdown") { |
16 | | - LEAF = leaf |
| 14 | + //! Android |
| 15 | + console.log("buttonsLine ⸦ Platform:", Platform); |
| 16 | + if (Platform.isMobile) { |
| 17 | + let LEAF: WorkspaceLeaf | null = null; |
| 18 | + this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => { |
| 19 | + if (leaf.getViewState().type == "markdown") { |
| 20 | + LEAF = leaf |
| 21 | + } |
| 22 | + }) |
| 23 | + |
| 24 | + if (LEAF !== null) { |
| 25 | + const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl |
| 26 | + |
| 27 | + const obsidianContainerElements = Array?.from(obsidianContainer?.children) |
| 28 | + //@ts-ignore |
| 29 | + const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl |
| 30 | + |
| 31 | + |
| 32 | + appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl) |
| 33 | + firstPageOfClusters(file, obsidianContainerElements) |
| 34 | + |
17 | 35 | } |
18 | | - }) |
19 | 36 |
|
20 | | - if (LEAF !== null) { |
21 | | - const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl |
| 37 | + } |
| 38 | + //! PC |
| 39 | + else { |
| 40 | + const e = this.app.workspace.activeLeaf.view.file.path |
| 41 | + if (e.startsWith(clusters) || e.startsWith(orphans)) { |
| 42 | + const LEAF = this.app.workspace.activeLeaf |
| 43 | + const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl |
| 44 | + |
22 | 45 |
|
23 | | - const obsidianContainerElements = Array?.from(obsidianContainer?.children) |
24 | | - //@ts-ignore |
25 | | - const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl |
| 46 | + const obsidianContainerElements = Array?.from(obsidianContainer?.children) |
| 47 | + |
| 48 | + //@ts-ignore |
| 49 | + const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl |
26 | 50 |
|
27 | 51 |
|
28 | | - appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl) |
29 | | - firstPageOfClusters(file, obsidianContainerElements) |
30 | 52 |
|
| 53 | + appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl) |
| 54 | + firstPageOfClusters(file, obsidianContainerElements) |
| 55 | + } else { |
| 56 | + const LEAF2 = this.app.workspace.activeLeaf |
| 57 | + const obsidianContainer2 = (LEAF2! as WorkspaceLeaf)?.view?.containerEl |
| 58 | + |
| 59 | + const obsidianContainerElements2 = Array?.from(obsidianContainer2?.children) |
| 60 | + |
| 61 | + //@ts-ignore |
| 62 | + const obsidianHeaderEl2 = (LEAF2! as WorkspaceLeaf)?.view?.headerEl |
| 63 | + |
| 64 | + RemoveChild(file, obsidianContainer2, obsidianContainerElements2, obsidianHeaderEl2) |
| 65 | + firstPageOfClusters(file, obsidianContainerElements2) |
| 66 | + |
| 67 | + } |
31 | 68 | } |
32 | 69 |
|
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +} |
| 76 | +function RemoveChild(file: TFile, obsidianContainer: any, obsidianContainerElements: any, obsidianHeaderEl: any) { |
| 77 | + const isButtonsLineContainer: any = obsidianContainerElements.find((item: HTMLElement) => item.classList.contains("buttonsLineContainer")) |
| 78 | + |
| 79 | + if (isButtonsLineContainer && !(file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) { |
| 80 | + obsidianContainer.removeChild(isButtonsLineContainer) |
| 81 | + } |
33 | 82 | } |
34 | 83 | //- Append Or Remove Child FUNCTION |
35 | 84 | function appendOrRemoveChild(file: TFile, obsidianContainer: any, obsidianContainerElements: any, obsidianHeaderEl: any) { |
36 | 85 | // check if buttonsLineContainer exist in the DOM or not |
37 | 86 | const isButtonsLineContainer: any = obsidianContainerElements.find((item: HTMLElement) => item.classList.contains("buttonsLineContainer")) |
38 | 87 |
|
39 | | - // remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder |
| 88 | + // // remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder |
40 | 89 | if (isButtonsLineContainer && !(file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) { |
41 | 90 | obsidianContainer.removeChild(isButtonsLineContainer) |
42 | 91 | } |
@@ -129,7 +178,7 @@ function makeButton(type: string, className: string, tooltipMsg: string, element |
129 | 178 | button.textContent = type; |
130 | 179 | setTooltip(button, tooltipMsg, { delay: 10 }) |
131 | 180 | button.addClasses(["btn", className]) |
132 | | - button.addEventListener('click', () => { |
| 181 | + button.addEventListener('click', async () => { |
133 | 182 | if (type == "Cluster") { |
134 | 183 | createClustersAndOrphansFolder(this.app); |
135 | 184 | new familyModal(this.app, NewFileLocation.NewTab, "newCluster", undefined).open(); |
@@ -168,7 +217,13 @@ function makeButton(type: string, className: string, tooltipMsg: string, element |
168 | 217 | window.location.href = coffeeLink; |
169 | 218 | } |
170 | 219 | else if (type == "puzzleBtn") { |
171 | | - console.log("puzzleBtn") |
| 220 | + const puzzleFileExists = await this.app.vault.adapter.exists("/ORPHANS/puzzle.md") |
| 221 | + console.log(puzzleFileExists) |
| 222 | + if (!puzzleFileExists) { |
| 223 | + |
| 224 | + const puzzleFile = await this.app.vault.create("/ORPHANS/puzzle.md", puzzleTemplate) |
| 225 | + this.app.workspace.getLeaf(true).openFile(puzzleFile); |
| 226 | + } |
172 | 227 | } |
173 | 228 |
|
174 | 229 |
|
|
0 commit comments