Skip to content

Commit

Permalink
reminder system added
Browse files Browse the repository at this point in the history
  • Loading branch information
DBChoco committed Dec 16, 2023
1 parent e1ee842 commit 094f052
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 14 deletions.
Empty file.
Empty file.
48 changes: 46 additions & 2 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ var customValues, delay;
var prayerTimes, datePrayerTimes, tomorrowPrayers;
var settings
var langFajr, langDhuhr, langAsr, langMaghrib, langIsha, langNow;
var reminderTimes;

var adjustements;
var updateInterval;
Expand Down Expand Up @@ -339,8 +340,8 @@ function checkTime(){
var prayers = nextPrayer();
if (settings.adhanCheck || settings.notifCheck){
if (prayers != undefined && prayers[0] != undefined){
var timeUntilCurrentPrayer = timeUntilPrayer(prayers[0])
if(timeUntilCurrentPrayer[0] == -1 && timeUntilCurrentPrayer[1] == -1 && timeUntilCurrentPrayer[2] == 0){ //-1 because math.floor
var timeUntilCurrentPrayer = timeUntilPrayer(prayers[1])
if(timeUntilCurrentPrayer[0] == 0 && timeUntilCurrentPrayer[1] == 0 && timeUntilCurrentPrayer[2] == 1){ //-1 because math.floor
if (settings.adhanCheck){
if (prayers[2] == langFajr && adhanSettings.adhanFajr.custom) mediaWindow.webContents.send('playFajr', adhanSettings);
else mediaWindow.webContents.send('play', adhanSettings);
Expand All @@ -349,6 +350,30 @@ function checkTime(){
showNotification(langNow + ": " + prayers[2])
}
}

if (reminderTimes.enabled){
if (prayers[3] == langFajr && reminderTimes.fajr != '0'){
launchReminder(timeUntilCurrentPrayer, reminderTimes.fajr)
}
else if ((prayers[3] == langDhuhr)){
if ((new Date).getDay() == 5 && reminderTimes.jumuah != '0'){ //Jumuah
launchReminder(timeUntilCurrentPrayer, reminderTimes.jumuah)
}
else if (reminderTimes.dhuhr != '0'){
launchReminder(timeUntilCurrentPrayer, reminderTimes.dhuhr)
}
}

else if ((prayers[3] == langAsr && reminderTimes.asr != '0')){
launchReminder(timeUntilCurrentPrayer, reminderTimes.asr)
}
else if ((prayers[3] == langMaghrib && reminderTimes.maghrib != '0')){
launchReminder(timeUntilCurrentPrayer, reminderTimes.maghrib)
}
else if ((prayers[3] == langIsha && reminderTimes.isha != '0')){
launchReminder(timeUntilCurrentPrayer, reminderTimes.isha)
}
}
}
}
if (today.getDate() != (new Date).getDate()){
Expand All @@ -362,6 +387,15 @@ function checkTime(){
}, 1000);
}

function launchReminder(timeUntilCurrentPrayer, time){
if (timeUntilCurrentPrayer[0] == 0 && timeUntilCurrentPrayer[1] == parseInt(time) && timeUntilCurrentPrayer[2] == 1){
mediaWindow.webContents.send('playReminder');
if (settings.notifCheck){
showNotification("Adhan in " + time + " minutes") //Add languages
}
}
}

/**
* Loads all required variables from the store
*/
Expand Down Expand Up @@ -426,6 +460,16 @@ async function loadSettings(){

adjustements = await store.get('adj', [false, 0,0,0,0,0]);

reminderTimes = await store.get('reminderTimes', {
enabled: false,
fajr: 0,
dhuhr: 0,
asr: 0,
maghrib: 0,
isha: 0,
jumuah: 0
});

if (settings.minStart && startup){
mainWindow.hide()
}
Expand Down
9 changes: 9 additions & 0 deletions src/mediaPlayer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ function setUpHandlers(){
athan.play();
})

window.api.handle('playReminder', msg => {
if (!athan.paused || !dua.paused){
stop()
}
athan = new Audio("../../ressources/audio/AllahuAkbar.mp3");
playDua = false;
athan.play();
})



window.api.handle('stop', msg => {
Expand Down
96 changes: 85 additions & 11 deletions src/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ <h1 id=settingsTitle>Settings</h1>
<button class="nav-link" id="v-pills-advanced-tab" data-bs-toggle="pill" data-bs-target="#v-pills-advanced" type="button" role="tab" aria-controls="v-pills-advanced" aria-selected="false">Advanced</button>
<button class="nav-link" id="v-pills-adjustments-tab" data-bs-toggle="pill" data-bs-target="#v-pills-adjustments" type="button" role="tab" aria-controls="v-pills-adjustments" aria-selected="false">Adjustments</button>
<button class="nav-link" id="v-pills-custom-tab" data-bs-toggle="pill" data-bs-target="#v-pills-custom" type="button" role="tab" aria-controls="v-pills-custom" aria-selected="false">Custom Times</button>
<button class="nav-link" id="v-pills-reminder-tab" data-bs-toggle="pill" data-bs-target="#v-pills-reminder" type="button" role="tab" aria-controls="v-pills-reminder" aria-selected="false">Adhan Reminder</button>
<button class="nav-link" id="v-pills-quran-tab" data-bs-toggle="pill" data-bs-target="#v-pills-quran" type="button" role="tab" aria-controls="v-pills-quran" aria-selected="false">
<i class="fa-solid fa-book-quran"></i>
Qur'an
Expand Down Expand Up @@ -189,7 +190,7 @@ <h1 id=settingsTitle>Settings</h1>
<label class="form-check-label" for="latInput" id="latText">
Latitude
</label>
<input id="latInput" class="form-control" type="number" value="0.00" min="-90" max="90" step="0.1" maxlength="5"
<input id="latInput" class="form-control" type="number" value="0.00" min="0" max="90" step="0.1" maxlength="5"
placeholder="00.00">
</div>
<div class="grid-itemL grid-sub">
Expand Down Expand Up @@ -449,19 +450,19 @@ <h1 id=settingsTitle>Settings</h1>
<label class="form-check-label" for="fajrAngle" id="fajrAngleText">
Fajr Angle
</label>
<input id="fajrAngle" class="form-control shortInput" type="number" value="0.00" min="-90" max="90" step="0.1" maxlength="5"
<input id="fajrAngle" class="form-control shortInput" type="number" value="0.00" min="0" max="90" step="0.1" maxlength="5"
placeholder="00.00">

<label class="form-check-label" for="maghribAngle" id="maghribAngleText">
Maghrib Angle
</label>
<input id="maghribAngle" class="form-control shortInput" type="number" value="0.00" min="-90" max="90" step="0.1" maxlength="5"
<input id="maghribAngle" class="form-control shortInput" type="number" value="0.00" min="0" max="90" step="0.1" maxlength="5"
placeholder="00.00">

<label class="form-check-label" for="ishaAngle" id="ishaAngleText">
Isha Angle
</label>
<input id="ishaAngle" class="form-control shortInput" type="number" value="0.00" min="-90" max="90" step="0.1" maxlength="5"
<input id="ishaAngle" class="form-control shortInput" type="number" value="0.00" min="0" max="90" step="0.1" maxlength="5"
placeholder="00.00">
</form>
</div>
Expand Down Expand Up @@ -505,39 +506,39 @@ <h1 id=settingsTitle>Settings</h1>
<label class="form-check-label" for="fajrAdjInput" id="fajrAdjText">
Fajr Adjustments
</label>
<input id="fajrAdjInput" class="form-control shortInput" type="number" value="0" min="-90" max="90" step="1" maxlength="5"
<input id="fajrAdjInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="dhuhrAdjInput" id="dhuhrAdjText">
Dhuhr Adjustments
</label>
<input id="dhuhrAdjInput" class="form-control shortInput" type="number" value="0" min="-90" max="90" step="1" maxlength="5"
<input id="dhuhrAdjInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="asrAdjInput" id="asrAdjText">
Asr Adjustments
</label>
<input id="asrAdjInput" class="form-control shortInput" type="number" value="0" min="-90" max="90" step="1" maxlength="5"
<input id="asrAdjInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="maghribAdjInput" id="maghribAdjText">
Maghrib Adjustments
</label>
<input id="maghribAdjInput" class="form-control shortInput" type="number" value="0" min="-90" max="90" step="1" maxlength="5"
<input id="maghribAdjInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="ishaAdjInput" id="ishaAdjText">
Isha Adjustments
</label>
<input id="ishaAdjInput" class="form-control shortInput" type="number" value="0" min="-90" max="90" step="1" maxlength="5"
<input id="ishaAdjInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>
</form>
Expand All @@ -553,7 +554,7 @@ <h1 id=settingsTitle>Settings</h1>
<label class="form-check-label" for="hijriAdjInput" id="hijriAdjText">
Hijri date difference
</label>
<input id="hijriAdjInput" class="form-control shortInput" type="number" value="0" min="-90" max="90" step="1" maxlength="5"
<input id="hijriAdjInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>
</form>
Expand Down Expand Up @@ -634,12 +635,85 @@ <h1 id=settingsTitle>Settings</h1>
</div>
</form>
</div>
</div>
</div>

<div class="tab-pane fade" id="v-pills-reminder" role="tabpanel" aria-labelledby="v-pills-reminder-tab"> <!-- Reminder before adhan -->
<div class="grid-container">
<div class="grid-itemL">
<p class="h4" id="reminderText">Reminder before Adhan</p>
</div>
<div class="grid-itemR">
<form >
<div class="form-check grid-R-spacer">
<label class="form-check-label" for="reminderCheck" id="reminderCheckText">
Enable Reminder
</label>
<input class="form-check-input" type="checkbox" id="reminderCheck" unchecked>
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="fajrReminderInput" id="fajrReminderText">
Minutes before Fajr
</label>
<input id="fajrReminderInput" class="form-control shortInput" type="number" value="0" min="0" max="59" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="dhuhrReminderInput" id="dhuhrReminderText">
Minutes before Dhuhr
</label>
<input id="dhuhrReminderInput" class="form-control shortInput" type="number" value="0" min="0" max="59" step="1" maxlength="5"
placeholder="00.00">
</div>

</div>
<div class="form-check grid-R-spacer">
<label class="form-check-label" for="asrReminderInput" id="asrReminderText">
Minutes before Asr
</label>
<input id="asrReminderInput" class="form-control shortInput" type="number" value="0" min="0" max="59" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="maghribReminderInput" id="maghribReminderText">
Minutes before Maghrib
</label>
<input id="maghribReminderInput" class="form-control shortInput" type="number" value="0" min="0" max="59" step="1" maxlength="5"
placeholder="00.00">
</div>

<div class="form-check grid-R-spacer">
<label class="form-check-label" for="ishaReminderInput" id="ishaReminderText">
Minutes before Isha
</label>
<input id="ishaReminderInput" class="form-control shortInput" type="number" value="0" min="0" max="59" step="1" maxlength="5"
placeholder="00.00">
</div>
</form>
</div>

<div class="grid-itemL">
<p class="h4" id="jumuahReminderTitle">Jumuah Reminder</p>
</div>

<div class="grid-itemR">
<form >
<div class="form-check grid-R-spacer">
<label class="form-check-label" for="jumuahReminderInput" id="jumuahReminderText">
Minutes before Jumuah
</label>
<input id="jumuahReminderInput" class="form-control shortInput" type="number" value="0" min="0" max="90" step="1" maxlength="5"
placeholder="00.00">
</div>
</form>
</div>

</div>
</div>


<div class="tab-pane fade" id="v-pills-quran" role="tabpanel" aria-labelledby="v-pills-quran-tab"> <!-- Qur'an -->
<div class="grid-container">

Expand Down
71 changes: 70 additions & 1 deletion src/settings/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var timeDisplay, language, adhanFile, bgImage, sunnahTimes, settings, weather, customTimes, jumuahTime,
calculationMethod, quran;
calculationMethod, reminderTimes, quran;
var lat,lon;
var fromQuran = false;
var locationName;
Expand Down Expand Up @@ -70,6 +70,7 @@ async function saveSettings(){
await saveAdjustments()
await saveCustomSettings()
await saveCustomTimes()
await saveReminderTimes()
await saveQuran()
}

Expand Down Expand Up @@ -121,6 +122,7 @@ async function loadSettings(){
await loadCustomSettings()
await loadAdjustments()
await loadCustomTimes()
await loadReminderTimes()

document.getElementById("latInput").value = lat
document.getElementById("lonInput").value = lon
Expand Down Expand Up @@ -1374,3 +1376,70 @@ function autocomplete(inp, arr) {
closeAllLists(e.target);
});
}

/*
Reminder before Adhan settings
*/

async function loadReminderTimes(){
reminderTimes = await window.api.getFromStore("reminderTimes", {
enabled: false,
fajr: 0,
dhuhr: 0,
asr: 0,
maghrib: 0,
isha: 0,
jumuah: 0
});

let reminderTimesCheck = document.getElementById("reminderCheck")
let reminderFajr = document.getElementById("fajrReminderInput")
let reminderDhuhr = document.getElementById("dhuhrReminderInput")
let reminderAsr = document.getElementById("asrReminderInput")
let reminderMaghrib = document.getElementById("maghribReminderInput")
let reminderIsha = document.getElementById("ishaReminderInput")
let reminderJumuah = document.getElementById("jumuahReminderInput")
reminderTimesCheck.checked = reminderTimes.enabled;

disableReminderTimes()
reminderTimesCheck.addEventListener("change", function(){
disableReminderTimes()
})
reminderFajr.value = reminderTimes.fajr;
reminderDhuhr.value = reminderTimes.dhuhr;
reminderAsr.value = reminderTimes.asr;
reminderMaghrib.value = reminderTimes.maghrib;
reminderIsha.value = reminderTimes.isha;

let jumuahCheck = document.getElementById("jumuahCheck")
let jumuahInput = document.getElementById("jumuahInput");
jumuahCheck.checked = reminderTimes.enabled;
jumuahInput.disabled = !jumuahCheck.checked;
jumuahCheck.addEventListener("change", function(){
jumuahInput.disabled = !jumuahCheck.checked;
})
jumuahInput.value = jumuahTime.time;

function disableReminderTimes(){
reminderFajr.disabled = !reminderTimesCheck.checked;
reminderDhuhr.disabled = !reminderTimesCheck.checked;
reminderAsr.disabled = !reminderTimesCheck.checked;
reminderMaghrib.disabled = !reminderTimesCheck.checked;
reminderIsha.disabled = !reminderTimesCheck.checked;
reminderJumuah.disabled = !reminderTimesCheck.checked;
}
}

async function saveReminderTimes(){
let newreminderTimes = {
enabled: document.getElementById("reminderCheck").checked,
fajr: document.getElementById("fajrReminderInput").value,
dhuhr: document.getElementById("dhuhrReminderInput").value,
asr: document.getElementById("asrReminderInput").value,
maghrib: document.getElementById("maghribReminderInput").value,
isha: document.getElementById("ishaReminderInput").value,
jumuah: document.getElementById("jumuahReminderInput").value
};

if (reminderTimes != newreminderTimes) await window.api.setToStore("reminderTimes", newreminderTimes);
}

0 comments on commit 094f052

Please sign in to comment.