Skip to content

Commit

Permalink
Refresh Location Using IP
Browse files Browse the repository at this point in the history
  • Loading branch information
kemzops committed Mar 14, 2023
1 parent 1b0550b commit b190d99
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pages/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@

<div class="settings_right">
<h3 class="settings_title">
جلب احداثيات الموقع
جلب احداثيات الموقع الجغرافي
</h3>

<p class="settings_description">
أدخِل إحداثيات نظام تحديد المواقع العالمي (GPS) لخط العرض
إعادة إنشاء ملف الموقع الجغرافي بإستخدام الـ (IP) عن طريق ip-api.com
</p>
</div>

<div class="settings_left">
<img src="../public/icon/refresh.png" id="refresh_location">
<button id="refresh_button">
<img src="../public/icon/refresh.png" id="refresh_location">
</button>
</div>

</li>
Expand Down
29 changes: 29 additions & 0 deletions src/preload/preload_modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = function settings(fs, path, App_Path, settings, ipcRenderer) {
let settings_font_quran = document.getElementById('settings_font_quran');
let settings_font_adhkar_output = document.getElementById('settings_font_adhkar_output');
let settings_font_quran_output = document.getElementById('settings_font_quran_output');
let refresh_button = document.getElementById("refresh_button");

location.timezone ? timezone.value = location.timezone : false
location.lat ? latitude.value = location.lat : false
Expand Down Expand Up @@ -77,6 +78,34 @@ module.exports = function settings(fs, path, App_Path, settings, ipcRenderer) {
adhanVolumeValue.innerHTML = adhanVolumeRange.value;
}

refresh_button.addEventListener('click', async (e) => {
try {
let fetch = require('node-fetch');
let response = await fetch('http://ip-api.com/json');
let status = await response?.status;
if (status !== 200) return
let body = await response?.json();

await fs.writeJsonSync(path.join(App_Path, './data/location.json'), {
country: body?.country,
countryCode: body?.countryCode,
regionName: body?.regionName,
city: body?.city,
lat: body?.lat,
lon: body?.lon,
timezone: body?.timezone,
ip: body?.query
}, { spaces: '\t' });
alrt.style.display = 'inline-flex';
setTimeout(() => {
alrt.style.display = 'none';
window.location.href = "./settings.html";
}, 1000);
} catch (error) {
/* MAYBE THERE IS NO INTERNET CONNECTION SO AVOIDING CRASH */
}
});

save.addEventListener('click', e => {

dark_mode?.checked ? ipcRenderer.send('background', true)
Expand Down
7 changes: 7 additions & 0 deletions src/public/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ output {
color: var(--color_font_grey);
}

#refresh_button {
border: none;
cursor: pointer;
appearance: none;
background-color: inherit;
}

#refresh_location {
width: 40px;
margin-left: 50px;
Expand Down

0 comments on commit b190d99

Please sign in to comment.