1import { App, Notice, PluginSettingTab, Setting } from "obsidian";2import type SublimatedPlugin from "./main";3import { SublimatedApi } from "./api";4
5export interface SublimatedSettings {6 apiToken: string;7 hasSeenWelcome: boolean;8}9
10export const DEFAULT_SETTINGS: SublimatedSettings = {11 apiToken: "",12 hasSeenWelcome: false,13};14
15export class SublimatedSettingTab extends PluginSettingTab {16 plugin: SublimatedPlugin;17
18 constructor(app: App, plugin: SublimatedPlugin) {19 super(app, plugin);20 this.plugin = plugin;21 }22
23 display(): void {24 const { containerEl } = this;25 containerEl.empty();26
27 // branding28 const header = containerEl.createDiv({ cls: "sbl-settings-header" });29 header.createEl("h2", { text: "sublimated" });30 header.createEl("p", {31 text: "Sync status, version history, and deep links.",32 cls: "setting-item-description",33 });34
35 // workspace detection (based on xattrs of the last opened file)36 const workspaceInfo = this.plugin.detectWorkspace();37 if (workspaceInfo) {38 new Setting(containerEl)39 .setName("Detected workspace")40 .setDesc(41 `Space: ${workspaceInfo.space || "unknown"}`42 );43 } else {44 new Setting(containerEl)45 .setName("No sublimated file open")46 .setDesc(47 "Open any synced file from a sublimated folder to see workspace info."48 );49 }50
51 // API token52 new Setting(containerEl)53 .setName("API token")54 .setDesc(55 "Required for version history. Generate at sublimated.com/settings/tokens"56 )57 .addText((text) =>58 text59 .setPlaceholder("sk_...")60 .setValue(this.plugin.settings.apiToken)61 .onChange(async (value) => {62 this.plugin.settings.apiToken = value;63 await this.plugin.saveSettings();64 })65 );66
67 // test connection68 new Setting(containerEl)69 .setName("Test connection")70 .setDesc("Verify your API token works")71 .addButton((btn) =>72 btn.setButtonText("Test").onClick(async () => {73 if (!this.plugin.settings.apiToken) {74 new Notice("No API token configured");75 return;76 }77 btn.setButtonText("Testing...");78 btn.setDisabled(true);79 const api = new SublimatedApi(80 this.plugin.settings.apiToken81 );82 const result = await api.testConnection();83 if (result.ok) {84 new Notice(85 `Connected as ${result.username}`86 );87 } else {88 new Notice(89 `Connection failed: ${result.error}`90 );91 }92 btn.setButtonText("Test");93 btn.setDisabled(false);94 })95 );96
97 // links98 containerEl.createEl("div", { cls: "sbl-settings-links" }, (el) => {99 el.createEl("a", {100 text: "sublimated.com",101 href: "https://sublimated.com",102 });103 el.createEl("span", { text: " · " });104 el.createEl("a", {105 text: "Documentation",106 href: "https://sublimated.com/docs/obsidian",107 });108 el.createEl("span", { text: " · " });109 el.createEl("a", {110 text: "Source code",111 href: "https://sublimated.com/sublimated/code/obsidian",112 });113 });114 }115} v2
commit 165f7db
message edit settings.ts via macOS
author anton
date Apr 11, 2026
size 2.9 KB