diff --git a/manifest.json b/manifest.json index 8f0f879..1302d1a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "gamified-pkm", "name": "Gamificate your PKM", - "version": "0.0.91", + "version": "0.0.92", "minAppVersion": "0.15.0", "description": "Enhance your Personal Knowledge Management with gamification elements. Boost motivation and achieve growth as you engage with your PKM.", "author": "Andreas Trebing", diff --git a/package-lock.json b/package-lock.json index c640771..d477933 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-gamified-pkm", - "version": "0.0.91", + "version": "0.0.92", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-gamified-pkm", - "version": "0.0.91", + "version": "0.0.92", "license": "MIT", "dependencies": { "chart.js": "^4.4.4", @@ -41,7 +41,7 @@ "jest-mock-extended": "^3.0.5", "lint": "^1.1.2", "markdownlint": "^0.30.0", - "obsidian": "^1.4.11", + "obsidian": "^1.7.2", "obsidian-dataview": "^0.5.67", "rollup": "^2.79.1", "rollup-plugin-commonjs": "^10.1.0", @@ -5124,8 +5124,8 @@ } }, "node_modules/obsidian": { - "version": "1.6.6", - "resolved": "git+ssh://git@github.com/obsidianmd/obsidian-api.git#df9434bec6883bd32727f61b1ed1336f7663d0e4", + "version": "1.7.2", + "resolved": "git+ssh://git@github.com/obsidianmd/obsidian-api.git#23947b58d372ea02225324308e31d36b4aa95869", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 3f32756..a088568 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-gamified-pkm", - "version": "0.0.91", + "version": "0.0.92", "description": "Enhance your Personal Knowledge Management with gamification elements. Boost motivation and achieve growth as you engage with your PKM.", "main": "main.js", "scripts": { @@ -50,7 +50,7 @@ "jest-mock-extended": "^3.0.5", "lint": "^1.1.2", "markdownlint": "^0.30.0", - "obsidian": "^1.4.11", + "obsidian": "^1.7.2", "obsidian-dataview": "^0.5.67", "rollup": "^2.79.1", "rollup-plugin-commonjs": "^10.1.0", diff --git a/src/Messages.ts b/src/Messages.ts index 02bfded..7282982 100644 --- a/src/Messages.ts +++ b/src/Messages.ts @@ -15,6 +15,10 @@ I develop this plugin as a hobby, spending my free time doing this. If you find It would mean a lot to me. `, +"0.0.92": ` +## Fixed +- when starting obsidian plugin not loading correctly [#77](https://github.com/saertna/obsidian-gamified-pkm/issues/77) +`, "0.0.91": ` ## New - Profile is transferred to right side leaf diff --git a/src/constants.ts b/src/constants.ts index a24307b..30ea48f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,5 @@ import { Badge } from './badges' -export const PLUGIN_VERSION = '0.0.91'; +export const PLUGIN_VERSION = '0.0.92'; export const pointsNoteMajurity = 100; export const pointsMajurity = 10; export const pointsForDailyChallenge = 500; diff --git a/src/main.ts b/src/main.ts index 8c9e4cd..92bea42 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,7 +12,7 @@ style.textContent = ` `; document.head.append(style); -import {MarkdownView, Notice, Plugin, TFile} from 'obsidian'; +import {MarkdownView, Notice, Plugin, TFile, requireApiVersion} from 'obsidian'; import {GamificationPluginSettings, ISettings} from './settings'; import format from 'date-fns/format'; import { @@ -82,7 +82,6 @@ export default class gamification extends Plugin { await checkGamifiedPkmVersion(this.app); } - //await this.mediator.loadSettings(); const delayLoadTime = this.mediator.getSettingNumber('delayLoadTime') * 1000; @@ -113,7 +112,6 @@ export default class gamification extends Plugin { ); - // This portion of code is adapted from the following source under the MIT License: // https://github.com/zsviczian/obsidian-excalidraw-plugin // Copyright (c) [2024], [zsviczian] @@ -149,7 +147,9 @@ export default class gamification extends Plugin { // import ends here if (this.mediator.getSettingBoolean('showProfileLeaf')) { - await this.openProfileView(); + this.app.workspace.onLayoutReady(async () => { + await this.openProfileView(); + }); } this.registerCommands(); @@ -237,7 +237,6 @@ export default class gamification extends Plugin { this.actualizeProfileLeaf().then(() => {if(debugLogs) console.log('Profile updated successfully')}); }); - this.addRibbonIcon("target", "gamification side overview", () => { this.activateView().then(() => {if(debugLogs) console.log('Profile view activated')}); }); @@ -473,6 +472,7 @@ export default class gamification extends Plugin { // workspace.revealLeaf(leaf); } + async profileLeafUpdateLevel(newLevel:number, newPoints:number, nextLevel:number, min:number, max:number) { const view = await this.getLeafAndView(); @@ -485,6 +485,7 @@ export default class gamification extends Plugin { } } + async updateChartWeeklyColorReceived(value: string) { const view = await this.getLeafAndView(); @@ -495,6 +496,7 @@ export default class gamification extends Plugin { } } + async updateChartWeeklyColorToGo(value: string) { const view = await this.getLeafAndView(); @@ -505,6 +507,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdatePicture() { const view = await this.getLeafAndView(); @@ -515,6 +518,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdatePoints(newPoints:number, nextLevel: number) { const view = await this.getLeafAndView(); @@ -526,6 +530,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdateBoosterFactor(newFactor:number) { const view = await this.getLeafAndView(); @@ -536,6 +541,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdateDailyNotes(dailyString:string) { const view = await this.getLeafAndView(); @@ -546,6 +552,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdateWeeklyNotes(weeklyString:string) { const view = await this.getLeafAndView(); @@ -556,6 +563,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdateWeeklyChart(days:number) { const view = await this.getLeafAndView(); @@ -566,6 +574,7 @@ export default class gamification extends Plugin { } } + async profileLeafUpdateMajurityList() { const view = await this.getLeafAndView(); @@ -577,7 +586,6 @@ export default class gamification extends Plugin { } - private async resetGame() { await this.removeKeysFromFrontmatter(); this.mediator.setSettingNumber('statusLevel', 1); @@ -749,34 +757,48 @@ export default class gamification extends Plugin { this.isProfileViewOpen = false; // Reset the flag when the plugin is unloaded } + async openProfileView() { if (this.isProfileViewOpen) { - return; // If the view is already open, don't open another one + return; } - // Check if a leaf with the same type already exists, and if so, focus it const existingLeaf = this.app.workspace.getLeavesOfType(VIEW_TYPE_GAMIFICATION_PROFILE)[0]; + if (existingLeaf) { - this.app.workspace.revealLeaf(existingLeaf); - return; + await this.app.workspace.revealLeaf(existingLeaf); + if (requireApiVersion("1.7.2")) { + await existingLeaf.loadIfDeferred(); + } + if (existingLeaf.view instanceof GamifiedPkmProfileView) { + this.isProfileViewOpen = true; + this.mediator.setSettingBoolean('showProfileLeaf', true); + return; + } } const leaf = this.app.workspace.getRightLeaf(false); - if (leaf) { - await leaf.setViewState({ type: VIEW_TYPE_GAMIFICATION_PROFILE }); - this.app.workspace.revealLeaf(leaf); - this.isProfileViewOpen = true; // Set the flag to indicate the view is open - - // Set the setting to reflect that the profile leaf is open - this.mediator.setSettingBoolean('showProfileLeaf', true); - } else { + if (!leaf) { console.error("Failed to get a right leaf. Cannot open the profile view."); + return; } - this.mediator.setSettingBoolean('showProfileLeaf', true); + await leaf.setViewState({ type: VIEW_TYPE_GAMIFICATION_PROFILE }); + + if (requireApiVersion("1.7.2")) { + await leaf.loadIfDeferred(); + } + + await this.app.workspace.revealLeaf(leaf); + + if (leaf.view instanceof GamifiedPkmProfileView) { + this.isProfileViewOpen = true; + this.mediator.setSettingBoolean('showProfileLeaf', true); + } } + closeProfileView() { this.app.workspace.detachLeavesOfType(VIEW_TYPE_GAMIFICATION_PROFILE); this.isProfileViewOpen = false; // Set the flag to indicate the view is closed @@ -785,6 +807,7 @@ export default class gamification extends Plugin { this.mediator.setSettingBoolean('showProfileLeaf', false); } + async calculateNoteMajurity(){ const file: TFile | null= this.app.workspace.getActiveFile(); if (file == null) {