Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect #23

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
62b113d
Update package-lock.json
lowrt Oct 28, 2023
d9294cb
Update README.md
lowrt Oct 28, 2023
edb86ab
Update package-lock.json
lowrt Oct 28, 2023
064d59b
Revert "Update package-lock.json"
lowrt Jan 4, 2024
f8d626b
Revert "Update package-lock.json"
lowrt Jan 4, 2024
767b881
Merge pull request #16 from lowrt/Release
whes1015 Jan 5, 2024
f2272f0
enable devtools
ids93216 Apr 24, 2024
2d8142e
api url fix
ids93216 Apr 24, 2024
5d0f4d6
api variables fix, remove unused data
ids93216 Apr 25, 2024
531b091
fix eew estimate time
ids93216 Apr 25, 2024
cec7082
add report detail
ids93216 Apr 25, 2024
66b6549
fix audio sorting
ids93216 Apr 25, 2024
911b16f
comment unused codes
ids93216 Apr 25, 2024
e019c65
add rts detail
ids93216 Apr 25, 2024
4358313
fix missing warnings
ids93216 Apr 25, 2024
bbd1451
fix audio playback speed
ids93216 Apr 25, 2024
00f86d8
update README, remove devtools
ids93216 Apr 25, 2024
c5f55d3
allow pack manually
ids93216 Apr 25, 2024
a160f44
remove p2p client.jar
ids93216 Apr 25, 2024
caaf0b3
fix epicenter won't remove when exit
ids93216 Apr 25, 2024
d701580
fix p_wave missing
ids93216 Apr 25, 2024
4874b57
fix time color wrong when replaying
ids93216 Apr 25, 2024
6b3486e
edit UI timeout warning
ids93216 Apr 25, 2024
cf5b811
edit disconnect detect
ids93216 Apr 25, 2024
ba02c19
edit disconnect detect websocket
ids93216 Apr 25, 2024
21dbc47
edit websocket connect msgs
ids93216 Apr 26, 2024
f6cee03
fix websocket error on reload
ids93216 Apr 26, 2024
5df4d20
add exptech login
ids93216 Apr 26, 2024
3cad045
edit api
ids93216 Apr 26, 2024
3f1ae0b
restore something
ids93216 Apr 26, 2024
95cef1b
fix real eew problem
ids93216 Apr 26, 2024
4aba534
fix not showing report on sratup
ids93216 Apr 26, 2024
5bf996c
Merge pull request #22 from ids93216/Release
whes1015 May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
![](https://img.shields.io/github/downloads/ExpTechTW/TREM-Lite/total)
> **Note**
> 2.0.0 版本修正新版 API(需進一步測試)

> **Note**
> 1.9.0 及後續版本加入 `P2P(中繼) 備援伺服器` `EEW 備援伺服器`
> - `p2p-1.exptech.com.tw:1015`
Expand Down Expand Up @@ -34,7 +37,7 @@ TREM Lite 是一款開源地震速報軟體,提供給您即時的地震資訊
## 注意事項
1. 使用過程中,請務必謹慎閱讀提示和注意事項
2. 使用過程中可能遇到無法理解的錯誤,但大部份不影響系統運作,如遇到錯誤請向開發人員回報
3. 即時測站資訊僅供參考,實際請以中央氣象局為主
3. 即時測站資訊僅供參考,實際請以中央氣象署為主
4. 此軟體僅供研究、學術及教育用途(不得營利),若使用則需接受相關風險
5. 任何不被官方所認可的行為均有可能被列入伺服器黑名單中,請務必遵守相關規範
6. 此程式為免費開源程式,不保證能永久營運
Expand Down
9 changes: 7 additions & 2 deletions src/core/index/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ document.getElementById("setting_button").onclick = () => {
ipcRenderer.send("openChildWindow");
};

document.getElementById("refresh_button").onclick = () => {
close();
setTimeout(() => ipcMain.emit("reload"), 500);
};

const location_button = document.getElementById("location_button");
location_button.style.border = "1px solid white";
location_button.onclick = () => {
if (location_button.style.color == "white") {
location_button.style.color = "grey";
if (location_button.style.color == "grey") {
location_button.style.color = "white";
location_button.style.border = "1px solid white";
focus_lock = false;
TREM.Maps.main.setView([23.6, 120.4], 7.8);
Expand Down
209 changes: 130 additions & 79 deletions src/core/index/api.js

Large diffs are not rendered by default.

Binary file removed src/core/index/client.jar
Binary file not shown.
49 changes: 0 additions & 49 deletions src/core/index/core.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,6 @@
/* eslint-disable no-undef */
const crypto = require("crypto");
const dgram = require("dgram");
const client = dgram.createSocket("udp4");

const EventEmitter = require("events").EventEmitter;
const event = new EventEmitter();

const win = BrowserWindow.fromId(process.env.window * 1);

// if (fs.existsSync(path.resolve(app.getAppPath(), "./core/index/client.js"))) {
// const vm = require("vm");
// const v8 = require("v8");
// v8.setFlagsFromString("--no-lazy");
// const code = fs.readFileSync(path.resolve(app.getAppPath(), "./core/index/client.js"), "utf-8");
// const script = new vm.Script(code);
// const bytecode = script.createCachedData();
// fs.writeFileSync(path.resolve(app.getAppPath(), "./core/index/client.jar"), bytecode);
// }

bytenode.runBytecodeFile(path.resolve(app.getAppPath(), "./core/index/client.jar"));

event.on("data", (data) => get_data(data, "p2p"));

event.on("log", (data) => log(data.msg, data.type));

client.on("listening", () => {
const address = client.address();
log(`Client listening on ${address.address}:${address.port}`, 1);
});

get_server_info();
async function get_server_info() {
try {
const controller = new AbortController();
setTimeout(() => controller.abort(), 1500);
let ans = await fetch("https://cdn.jsdelivr.net/gh/ExpTechTW/API@master/resource/server_list.json", { signal: controller.signal })
.catch((err) => void 0);
if (controller.signal.aborted || !ans) {
setTimeout(() => get_server_info(), 500);
return;
}
ans = await ans.json();
init(client, event, {
server_list: ans.p2p,
}, crypto);
} catch (err) {
log(err, 3, "core", "get_server_info");
setTimeout(() => get_server_info(), 500);
}
}

log("Start", 1, "log", "~");

ipcMain.on("replay_start", (e, time) => {
Expand Down
32 changes: 11 additions & 21 deletions src/core/index/eew.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,22 @@ function eew(_eew) {
const data = TREM.EQ_list[show_eew_id].data;
const eew_max_intensity = TREM.EQ_list[show_eew_id].eew;
const alert = TREM.EQ_list[show_eew_id].alert;
const unit = (data.type == "eew-jma") ? "JMA" : (data.type == "eew-nied") ? "NIED" : (data.type == "eew-kma") ? "KMA" : (data.type == "eew-scdzj") ? "SCDZJ" : (data.type == "eew-cwb") ? "CWA" : "TREM";
const unit = data.author;
document.getElementById("eew_title_text").textContent = `${unit} ${get_lang_string("eew.title").replace("${type}", (data.cancel) ? get_lang_string("eew.cancel") : (data.Test) ? get_lang_string("eew.test") : (alert) ? get_lang_string("eew.alert") : get_lang_string("eew.warn"))}${(eew_list.length == 1) ? "" : ` ${eew_number + 1}/${eew_list.length}`}`;
document.getElementById("eew_title_text_number").textContent = `${get_lang_string("eew.number").replace("${number}", data.number)}${(data.final) ? `(${get_lang_string("eew.final")})` : ""}`;
document.getElementById("eew_box").style.backgroundColor = (data.cancel) ? "#333439" : (data.Test) ? "darkviolet" : (data.model == "nsspe" || data.scale == 1) ? "darkblue" : (alert) ? "red" : "#FF9224";
document.getElementById("eew_title_text_number").textContent = `${get_lang_string("eew.number").replace("${number}", data.serial)}${(data.final) ? `(${get_lang_string("eew.final")})` : ""}`;
document.getElementById("eew_box").style.backgroundColor = (data.status == 2) ? "#333439" : (data.status == 3) ? "darkviolet" : (data.eq.mag == 1) ? "darkblue" : (alert) ? "red" : "#FF9224";
const eew_body = document.getElementById("eew_body");
eew_body.style.backgroundColor = "#514339";
eew_body.style.border = "2px solid black";
const eew_intensity = document.getElementById("eew_intensity");
eew_intensity.className = `intensity_${eew_max_intensity} intensity_center`;
eew_intensity.textContent = (data.model == "nsspe" && !eew_max_intensity) ? "不明" : int_to_intensity(eew_max_intensity);
if (data.model == "nsspe" && !eew_max_intensity) {
eew_intensity.style.fontSize = 30;
} else {
eew_intensity.style.fontSize = 50;
}
eew_intensity.textContent = int_to_intensity(eew_max_intensity);
eew_intensity.style.fontSize = 50;
const eew_location = document.getElementById("eew_location");
eew_location.style.fontSize = (data.location.length > 10) ? "16px" : (data.location.length > 7) ? "20px" : "24px";
eew_location.textContent = `${data.location}`;
eew_location.style.fontSize = (data.eq.loc.length > 10) ? "16px" : (data.eq.loc.length > 7) ? "20px" : "24px";
eew_location.textContent = `${data.eq.loc}`;

const now = new Date((data.replay_time) ? data.replay_time : data.time);
const now = new Date((data.replay_time) ? data.replay_time : data.eq.time);
let eew_time = now.getFullYear().toString();
eew_time += "/";
if ((now.getMonth() + 1) < 10) {
Expand Down Expand Up @@ -80,31 +76,25 @@ function eew(_eew) {
} else {
eew_time += now.getSeconds().toString();
}
let eew_scale = data.scale.toString();
let eew_scale = data.eq.mag.toString();
if (eew_scale.length == 1) {
eew_scale = eew_scale + ".0";
}
document.getElementById("eew_time").textContent = get_lang_string("eew.time").replace("${time}", eew_time);
const text_title = document.getElementById("eew_scale");
const text_body = document.getElementById("eew_args");
if (data.scale == 1) {
if (data.eq.mag == 1) {
text_title.style.fontSize = 18;
text_title.textContent = "PLUM";
text_body.style.fontSize = 12;
text_body.style.textAlign = "start";
text_body.textContent = "局部無阻尼運動傳播法";
} else if (data.model == "nsspe") {
text_title.style.fontSize = 18;
text_title.textContent = "NSSPE";
text_body.style.fontSize = 14;
text_body.style.textAlign = "start";
text_body.textContent = "無震源參數推算";
} else {
text_title.style.fontSize = 26;
text_body.style.fontSize = 18;
text_body.style.textAlign = "right";
text_title.textContent = `M ${eew_scale}`;
text_body.innerHTML = `${get_lang_string("word.depth")}:&nbsp;<b>${data.depth}</b>&nbsp;km`;
text_body.innerHTML = `${get_lang_string("word.depth")}:&nbsp;<b>${data.eq.depth}</b>&nbsp;km`;
}
}
}
105 changes: 39 additions & 66 deletions src/core/index/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ let _id = "";
let type_list = {
time : 0,
http : 0,
p2p : 0,
fcm : 0,
websocket : 0,
};

Expand Down Expand Up @@ -44,11 +42,7 @@ const item_audio_eew2 = storage.getItem("audio.EEW2") ?? true;
function get_data(data, type = "websocket") {
if (data.type != "trem-rts") {
type_list.time = now_time();
if (type == "p2p") {
type_list.p2p = now_time();
} else if (type == "fcm") {
type_list.fcm = now_time();
} else if (type == "websocket") {
if (type == "websocket") {
type_list.websocket = now_time();
} else if (type == "http") {
type_list.http = now_time();
Expand Down Expand Up @@ -80,12 +74,6 @@ function get_data(data, type = "websocket") {
if (data_cache.length > 15) {
data_cache.splice(0, 1);
}
if (data.type == "trem-eew" && !item_trem_eew) {
return;
}
if (data.model == "eew") {
data.type = "eew-trem";
}
if (data.type == "trem-rts") {
if (!rts_replay_time) {
on_rts_data(data.raw);
Expand Down Expand Up @@ -140,7 +128,7 @@ function get_data(data, type = "websocket") {
eq_station_list[station.stationIntensity].push(`${city.areaName}${station.stationName}`);
}
}
console.log(eq_station_list);
// console.log(eq_station_list);
let count = 0;
for (let i = 9; i >= 1; i--) {
if (!eq_station_list[i].length) {
Expand Down Expand Up @@ -174,25 +162,7 @@ function get_data(data, type = "websocket") {
refresh_report_list(false, data);
screenshot_id = `report_${now_time()}`;
plugin.emit("trem.report.on-report", data);
} else if (data.type == "eew-report" || data.type == "eew-trem" || data.type == "eew-cwb" || data.type == "eew-scdzj" || data.type == "eew-kma" || data.type == "eew-jma" || data.type == "eew-nied") {
if ((data.type == "eew-jma" || data.type == "eew-nied") && data.location == "台湾付近") {
return;
}
if (data.type == "eew-jma" && !item_jma_eew) {
return;
}
if (data.type == "eew-kma" && !item_kma_eew) {
return;
}
if (data.type == "eew-nied" && !item_nied_eew) {
return;
}
if (data.type == "eew-scdzj" && !item_scdzj_eew) {
return;
}
if (data.type == "eew-cwb" && !item_cwb_eew) {
return;
}
} else if (data.type == "eew-report" || data.type == "eew-cwb") {
if (Now().getTime() - data.time > 240_000 && !data.replay_timestamp) {
return;
}
Expand Down Expand Up @@ -225,6 +195,7 @@ function get_data(data, type = "websocket") {
}

function on_eew(data, type) {
// console.log(data)
TREM.eew = true;
let skip = false;
if (item_eew_level != -1) {
Expand All @@ -251,8 +222,8 @@ function on_eew(data, type) {
eew : 0,
alert : false,
};
if (!eew_cache.includes(data.id + data.number)) {
eew_cache.push(data.id + data.number);
if (!eew_cache.includes(data.id + data.serial)) {
eew_cache.push(data.id + data.serial);
if (!skip && item_audio_eew) {
TREM.audio.push("EEW");
}
Expand All @@ -262,14 +233,14 @@ function on_eew(data, type) {
TREM.EQ_list[data.id].loc = eew;
plugin.emit("trem.eew.on-eew-create", data);
} else {
if (!data.location) {
data.location = TREM.EQ_list[data.id].data.location;
if (!data.eq.loc) {
data.eq.loc = TREM.EQ_list[data.id].data.eq.loc;
}
if (!data.lat) {
data.lat = TREM.EQ_list[data.id].data.lat;
if (!data.eq.lat) {
data.eq.lat = TREM.EQ_list[data.id].data.eq.lat;
}
if (!data.lon) {
data.lon = TREM.EQ_list[data.id].data.lon;
if (!data.eq.lon) {
data.eq.lon = TREM.EQ_list[data.id].data.eq.lon;
}
TREM.EQ_list[data.id].data = data;
if (data.cancel) {
Expand All @@ -286,19 +257,19 @@ function on_eew(data, type) {
}
} else {
if (TREM.EQ_list[data.id].p_wave) {
TREM.EQ_list[data.id].p_wave.setLatLng([data.lat, data.lon]);
TREM.EQ_list[data.id].p_wave.setLatLng([data.eq.lat, data.eq.lon]);
}
if (TREM.EQ_list[data.id].s_wave) {
TREM.EQ_list[data.id].s_wave.setLatLng([data.lat, data.lon]);
TREM.EQ_list[data.id].s_wave.setLatLng([data.eq.lat, data.eq.lon]);
}
if (TREM.EQ_list[data.id].s_wave_back) {
TREM.EQ_list[data.id].s_wave_back.setLatLng([data.lat, data.lon]);
TREM.EQ_list[data.id].s_wave_back.setLatLng([data.eq.lat, data.eq.lon]);
}
}
if (item_audio_update) {
TREM.audio.push("update");
}
const eew = eew_location_intensity(data, data.depth);
const eew = eew_location_intensity(data, data.eq.depth);
data.max = intensity_float_to_int(eew.max_i);
TREM.EQ_list[data.id].loc = eew;
TREM.EQ_list[data.id].eew = intensity_float_to_int(TREM.EQ_list[data.id].loc.max_i);
Expand All @@ -314,16 +285,16 @@ function on_eew(data, type) {
TREM.EQ_list[data.id].epicenterIcon.remove();
delete TREM.EQ_list[data.id].epicenterIcon;
}
if (data.type == "eew-cwb" && data.location.includes("海") && Number(data.depth) <= 35) {
if (Number(data.scale) >= 7) {
if (data.type == "eew-cwb" && data.eq.loc.includes("海") && Number(data.eq.depth) <= 35) {
if (Number(data.eq.mag) >= 7) {
if (!TREM.EQ_list[data.id].alert_tsunami) {
TREM.EQ_list[data.id].alert_tsunami = true;
if (!skip && speecd_use) {
setTimeout(() => speech.speak({ text: "震源位置及規模表明,可能發生海嘯,沿岸地區應慎防海水位突變,並留意中央氣象署是否發布,海嘯警報" }), 15000);
}
add_info("fa-solid fa-house-tsunami fa-2x info_icon", "#0072E3", "注意海嘯", "#FF5809", "震源位置及規模表明<br>可能發生海嘯<br>沿岸地區應慎防海水位突變<br>並留意 中央氣象署(CWA)<br>是否發布 [ 海嘯警報 ]");
}
} else if (Number(data.scale) >= 6) {
} else if (Number(data.eq.mag) >= 6) {
if (!TREM.EQ_list[data.id].alert_sea) {
TREM.EQ_list[data.id].alert_sea = true;
if (!skip && speecd_use) {
Expand All @@ -333,28 +304,30 @@ function on_eew(data, type) {
}
}
}
const notification = new Notification(`🚨 地震預警 第${data.number}報 | ${unit}`, {
body : `${time_to_string((data.replay_time) ? data.replay_time : data.time)}\n${data.location} ${(data.cancel) ? "取消" : `發生 M${data.scale.toFixed(1)} 地震`}`,
icon : "../TREM.ico",
});
notification.addEventListener("click", () => MainWindow.focus());
if (_id != data.id) {
_id = data.id;
_list = "";
_max = -1;
_location = "";
if (!data.replay_timestamp) {
const notification = new Notification(`🚨 地震預警 第${data.serial}報 | ${unit}`, {
body : `${time_to_string((data.eq.time) ? data.eq.time : data.time)}\n${data.eq.loc} ${(data.status == 2) ? "取消" : `發生 M${data.eq.mag.toFixed(1)} 地震`}`,
icon : "../TREM.ico",
});
notification.addEventListener("click", () => MainWindow.focus());
if (_id != data.id) {
_id = data.id;
_list = "";
_max = -1;
_location = "";
}
}
if (data.cancel) {
if (data.status == 2) {
if (!skip && speecd_use) {
loc_speech_clock = false;
eew_speech_clock = false;
speech.speak({ text: `${data.location},取消` });
speech.speak({ text: `${data.eq.loc},取消` });
}
plugin.emit("trem.eew.on-eew-cancel", data);
} else if (!skip && speecd_use) {
eew_speech = {
loc : data.location,
max : data.max,
loc : data.eq.loc,
max : data.eq.max,
};
eew_speech_clock = true;
}
Expand Down Expand Up @@ -390,20 +363,20 @@ function on_eew(data, type) {
}
if (TREM.EQ_list[_data.id].epicenterIcon) {
TREM.EQ_list[_data.id].epicenterIcon.setIcon(epicenterIcon);
TREM.EQ_list[_data.id].epicenterIcon.setLatLng([_data.lat + offsetY, _data.lon + offsetX]);
TREM.EQ_list[_data.id].epicenterIcon.setLatLng([_data.eq.lat + offsetY, _data.eq.lon + offsetX]);
} else {
TREM.EQ_list[_data.id].epicenterIcon = L.marker([_data.lat + offsetY, _data.lon + offsetX], { icon: epicenterIcon, zIndexOffset: 6000 }).addTo(TREM.Maps.main);
TREM.EQ_list[_data.id].epicenterIcon = L.marker([_data.eq.lat + offsetY, _data.eq.lon + offsetX], { icon: epicenterIcon, zIndexOffset: 6000 }).addTo(TREM.Maps.main);
}
}
} else if (TREM.EQ_list[data.id].epicenterIcon) {
TREM.EQ_list[data.id].epicenterIcon.setLatLng([data.lat, data.lon]);
TREM.EQ_list[data.id].epicenterIcon.setLatLng([data.eq.lat, data.eq.lon]);
} else {
epicenterIcon = L.icon({
iconUrl : "../resource/images/cross.png",
iconSize : [40 + TREM.size * 3, 40 + TREM.size * 3],
className : "flash",
});
TREM.EQ_list[data.id].epicenterIcon = L.marker([data.lat, data.lon], { icon: epicenterIcon, zIndexOffset: 6000 })
TREM.EQ_list[data.id].epicenterIcon = L.marker([data.eq.lat, data.eq.lon], { icon: epicenterIcon, zIndexOffset: 6000 })
.addTo(TREM.Maps.main);
}
const _loc_list = TREM.EQ_list[data.id].loc;
Expand Down
2 changes: 0 additions & 2 deletions src/core/index/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ const speech = new Speech.default();
await speech.init();
speech.setLanguage("zh-TW");
speech.setVoice("Microsoft Zhiwei - Chinese (Traditional, Taiwan)");
// speech.setLanguage("ja-JP");
// speech.setVoice("Microsoft Sayaka - Japanese (Japan)");
speech.setRate(1.8);
})();
Loading
Loading