mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Add minimal settings
This commit is contained in:
parent
09e1020c2a
commit
7ab945ca80
3 changed files with 97 additions and 0 deletions
16
src/main.ts
16
src/main.ts
|
|
@ -1,11 +1,27 @@
|
|||
import { Plugin } from "obsidian";
|
||||
import { GitHubSyncSettings, DEFAULT_SETTINGS } from "./settings/settings";
|
||||
import GitHubSyncSettingsTab from "./settings/tab";
|
||||
|
||||
export default class GitHubSyncPlugin extends Plugin {
|
||||
settings: GitHubSyncSettings;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
||||
this.addSettingTab(new GitHubSyncSettingsTab(this.app, this));
|
||||
|
||||
console.log("GitHubSyncPlugin loaded");
|
||||
}
|
||||
|
||||
async onunload() {
|
||||
console.log("GitHubSyncPlugin unloaded");
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
src/settings/settings.ts
Normal file
13
src/settings/settings.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export interface GitHubSyncSettings {
|
||||
githubToken: string;
|
||||
githubOwner: string;
|
||||
githubRepo: string;
|
||||
githubBranch: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: GitHubSyncSettings = {
|
||||
githubToken: "",
|
||||
githubOwner: "",
|
||||
githubRepo: "",
|
||||
githubBranch: "main",
|
||||
};
|
||||
68
src/settings/tab.ts
Normal file
68
src/settings/tab.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { PluginSettingTab, App, Setting } from "obsidian";
|
||||
import GitHubSyncPlugin from "src/main";
|
||||
import { GitHubSyncSettings } from "./settings";
|
||||
|
||||
const SETTINGS_DATA: {
|
||||
Name: string;
|
||||
Description: string;
|
||||
Field: keyof GitHubSyncSettings;
|
||||
Placeholder: string;
|
||||
}[] = [
|
||||
{
|
||||
Name: "GitHub Token",
|
||||
Description:
|
||||
"A personal access token or a fine-grained token with read and write access to your repository",
|
||||
Field: "githubToken",
|
||||
Placeholder: "Token",
|
||||
},
|
||||
{
|
||||
Name: "Owner",
|
||||
Description: "Owner of the repository to sync",
|
||||
Field: "githubOwner",
|
||||
Placeholder: "Owner",
|
||||
},
|
||||
{
|
||||
Name: "Repository",
|
||||
Description: "Name of the repository to sync",
|
||||
Field: "githubRepo",
|
||||
Placeholder: "Repository",
|
||||
},
|
||||
{
|
||||
Name: "Repository branch",
|
||||
Description: "Branch to sync",
|
||||
Field: "githubBranch",
|
||||
Placeholder: "Branch name",
|
||||
},
|
||||
];
|
||||
|
||||
export default class GitHubSyncSettingsTab extends PluginSettingTab {
|
||||
plugin: GitHubSyncPlugin;
|
||||
|
||||
constructor(app: App, plugin: GitHubSyncPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const { containerEl } = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl("h2", { text: "Settings for GitHub Sync" });
|
||||
|
||||
SETTINGS_DATA.forEach((setting) => {
|
||||
new Setting(containerEl)
|
||||
.setName(setting.Name)
|
||||
.setDesc(setting.Description)
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder(setting.Placeholder)
|
||||
.setValue(this.plugin.settings[setting.Field])
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings[setting.Field] = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue