From e86146ca3cf7e511cec2dd5b50baf9280abbcf28 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Tue, 9 Jan 2024 22:54:41 +0100 Subject: [PATCH 1/2] Check for new version --- src/Utils.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.ts | 13 +++++++++-- src/settings.ts | 19 +++++++++++++++-- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/Utils.ts diff --git a/src/Utils.ts b/src/Utils.ts new file mode 100644 index 0000000..79d24c0 --- /dev/null +++ b/src/Utils.ts @@ -0,0 +1,57 @@ +import {App, Notice, request} from 'obsidian'; +import { PLUGIN_VERSION } from "./main" + +//const PLUGIN_VERSION = this.manifest.version; +//declare let PLUGIN_VERSION:string; + +let versionUpdateChecked = false; +export const checkGamifiedPkmVersion = async (app: App) => { + if (versionUpdateChecked) { + return; + } + versionUpdateChecked = true; + + try { + const gitAPIrequest = async () => { + return JSON.parse( + await request({ + url: `https://api.github.com/repos/saertna/obsidian-gamified-pkm/releases?per_page=5&page=1`, + }), + ); + }; + + const latestVersion = (await gitAPIrequest()) + .map((el: any) => { + return { + version: el.tag_name, + published: new Date(el.published_at), + }; + }) + .filter((el: any) => el.version.match(/^\d+\.\d+\.\d+$/)) + .sort((el1: any, el2: any) => el2.published - el1.published)[0].version; + + if (isVersionNewerThanOther(latestVersion,PLUGIN_VERSION)) { + new Notice( + `A newer version of Gamificate your PKM is available in Community Plugins.\n\nYou are using ${PLUGIN_VERSION}.\n\nThe latest is ${latestVersion}`, + ); + } + } catch (e) { + console.error({ where: "Utils/checkGamifiedPkmVersion", error: e }); + } + setTimeout(() => (versionUpdateChecked = false), 28800000); //reset after 8 hours +}; + +export const isVersionNewerThanOther = (version: string, otherVersion: string): boolean => { + const v = version.match(/(\d*)\.(\d*)\.(\d*)/); + const o = otherVersion.match(/(\d*)\.(\d*)\.(\d*)/); + + return Boolean(v && v.length === 4 && o && o.length === 4 && + !(isNaN(parseInt(v[1])) || isNaN(parseInt(v[2])) || isNaN(parseInt(v[3]))) && + !(isNaN(parseInt(o[1])) || isNaN(parseInt(o[2])) || isNaN(parseInt(o[3]))) && + ( + parseInt(v[1])>parseInt(o[1]) || + (parseInt(v[1]) >= parseInt(o[1]) && parseInt(v[2]) > parseInt(o[2])) || + (parseInt(v[1]) >= parseInt(o[1]) && parseInt(v[2]) >= parseInt(o[2]) && parseInt(v[3]) > parseInt(o[3])) + ) + ) +} diff --git a/src/main.ts b/src/main.ts index aaf249e..c97e709 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,8 +42,10 @@ import { import {ModalInformationbox} from 'ModalInformationbox'; import {ModalBooster} from 'ModalBooster'; import {decryptBoolean, decryptNumber, decryptString, encryptBoolean, encryptNumber, encryptString} from 'encryption'; +import { checkGamifiedPkmVersion } from './Utils' let pointsToReceived = 0; +export let PLUGIN_VERSION="0.0.0" export default class gamification extends Plugin { //public settings: GamificationPluginSettings; private timerInterval: number; @@ -103,16 +105,23 @@ export default class gamification extends Plugin { } - - + + async onload() { console.log('obsidian-pkm-gamification loaded!'); //this.settings = defaultSettings; + PLUGIN_VERSION=this.manifest.version this.addSettingTab(new GamificationPluginSettings(this.app, this)); + await this.loadSettings(); + if(this.getSettingBoolean('showNewVersionNotification')) { + await checkGamifiedPkmVersion(this.app); + } + + await this.loadSettings(); // take care to reset when opened on a new day, don't wait for trigger diff --git a/src/settings.ts b/src/settings.ts index ce1f8d3..46ff1fa 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -91,7 +91,8 @@ export const defaultSettings: Partial = { counterMajurityCalcInitial: "U2FsdGVkX1+2Qii8qhFSqrNqmKR1Wh6saEjYbwPdi8Q=", delayLoadTime: "U2FsdGVkX19TLndonGY4Y8vHuZFfLJ5gZ2t/CLprh0o=", timeShowNotice: "U2FsdGVkX190u8cOsylOs1cQ8MeZFq+i+Wv4ox6qq0k=", - receivedBadges: "U2FsdGVkX1/skTUHmzuMYD86hDA/uF1kElPVYm04ijQ=" + receivedBadges: "U2FsdGVkX1/skTUHmzuMYD86hDA/uF1kElPVYm04ijQ=", + showNewVersionNotification: "U2FsdGVkX1+7lWe/h95uqzgl27JBGW2iki7sBwk44YQ=" }; export interface DynamicSettings { @@ -181,7 +182,8 @@ export interface ISettings extends DynamicSettings{ counterMajurityCalcInitial: string; delayLoadTime: string; timeShowNotice: string; - receivedBadges: string + receivedBadges: string; + showNewVersionNotification: string //[key: string]: number | string | boolean | MomentInput; } @@ -272,6 +274,7 @@ export class GamificationPluginSettings extends PluginSettingTab { public delayLoadTime: string; public timeShowNotice: string; public receivedBadges: string; + public showNewVersionNotification: string; constructor(app: App, plugin: gamification) { super(app, plugin); @@ -307,6 +310,18 @@ export class GamificationPluginSettings extends PluginSettingTab { //containerEl.empty(); if(debugLogs) console.debug('settings called') + new Setting(containerEl) + .setName('Plugin Update Notification') + .setDesc('When on, you get informed at startup if there is a newer Version.') + .addToggle((toggle) => + toggle + .setValue(decryptBoolean(this.plugin.settings.showNewVersionNotification)) + .onChange((value) => { + this.plugin.settings.showNewVersionNotification = encryptBoolean(value); + this.plugin.saveData(this.plugin.settings); + }), + ); + new Setting(containerEl) .setName('#tags to ignore') .setDesc('Enter tags without # and separate with ", ".\nInclude nested tags.') From 43e048c8b39da42c5c380e2752eb9c22d2f0a0b1 Mon Sep 17 00:00:00 2001 From: saertna <83655354+saertna@users.noreply.github.com> Date: Tue, 9 Jan 2024 23:01:23 +0100 Subject: [PATCH 2/2] Update Version --- manifest.json | 2 +- .../obsidian-gamified-pkm.zip | Bin 420037 -> 422599 bytes package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 49baf67..6457c9b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "gamified-pkm", "name": "Gamificate your PKM", - "version": "0.0.86", + "version": "0.0.87", "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/obsidian-gamified-pkm/obsidian-gamified-pkm.zip b/obsidian-gamified-pkm/obsidian-gamified-pkm.zip index bc6948ea56dd9eaada58c927ea2182900d654323..0d658df82ebd83422f49e475bfe39529272709b3 100644 GIT binary patch delta 2638 zcmaJ@U2NM_6mFVctAsH?Ost*CI4dRCkUDM0x{=cTqtbP4qqW;QwIg+t+t{09yY@}8 zs;k0~%6J5Uus}>8fdC041QIh(XaaTcfEYu9@q)zv3owZn9$*rjYrARFt#cG#``mlZ z`ObIGIlhaRn?L)txhXvmZP-x9FV&OA4S&+ z`iC+{9y>JBKRlEIQG(u`P%BNiXAea`k950#-9x~$Mxwu**qn#~II3A5qU9shb~Mu% zGMP55Wfg|c?x$}=JG{}4qhCiVX}y@&3^;7%6h>j?s#ZyMDBDk+tk`-~r3RQr0%px3 zcuZK#NQ`}nWj7Lmd#|NJ3JC?b|+g%L!}f@5X87o zrP-4Rycebw-Jw0Pl43)a3;UD;QbcpfIXBMYKpSw8i1h#lh;Z)8#eJ_}$| zRnl(M2R5IYi}6)e+c8FQ-QXgN(Ww#lJUNepmuO8`Y%Pr;|#r>gk(x(F|=w)6C zogKH5OTM2(dO44JkvS-#z*bCYHuK zk7L@LK8*xaR?T!(XI4#Y#R-W!xXzrp!d#7#IlhK9bG&M;vI-XLgep$oFo#){_{d>r z@3JIVgRoYtL9exDxL^%4$FQSvPS&(jh=^ z{#spqhHQ;=d#}xq-%0$sRZP_!OesT~#%{UPDcprJDY)^=q-AvNuW0Lvh7k1DH7ZK< zeejQ6(1GT?FU#agBOWe>pCSX#Kl=gk{(h2-MGzzk%0e*F;{E&#`Qt8p`RWydClT+Z zbL2pzv0LWHi7a(5rG$-M{j20%G~~Va7WrlqjtidMB|9j%7)Y_x%qt!N zr=^7NI8KE2ocmEbx!wI|7m0g~dxigEC~h1SUPjH=2ZeVyy5S>2l1EoLD%^W(V-}BQ z-S=HN<-R#3oQQ1q?#v4LNW=E?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