Skip to content

Commit

Permalink
Merge pull request #58 from saertna/check-for-new-version
Browse files Browse the repository at this point in the history
Check for new version
  • Loading branch information
saertna authored Jan 9, 2024
2 parents af55a1b + 43e048c commit 1ceec89
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 8 deletions.
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.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",
Expand Down
Binary file modified obsidian-gamified-pkm/obsidian-gamified-pkm.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-gamified-pkm",
"version": "0.0.86",
"version": "0.0.87",
"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
57 changes: 57 additions & 0 deletions src/Utils.ts
Original file line number Diff line number Diff line change
@@ -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]))
)
)
}
13 changes: 11 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export const defaultSettings: Partial<ISettings> = {
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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.')
Expand Down

0 comments on commit 1ceec89

Please sign in to comment.