generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
5 changed files
with
87 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { PluginSettingTab, Setting } from "obsidian"; | ||
import ObsidianDiscordRPC from "src/main"; | ||
|
||
export class DiscordRPCSettingsTab extends PluginSettingTab { | ||
display(): void { | ||
let { containerEl } = this; | ||
const plugin: ObsidianDiscordRPC = (this as any).plugin; | ||
|
||
containerEl.empty(); | ||
containerEl.createEl("h2", { text: "Discord Rich Presence Settings" }); | ||
|
||
new Setting(containerEl) | ||
.setName("Show Vault Name") | ||
.setDesc( | ||
"Enable this to show the name of the vault you are working with." | ||
) | ||
.addToggle((boolean) => | ||
boolean.setValue(plugin.settings.showVaultName).onChange((value) => { | ||
plugin.settings.showVaultName = value; | ||
plugin.saveData(plugin.settings); | ||
plugin.setActivity(this.app.vault.getName(), "..."); | ||
}) | ||
); | ||
|
||
new Setting(containerEl) | ||
.setName("Show Current File Name") | ||
.setDesc("Enable this to show the name of the file you are working on.") | ||
.addToggle((boolean) => | ||
boolean | ||
.setValue(plugin.settings.showCurrentFileName) | ||
.onChange((value) => { | ||
plugin.settings.showCurrentFileName = value; | ||
plugin.saveData(plugin.settings); | ||
plugin.setActivity(this.app.vault.getName(), "..."); | ||
}) | ||
); | ||
} | ||
} |
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,10 @@ | ||
export class DiscordRPCSettings { | ||
showVaultName: boolean = true; | ||
showCurrentFileName: boolean = true; | ||
} | ||
|
||
export enum PluginState { | ||
connected, | ||
connecting, | ||
disconnected, | ||
} |
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,33 @@ | ||
import { PluginState } from "./settings/settings"; | ||
|
||
export class StatusBar { | ||
private statusBarEl: HTMLElement; | ||
|
||
constructor(statusBarEl: HTMLElement) { | ||
this.statusBarEl = statusBarEl; | ||
} | ||
|
||
displayState(state: PluginState) { | ||
switch (state) { | ||
case PluginState.connected: | ||
this.displayConnected(2000); | ||
break; | ||
case PluginState.connecting: | ||
this.statusBarEl.setText(`Connecting to Discord...`); | ||
break; | ||
case PluginState.disconnected: | ||
this.statusBarEl.setText(`\u{1F5D8} Reconnect to Discord`); | ||
break; | ||
} | ||
} | ||
|
||
displayConnected(timeout: number) { | ||
this.statusBarEl.setText(`\u{1F30D} Connected to Discord`); | ||
|
||
if (timeout && timeout > 0) { | ||
window.setTimeout(() => { | ||
this.statusBarEl.setText(`\u{1F30D}`); | ||
}, timeout); | ||
} | ||
} | ||
} |