Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

feat: auto updates report lists #32

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 新增開機時自動啟動的設定 (https://github.com/ExpTechTW/TREM-tauri/pull/30)
* 新增最小化至系統匣的設定 (https://github.com/ExpTechTW/TREM-tauri/pull/30)
* 新增啟動參數 `--quiet` 在開啟程式時隱藏視窗 (https://github.com/ExpTechTW/TREM-tauri/pull/30)
* 自動抓取並更新地震報告 (https://github.com/ExpTechTW/TREM-tauri/pull/32)

**完整變更紀錄**: https://github.com/ExpTechTW/TREM-tauri/compare/v0.0.0-alpha.2...v0.0.0-alpha.3

Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const instance = app.mount("#app") as InstanceType<typeof App>;

api.setApiKey(await setting.get("api.key"));

props.reports.push(...(await api.getReports(50)));
props.reports.push(...(await api.getReports()));
props.stations.value = await api.getStations();

await browserWindow.setAlwaysOnTop(setting.settings.behavior.alwaysOnTop);
Expand All @@ -79,6 +79,14 @@ const instance = app.mount("#app") as InstanceType<typeof App>;
} else {
disableAutoStart();
}

timer.reportFetchTimer = window.setInterval(async () => {
const ids = props.reports.map((r) => r.id);
const reports = (await api.getReports()).filter((r) => !ids.includes(r.id));

props.reports.push(...reports);
props.reports.sort((a, b) => b.time - a.time);
}, 60_000);
})();

let replayMode: boolean = false;
Expand Down
Loading