Skip to content

Commit

Permalink
Add timing configuration to show Hadith notification
Browse files Browse the repository at this point in the history
  • Loading branch information
SABER-MOHAMED committed Feb 18, 2023
1 parent b6d8f0e commit f43d4ed
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 17 deletions.
35 changes: 22 additions & 13 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/**
* developer: @mohamedSaber
* desginer: @yahyaTizza
*/
const vscode = require("vscode");

const axios = require("axios").default;

async function getRandomAya() {
const getRandomHadith = async () => {
let hadith =
"✨ إِنَّ اللَّهَ وَمَلائِكَتَهُ يُصَلُّونَ عَلَى النَّبِيِّ يَا أَيُّهَا الَّذِينَ آمَنُوا صَلُّوا عَلَيْهِ وَسَلِّمُوا تَسْلِيمًا";

Expand All @@ -15,56 +19,61 @@ async function getRandomAya() {
},
}
);
// Select Muslim language
const muslimLanguage = vscode.workspace
.getConfiguration("hadith")
.get("language");

hadith = `✨ ${data.hadith[1].body.slice(3, -4)}`;
muslimLanguage === "Arabic"
? (hadith = `✨ ${data.hadith[1].body.slice(3, -4)}`)
: (hadith = `✨ ${data.hadith[0].body.slice(3, -4)}`);
} catch (error) {}

return hadith;
}
};

/**
* @param {vscode.ExtensionContext} context
*/

function activate(context) {
let disposable = vscode.commands.registerCommand(
"hadith.activate",

"hadith.getHadith",
async function () {
getRandomAya()
getRandomHadith()
.then(function (response) {
vscode.window.showInformationMessage(response);
})
.catch((error) => {
console.log("error11: ", error);
vscode.window.showInformationMessage(
"Error while activating Hadith :( 111"
"✨ إِنَّ اللَّهَ وَمَلائِكَتَهُ يُصَلُّونَ عَلَى النَّبِيِّ يَا أَيُّهَا الَّذِينَ آمَنُوا صَلُّوا عَلَيْهِ وَسَلِّمُوا تَسْلِيمًا"
);
});
}
);

// let repeatedEveryMinute = vscode.workspace.getConfiguration("ayat").get('repeatedEveryMinute');
console.log("vscode.workspace: ", vscode.workspace.getConfiguration);
const repeatedEveryMinute = 1;
const repeatedEveryMinute = vscode.workspace
.getConfiguration("hadith")
.get("repeatedEveryMinute");

const convertMinutesToMs = repeatedEveryMinute * 60000;

setInterval(async function () {
getRandomAya()
getRandomHadith()
.then(function (response) {
vscode.window.showInformationMessage(response, "X");
})
.catch((error) => {
vscode.window.showInformationMessage(
"Error while activating Hadith :( 2222"
"✨ إِنَّ اللَّهَ وَمَلائِكَتَهُ يُصَلُّونَ عَلَى النَّبِيِّ يَا أَيُّهَا الَّذِينَ آمَنُوا صَلُّوا عَلَيْهِ وَسَلِّمُوا تَسْلِيمًا"
);
});
}, convertMinutesToMs);

context.subscriptions.push(disposable);
}

// This method is called when your extension is deactivated
function deactivate() {}

module.exports = {
Expand Down
53 changes: 49 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
{
"name": "hadith",
"displayName": "Hadith",
"description": "",
"description": "Get a Hadith from the Sunnah during your coding session 💻 stay connected with Sayings and Teachings of the Prophet Muhammad (ﷺ) 🕌💚 ",
"version": "0.0.1",
"icon": "",
"repository": {
"type": "git",
"url": "git+https://github.com/SABER-MOHAMED/Hadith"
},
"publisher": "MohamedSaber",
"author": "Mohamed Saber <mrsabermed@gmail.com>",
"engines": {
"vscode": "^1.75.0"
},
"categories": [
"Other"
],
"keywords": [
"sunnah",
"Ayat",
"hadith",
"quran",
"quotes",
"Islam"
],
"activationEvents": [
"*",
"onCommand:hadith.activate"
],
"main": "./extension.js",
"contributes": {
"commands": [
{
"command": "hadith.activate",
"title": "Hadith"
"command": "hadith.getHadith",
"category": "Hadith",
"title": "Get Hadith",
"icon": ""
}
],
"configuration": {
"type": "object",
"title": "Hadith configuration",
"properties": {
"hadith.repeatedEveryMinute": {
"type": "number",
"default": "25",
"enum": [
"25",
"50",
"75",
"100",
"125"
],
"description": "Select time between Hadith notifications."
},
"hadith.language": {
"type": "string",
"description": "Select the language of Hadith",
"default": "Arabic",
"enum": [
"Arabic",
"English"
]
}
}
]
}
},
"scripts": {
"lint": "eslint .",
Expand Down

0 comments on commit f43d4ed

Please sign in to comment.