Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 77 #78

Merged
merged 7 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
61 changes: 42 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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')});
});
Expand Down Expand Up @@ -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();

Expand All @@ -485,6 +485,7 @@ export default class gamification extends Plugin {
}
}


async updateChartWeeklyColorReceived(value: string) {
const view = await this.getLeafAndView();

Expand All @@ -495,6 +496,7 @@ export default class gamification extends Plugin {
}
}


async updateChartWeeklyColorToGo(value: string) {
const view = await this.getLeafAndView();

Expand All @@ -505,6 +507,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdatePicture() {
const view = await this.getLeafAndView();

Expand All @@ -515,6 +518,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdatePoints(newPoints:number, nextLevel: number) {
const view = await this.getLeafAndView();

Expand All @@ -526,6 +530,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdateBoosterFactor(newFactor:number) {
const view = await this.getLeafAndView();

Expand All @@ -536,6 +541,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdateDailyNotes(dailyString:string) {
const view = await this.getLeafAndView();

Expand All @@ -546,6 +552,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdateWeeklyNotes(weeklyString:string) {
const view = await this.getLeafAndView();

Expand All @@ -556,6 +563,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdateWeeklyChart(days:number) {
const view = await this.getLeafAndView();

Expand All @@ -566,6 +574,7 @@ export default class gamification extends Plugin {
}
}


async profileLeafUpdateMajurityList() {
const view = await this.getLeafAndView();

Expand All @@ -577,7 +586,6 @@ export default class gamification extends Plugin {
}



private async resetGame() {
await this.removeKeysFromFrontmatter();
this.mediator.setSettingNumber('statusLevel', 1);
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Loading