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
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { moment, Platform, TFile } from "obsidian";
|
|
import type BratPlugin from "../main";
|
|
|
|
const DEFAULT_DAILY_NOTE_FORMAT = "YYYY-MM-DD";
|
|
|
|
interface DailyNotesPluginLike {
|
|
instance?: {
|
|
options?: {
|
|
format?: string;
|
|
};
|
|
};
|
|
}
|
|
|
|
interface PeriodicNotesPluginLike {
|
|
settings?: {
|
|
daily?: {
|
|
enabled?: boolean;
|
|
format?: string;
|
|
};
|
|
};
|
|
}
|
|
|
|
/** Daily note date format, from Periodic Notes if it handles dailies, else core Daily notes. */
|
|
function getDailyNoteFormat(plugin: BratPlugin): string {
|
|
// @ts-expect-error app.plugins is not part of the public API
|
|
const periodicNotes = plugin.app.plugins.getPlugin(
|
|
"periodic-notes",
|
|
) as PeriodicNotesPluginLike | null;
|
|
const periodicDailySettings = periodicNotes?.settings?.daily;
|
|
if (periodicDailySettings?.enabled) {
|
|
return periodicDailySettings.format || DEFAULT_DAILY_NOTE_FORMAT;
|
|
}
|
|
|
|
// @ts-expect-error app.internalPlugins is not part of the public API
|
|
const dailyNotes = plugin.app.internalPlugins.getPluginById(
|
|
"daily-notes",
|
|
) as DailyNotesPluginLike | null;
|
|
return dailyNotes?.instance?.options?.format || DEFAULT_DAILY_NOTE_FORMAT;
|
|
}
|
|
|
|
/**
|
|
* Logs events to a log file
|
|
*
|
|
* @param plugin - Plugin object
|
|
* @param textToLog - text to be saved to log file
|
|
* @param verboseLoggingOn - True if should only be logged if verbose logging is enabled
|
|
*
|
|
*/
|
|
export async function logger(
|
|
plugin: BratPlugin,
|
|
textToLog: string,
|
|
verboseLoggingOn = false,
|
|
): Promise<void> {
|
|
if (plugin.settings.debuggingMode) console.debug(`BRAT: ${textToLog}`);
|
|
if (plugin.settings.loggingEnabled) {
|
|
if (!plugin.settings.loggingVerboseEnabled && verboseLoggingOn) return;
|
|
|
|
const fileName = `${plugin.settings.loggingPath}.md`;
|
|
const now = moment();
|
|
const dateOutput = `[[${now.format(getDailyNoteFormat(plugin))}]] ${now.format("HH:mm")}`;
|
|
const os = Platform.isDesktop
|
|
? (window.require("os") as { hostname: () => string })
|
|
: null;
|
|
const machineName = Platform.isDesktop ? os?.hostname() : "MOBILE";
|
|
const output = `${dateOutput} ${machineName} ${textToLog.replace("\n", " ")}\n`;
|
|
|
|
const file = plugin.app.vault.getAbstractFileByPath(fileName);
|
|
if (!(file instanceof TFile)) {
|
|
await plugin.app.vault.create(fileName, output);
|
|
} else {
|
|
await plugin.app.vault.append(file, output);
|
|
}
|
|
}
|
|
}
|