diff --git a/core/api.js b/core/api.js index 415f53c3..656591eb 100644 --- a/core/api.js +++ b/core/api.js @@ -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 = []; @@ -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(() => { diff --git a/core/event.js b/core/event.js index 2eb5fabc..8d0b2c65 100644 --- a/core/event.js +++ b/core/event.js @@ -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 { @@ -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"); } @@ -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"); diff --git a/core/loop.js b/core/loop.js index 3cbae1d7..cb8aa909 100644 --- a/core/loop.js +++ b/core/loop.js @@ -182,6 +182,7 @@ setInterval(() => { get_station_info(); storage.setItem("report_data", []); refresh_report_list(true); + check_update(); } }, 60_000); const audioContext = new AudioContext(); diff --git a/core/main.js b/core/main.js index bea932fa..bacfe1f8 100644 --- a/core/main.js +++ b/core/main.js @@ -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); -} \ No newline at end of file +} +check_update(); \ No newline at end of file diff --git a/core/rts.js b/core/rts.js index b89bd93b..e63ad008 100644 --- a/core/rts.js +++ b/core/rts.js @@ -175,9 +175,8 @@ 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) { @@ -185,9 +184,8 @@ function on_rts_data(data) { 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 { @@ -195,9 +193,8 @@ function on_rts_data(data) { 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(); } diff --git a/package.json b/package.json index 83599f35..b7a63e67 100644 --- a/package.json +++ b/package.json @@ -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": {