Skip to content

Commit

Permalink
feat: version check
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Apr 20, 2023
1 parent 4cfa34b commit 7daabd6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
32 changes: 32 additions & 0 deletions core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const PostAddressIP = "https://exptech.com.tw/api/v1/trem/";
let report_data = {};
let report_now_id = 0;
let replay_stop_state = false;
let update = false;

const info_list = [];

Expand All @@ -32,6 +33,37 @@ function intensity_string_to_int(string) {
return (string == "0") ? 0 : (string == "1") ? 1 : (string == "2") ? 2 : (string == "3") ? 3 : (string == "4") ? 4 : (string == "5-") ? 5 : (string == "5+") ? 6 : (string == "6-") ? 7 : (string == "6+") ? 8 : 9;
}

function check_update() {
if (update) return;
const controller = new AbortController();
setTimeout(() => {
controller.abort();
}, 2500);
fetch("https://api.github.com/repos/ExpTechTW/TREM-Lite/releases", { signal: controller.signal })
.then((ans) => ans.json())
.then((ans) => {
if (ver_string_to_int(ans[0].tag_name) > ver_string_to_int(app.getVersion())) {
update = true;
const notification = new Notification("🆙 新版本", {
body : `發現新版本! 『${ans[0].tag_name}』\n點擊此訊息前往查看`,
icon : "../TREM.ico",
});
notification.onclick = () => {
shell.openExternal("https://github.com/ExpTechTW/TREM-Lite/releases/latest");
};
}
})
.catch((err) => {
log(err, 3, "api", "check_update");
});
}

function ver_string_to_int(ver) {
if (ver.includes("-")) ver = ver.split("-")[0].replaceAll(".", "");
else ver = ver.replaceAll(".", "");
return ver;
}

function fetch_eew() {
const controller = new AbortController();
setTimeout(() => {
Expand Down
15 changes: 6 additions & 9 deletions core/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ function get_data(data, type = "websocket") {
const text = `${data.raw.originTime}\n${loc} 發生 M${report_scale} 地震`;
if (speecd_use) speech.speak({ text: `地震資訊,${text.replace("M", "規模").replace(".", "點")}` });
new Notification("⚠️ 地震資訊", {
body : text,
icon : "../TREM.ico",
silent : win.isFocused(),
body : text,
icon : "../TREM.ico",
});
} else return;
else {
Expand All @@ -86,9 +85,8 @@ function get_data(data, type = "websocket") {
const text = `${data.raw.originTime}\n${loc} 發生 M${report_scale} 地震\n最大震度 ${data.raw.data[0].areaName} ${data.raw.data[0].eqStation[0].stationName} ${I}`;
if (speecd_use) speech.speak({ text: `地震報告,${text.replace("M", "規模").replace(".", "點")}` });
new Notification("⚠️ 地震報告", {
body : text,
icon : "../TREM.ico",
silent : win.isFocused(),
body : text,
icon : "../TREM.ico",
});
show_screen("report");
}
Expand Down Expand Up @@ -165,9 +163,8 @@ function on_eew(data, type) {
const unit = (data.type == "eew-jma") ? "気象庁(JMA)" : (data.type == "eew-nied") ? "防災科学技術研究所" : (data.type == "eew-kma") ? "기상청(KMA)" : (data.type == "eew-scdzj") ? "四川省地震局" : (data.type == "eew-cwb") ? "交通部中央氣象局" : "TREM";
if (speecd_use) speech.speak({ text: `${data.location},發生規模${data.scale.toFixed(1).replace(".", "點")}地震` });
new Notification(`🚨 地震預警 第${data.number}報 | ${unit}`, {
body : `${time_to_string((data.replay_time) ? data.replay_time : data.time)}\n${data.location} 發生 M${data.scale.toFixed(1)} 地震`,
icon : "../TREM.ico",
silent : win.isFocused(),
body : `${time_to_string((data.replay_time) ? data.replay_time : data.time)}\n${data.location} 發生 M${data.scale.toFixed(1)} 地震`,
icon : "../TREM.ico",
});
if (!TREM.EQ_list[data.id]) {
show_screen("eew");
Expand Down
1 change: 1 addition & 0 deletions core/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ setInterval(() => {
get_station_info();
storage.setItem("report_data", []);
refresh_report_list(true);
check_update();
}
}, 60_000);
const audioContext = new AudioContext();
Expand Down
3 changes: 2 additions & 1 deletion core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ function set_user_location() {
TREM.setting.rts_station = storage.getItem("rts_station") ?? "H-711-11334880-12";
if (TREM.user.icon) TREM.user.icon.remove();
TREM.user.icon = L.marker([_lat, _lon], { icon: user_icon }).addTo(TREM.Maps.main);
}
}
check_update();
15 changes: 6 additions & 9 deletions core/rts.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,26 @@ function on_rts_data(data) {
TREM.audio.minor.push("Shindo2");
if (speecd_use) speech.speak({ text: `強震檢測,${loc}` });
new Notification("🟥 強震檢測", {
body : `${loc}`,
icon : "../TREM.ico",
silent : win.isFocused(),
body : `${loc}`,
icon : "../TREM.ico",
});
rts_screenshot();
} else if (max_intensity > 1) {
TREM.rts_audio.intensity = 4;
TREM.audio.minor.push("Shindo1");
if (speecd_use) speech.speak({ text: `震動檢測,${loc}` });
new Notification("🟨 震動檢測", {
body : `${loc}`,
icon : "../TREM.ico",
silent : win.isFocused(),
body : `${loc}`,
icon : "../TREM.ico",
});
rts_screenshot();
} else {
TREM.rts_audio.intensity = 1;
TREM.audio.minor.push("Shindo0");
if (speecd_use) speech.speak({ text: `弱反應,${loc}` });
new Notification("🟩 弱反應", {
body : `${loc}`,
icon : "../TREM.ico",
silent : win.isFocused(),
body : `${loc}`,
icon : "../TREM.ico",
});
rts_screenshot();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trem_lite",
"version": "1.4.5",
"version": "1.4.6",
"description": "Taiwan Real-time Earthquake Monitoring ( 臺灣即時地震監測 )",
"main": "main.js",
"author": {
Expand Down

0 comments on commit 7daabd6

Please sign in to comment.