Fork fixes: - Global token is GitHub-only; never sent to Gitea/Forgejo hosts - Gitea: download assets via browser_download_url (+token) so private repos work - Gitea URL parsing keeps port and sub-path installs, strips browser sub-pages - GitHub detected by hostname, not substring - Gitea releases: follow pagination (X-Total-Count), skip drafts - Gitea token validation against the repo; 404 is no longer "valid" - Settings tab and migration log use this plugin's own id/folder - Check-only mode no longer reinstalls/enables a missing plugin folder - reloadPlugin reports load failures (enablePlugin resolves false) - Repository / release-notes links work for both providers Ported from upstream BRAT 2.2.0: - Release sort: semver tags first, date fallback - Null-safe version comparison, JSON shape guards - Drop obsidian-daily-notes-interface (read daily note format directly) - Notice.messageEl, CSS without !important, console.debug/error
128 lines
3.5 KiB
TypeScript
128 lines
3.5 KiB
TypeScript
import { ButtonComponent, Modal, Setting } from "obsidian";
|
|
import { themeSave } from "../features/themes";
|
|
import { normalizeRepoAddress } from "../providers";
|
|
import type BratPlugin from "../main";
|
|
import { existBetaThemeinInList } from "../settings";
|
|
import { toastMessage } from "../utils/notifications";
|
|
import { promotionalLinks } from "./Promotional";
|
|
|
|
/**
|
|
* Add a beta theme to the list of plugins being tracked and updated
|
|
*/
|
|
export default class AddNewTheme extends Modal {
|
|
plugin: BratPlugin;
|
|
address: string;
|
|
openSettingsTabAfterwards: boolean;
|
|
|
|
constructor(plugin: BratPlugin, openSettingsTabAfterwards = false) {
|
|
super(plugin.app);
|
|
this.plugin = plugin;
|
|
this.address = "";
|
|
this.openSettingsTabAfterwards = openSettingsTabAfterwards;
|
|
}
|
|
|
|
async submitForm(): Promise<void> {
|
|
if (this.address === "") return;
|
|
const scrubbedAddress = normalizeRepoAddress(this.address);
|
|
if (!scrubbedAddress) {
|
|
toastMessage(
|
|
this.plugin,
|
|
"Invalid address. Expected: user/repo (GitHub) or https://host/user/repo (Gitea).",
|
|
10,
|
|
);
|
|
return;
|
|
}
|
|
if (existBetaThemeinInList(this.plugin, scrubbedAddress)) {
|
|
toastMessage(
|
|
this.plugin,
|
|
"This theme is already in the list for beta testing",
|
|
10,
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (await themeSave(this.plugin, scrubbedAddress, true)) {
|
|
this.close();
|
|
}
|
|
}
|
|
|
|
onOpen(): void {
|
|
this.contentEl.createEl("h4", {
|
|
text: "Github repository for beta theme:",
|
|
});
|
|
this.contentEl.createEl("form", {}, (formEl) => {
|
|
formEl.addClass("brat-modal");
|
|
new Setting(formEl).addText((textEl) => {
|
|
textEl.setPlaceholder(
|
|
"Repository (example: https://github.com/user/repo or https://git.example.com/user/repo)",
|
|
);
|
|
textEl.setValue(this.address);
|
|
textEl.onChange((value) => {
|
|
this.address = value.trim();
|
|
});
|
|
textEl.inputEl.addEventListener("keydown", (e: KeyboardEvent) => {
|
|
if (e.key === "Enter" && this.address !== " ") {
|
|
e.preventDefault();
|
|
void this.submitForm();
|
|
}
|
|
});
|
|
textEl.inputEl.style.width = "100%";
|
|
window.setTimeout(() => {
|
|
const title = document.querySelector(".setting-item-info");
|
|
if (title) title.remove();
|
|
textEl.inputEl.focus();
|
|
}, 10);
|
|
});
|
|
|
|
formEl.createDiv("modal-button-container", (buttonContainerEl) => {
|
|
new ButtonComponent(buttonContainerEl)
|
|
.setButtonText("Never mind")
|
|
.onClick(() => {
|
|
this.close();
|
|
});
|
|
|
|
new ButtonComponent(buttonContainerEl)
|
|
.setButtonText("Add theme")
|
|
.setCta()
|
|
.onClick((e: Event) => {
|
|
e.preventDefault();
|
|
if (this.address !== "") void this.submitForm();
|
|
});
|
|
});
|
|
|
|
const newDiv = formEl.createDiv();
|
|
newDiv.style.borderTop = "1px solid #ccc";
|
|
newDiv.style.marginTop = "30px";
|
|
const byTfThacker = newDiv.createSpan();
|
|
byTfThacker.createEl("a", {
|
|
href: "https://bit.ly/o42-twitter",
|
|
text: "TFTHacker",
|
|
});
|
|
byTfThacker.appendText(" and ");
|
|
byTfThacker.createEl("a", {
|
|
href: "https://github.com/johannrichard",
|
|
text: "johannrichard",
|
|
});
|
|
byTfThacker.style.fontStyle = "italic";
|
|
newDiv.appendChild(byTfThacker);
|
|
promotionalLinks(newDiv, false);
|
|
|
|
window.setTimeout(() => {
|
|
const title = formEl.querySelectorAll(".brat-modal .setting-item-info");
|
|
for (const titleEl of Array.from(title)) {
|
|
titleEl.remove();
|
|
}
|
|
}, 50);
|
|
});
|
|
}
|
|
|
|
onClose(): void {
|
|
if (this.openSettingsTabAfterwards) {
|
|
// @ts-expect-error
|
|
this.plugin.app.setting.openTab();
|
|
// @ts-expect-error
|
|
this.plugin.app.setting.openTabById(this.plugin.manifest.id);
|
|
}
|
|
}
|
|
}
|