mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Fix load error (#893)
* Fix critical load error for new installs * Add version update notice
This commit is contained in:
parent
5609c66d28
commit
d12d7cc1c7
2 changed files with 38 additions and 4 deletions
32
src/main.ts
32
src/main.ts
|
|
@ -36,6 +36,7 @@ import {
|
|||
TFile,
|
||||
TFolder,
|
||||
WorkspaceLeaf,
|
||||
requestUrl,
|
||||
} from "obsidian";
|
||||
|
||||
export default class CopilotPlugin extends Plugin {
|
||||
|
|
@ -50,6 +51,7 @@ export default class CopilotPlugin extends Plugin {
|
|||
settingsUnsubscriber?: () => void;
|
||||
|
||||
async onload(): Promise<void> {
|
||||
await this.checkForUpdates();
|
||||
await this.loadSettings();
|
||||
this.settingsUnsubscriber = subscribeToSettingsChange(() => {
|
||||
const settings = getSettings();
|
||||
|
|
@ -667,4 +669,34 @@ export default class CopilotPlugin extends Plugin {
|
|||
metadata: doc.metadata,
|
||||
}));
|
||||
}
|
||||
|
||||
private async checkForUpdates(): Promise<void> {
|
||||
try {
|
||||
const response = await requestUrl({
|
||||
url: "https://api.github.com/repos/logancyang/obsidian-copilot/releases/latest",
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
const latestVersion = response.json.tag_name.replace("v", "");
|
||||
if (this.isNewerVersion(latestVersion, this.manifest.version)) {
|
||||
new Notice(
|
||||
`A new version (${latestVersion}) of Obsidian Copilot is available. You are currently on version ${this.manifest.version}. Please update to the latest version.`,
|
||||
10000
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to check for updates:", error);
|
||||
}
|
||||
}
|
||||
|
||||
private isNewerVersion(latest: string, current: string): boolean {
|
||||
const latestParts = latest.split(".").map(Number);
|
||||
const currentParts = current.split(".").map(Number);
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (latestParts[i] > currentParts[i]) return true;
|
||||
if (latestParts[i] < currentParts[i]) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,16 +115,18 @@ export function useSettingsValue(): Readonly<CopilotSettings> {
|
|||
* Note: This will be better handled by Zod in the future.
|
||||
*/
|
||||
export function sanitizeSettings(settings: CopilotSettings): CopilotSettings {
|
||||
const sanitizedSettings: CopilotSettings = { ...settings };
|
||||
// If settings is null/undefined, use DEFAULT_SETTINGS
|
||||
const settingsToSanitize = settings || DEFAULT_SETTINGS;
|
||||
const sanitizedSettings: CopilotSettings = { ...settingsToSanitize };
|
||||
|
||||
// Stuff in settings are string even when the interface has number type!
|
||||
const temperature = Number(settings.temperature);
|
||||
const temperature = Number(settingsToSanitize.temperature);
|
||||
sanitizedSettings.temperature = isNaN(temperature) ? DEFAULT_SETTINGS.temperature : temperature;
|
||||
|
||||
const maxTokens = Number(settings.maxTokens);
|
||||
const maxTokens = Number(settingsToSanitize.maxTokens);
|
||||
sanitizedSettings.maxTokens = isNaN(maxTokens) ? DEFAULT_SETTINGS.maxTokens : maxTokens;
|
||||
|
||||
const contextTurns = Number(settings.contextTurns);
|
||||
const contextTurns = Number(settingsToSanitize.contextTurns);
|
||||
sanitizedSettings.contextTurns = isNaN(contextTurns)
|
||||
? DEFAULT_SETTINGS.contextTurns
|
||||
: contextTurns;
|
||||
|
|
|
|||
Loading…
Reference in a new issue