-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TfT Hacker
committed
Sep 10, 2022
1 parent
6878789
commit ca6c263
Showing
6 changed files
with
109 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { App, PluginSettingTab, Setting, ToggleComponent } from 'obsidian'; | ||
import ThePlugin from './main'; | ||
|
||
export interface Settings { | ||
debugMode: boolean | ||
} | ||
|
||
export const DEFAULT_SETTINGS: Settings = { | ||
debugMode: false | ||
} | ||
|
||
export class SettingsTab extends PluginSettingTab { | ||
plugin: ThePlugin; | ||
|
||
constructor(app: App, plugin: ThePlugin) { | ||
super(app, plugin); | ||
this.plugin = plugin; | ||
} | ||
|
||
display(): void { | ||
const { containerEl } = this; | ||
containerEl.empty(); | ||
containerEl.createEl('h2', { text: 'Obsidian42 - Strange New Worlds' }); | ||
|
||
new Setting(containerEl) | ||
.setName('Developer Debugging Mode') | ||
.setDesc('Enable Debugging Mode for troubleshooting in the console.') | ||
.addToggle((cb: ToggleComponent) => { | ||
cb.setValue(this.plugin.settings.debugMode); | ||
cb.onChange(async (value: boolean) => { | ||
this.plugin.settings.debugMode = value; | ||
await this.plugin.saveSettings(); | ||
}); | ||
}); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { getCurrentPage } from "./indexer"; | ||
import ThePlugin from "./main"; | ||
|
||
/** | ||
* Provide a simple API for use with Templater, Dataview and debugging the complexities of various pages. | ||
* main.ts will attach this to window.snwAPI | ||
* | ||
* @export | ||
* @class SnwAPI | ||
*/ | ||
export default class SnwAPI { | ||
plugin: ThePlugin; | ||
|
||
constructor(plugin: ThePlugin) { | ||
this.plugin = plugin | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
console = (logDescription: string, ...outputs: any[]): void => { | ||
if(this.plugin.settings.debugMode===true) | ||
console.log(logDescription, outputs) | ||
} | ||
|
||
/** | ||
* For active file return the meta information used by various components of SNW | ||
* | ||
* @return {*} {Promise<any>} // Needs to be any since we might return just about anything | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
getMetaInfoByCurrentFile = async (): Promise<any> => { | ||
return this.getMetaInfoByFileName(app.workspace.getActiveFile().path) | ||
} | ||
|
||
/** | ||
* For given file name passed into the function, get the meta info for that file | ||
* | ||
* @param {string} fileName (or file name path) | ||
* @memberof SnwAPI | ||
*/ | ||
getMetaInfoByFileName = async (fileName: string)=> { | ||
const currentFile = app.metadataCache.getFirstLinkpathDest(fileName, "/") | ||
return { | ||
TFile: currentFile, | ||
metadataCache: app.metadataCache.getFileCache(currentFile), | ||
SnwTransformedCache: getCurrentPage(currentFile, this.plugin.app), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters