From 78ad7f8c498eeef9ce5c7bcbabf11fee3b92b033 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:40:14 +0200 Subject: [PATCH 1/7] Use of deferred view functionality --- package-lock.json | 6 +++--- package.json | 4 ++-- src/main.ts | 23 +++++++++++++---------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index c640771..90464de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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..c74e716 100644 --- a/package.json +++ b/package.json @@ -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", @@ -65,4 +65,4 @@ "tslib": "2.4.0", "typescript": "4.7.4" } -} \ No newline at end of file +} diff --git a/src/main.ts b/src/main.ts index 8c9e4cd..c886e79 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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; @@ -237,7 +236,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')}); }); @@ -756,27 +754,32 @@ export default class gamification extends Plugin { // 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); // Ensure the view is fully loaded and visible + 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 }); + await leaf.loadIfDeferred(); // Ensure the view is fully loaded if deferred 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); + if (leaf.view instanceof GamifiedPkmProfileView) { + this.isProfileViewOpen = true; + this.mediator.setSettingBoolean('showProfileLeaf', true); + } } else { console.error("Failed to get a right leaf. Cannot open the profile view."); } - - 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 From dbe3d81432394c94807cb1f1b859ea088ab15aee Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:42:12 +0200 Subject: [PATCH 2/7] Use of deferred view functionality --- src/main.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index c886e79..2ace1e7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -749,14 +749,15 @@ export default class gamification extends Plugin { 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) { - await this.app.workspace.revealLeaf(existingLeaf); // Ensure the view is fully loaded and visible + await this.app.workspace.revealLeaf(existingLeaf); + await existingLeaf.loadIfDeferred(); if (existingLeaf.view instanceof GamifiedPkmProfileView) { this.isProfileViewOpen = true; this.mediator.setSettingBoolean('showProfileLeaf', true); @@ -768,8 +769,9 @@ export default class gamification extends Plugin { if (leaf) { await leaf.setViewState({ type: VIEW_TYPE_GAMIFICATION_PROFILE }); - await leaf.loadIfDeferred(); // Ensure the view is fully loaded if deferred - this.app.workspace.revealLeaf(leaf); + await leaf.loadIfDeferred(); + await this.app.workspace.revealLeaf(leaf); + if (leaf.view instanceof GamifiedPkmProfileView) { this.isProfileViewOpen = true; this.mediator.setSettingBoolean('showProfileLeaf', true); @@ -780,6 +782,7 @@ export default class gamification extends Plugin { } + closeProfileView() { this.app.workspace.detachLeavesOfType(VIEW_TYPE_GAMIFICATION_PROFILE); this.isProfileViewOpen = false; // Set the flag to indicate the view is closed From 68909c6116dc1281b8cdb6b30111e8e5a26df846 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:58:59 +0200 Subject: [PATCH 3/7] Fix null error when opening Leaf at startup --- src/main.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main.ts b/src/main.ts index 2ace1e7..98db4e3 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 { @@ -752,12 +752,13 @@ export default class gamification extends Plugin { 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) { await this.app.workspace.revealLeaf(existingLeaf); - await existingLeaf.loadIfDeferred(); + if (requireApiVersion("1.7.2")) { + await existingLeaf.loadIfDeferred(); + } if (existingLeaf.view instanceof GamifiedPkmProfileView) { this.isProfileViewOpen = true; this.mediator.setSettingBoolean('showProfileLeaf', true); @@ -765,24 +766,28 @@ export default class gamification extends Plugin { } } - const leaf = this.app.workspace.getRightLeaf(false); + let leaf = this.app.workspace.getRightLeaf(false); - if (leaf) { - await leaf.setViewState({ type: VIEW_TYPE_GAMIFICATION_PROFILE }); + if (!leaf) { + console.error("Failed to get a right leaf. Cannot open the profile view."); + return; + } + + 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); - } - } else { - console.error("Failed to get a right leaf. Cannot open the profile view."); + 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 From 04181dcc8d4ec5f5e66c7b3c85de94c1a9a07907 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:04:07 +0200 Subject: [PATCH 4/7] Wait for workspace init to avoid leaf crashes --- src/main.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 98db4e3..97918b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -148,7 +148,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(); @@ -766,7 +768,7 @@ export default class gamification extends Plugin { } } - let leaf = this.app.workspace.getRightLeaf(false); + const leaf = this.app.workspace.getRightLeaf(false); if (!leaf) { console.error("Failed to get a right leaf. Cannot open the profile view."); From b09ff91971407feede5a4ca9350763b564b96a47 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:13:42 +0200 Subject: [PATCH 5/7] Release Note 0.0.92 --- src/Messages.ts | 4 ++++ 1 file changed, 4 insertions(+) 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 From 3b808edf637fcd4dc7cc18270bff54e6cb7f2537 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:16:23 +0200 Subject: [PATCH 6/7] Release Note 0.0.92 --- manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 4 ++-- src/constants.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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 90464de..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", diff --git a/package.json b/package.json index c74e716..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": { @@ -65,4 +65,4 @@ "tslib": "2.4.0", "typescript": "4.7.4" } -} +} \ No newline at end of file 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; From 04ed4771a30cad96adbba0150e60534baa38137e Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:21:30 +0200 Subject: [PATCH 7/7] Release Note 0.0.92 Fixes #77 --- src/main.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 97918b3..92bea42 100644 --- a/src/main.ts +++ b/src/main.ts @@ -112,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] @@ -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,6 +757,7 @@ export default class gamification extends Plugin { this.isProfileViewOpen = false; // Reset the flag when the plugin is unloaded } + async openProfileView() { if (this.isProfileViewOpen) { return; @@ -798,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) {