Add auto refresh every minute
This commit is contained in:
parent
cd8b03424d
commit
276f51fc5f
2 changed files with 6 additions and 2 deletions
|
@ -15,7 +15,10 @@ fn fetchThread(state: *AppState) !void {
|
||||||
defer curl.deinit();
|
defer curl.deinit();
|
||||||
|
|
||||||
while (state.departure_screen_state.fetch_thread != null) {
|
while (state.departure_screen_state.fetch_thread != null) {
|
||||||
const fetch_anyway = state.departure_screen_state.should_refresh;
|
var fetch_anyway = state.departure_screen_state.should_refresh;
|
||||||
|
if (state.departure_screen_state.last_refresh_time + 60000 < std.time.milliTimestamp()) {
|
||||||
|
fetch_anyway = true;
|
||||||
|
}
|
||||||
if (!fetch_anyway and std.mem.eql(u8, station_id_buf.slice(), state.departure_screen_state.station_id.items) and include_tram == state.departure_screen_state.include_tram) {
|
if (!fetch_anyway and std.mem.eql(u8, station_id_buf.slice(), state.departure_screen_state.station_id.items) and include_tram == state.departure_screen_state.include_tram) {
|
||||||
std.time.sleep(100 * 1000);
|
std.time.sleep(100 * 1000);
|
||||||
continue;
|
continue;
|
||||||
|
@ -64,6 +67,7 @@ fn fetchThread(state: *AppState) !void {
|
||||||
}
|
}
|
||||||
state.departure_screen_state.fetch_result = parsed;
|
state.departure_screen_state.fetch_result = parsed;
|
||||||
state.departure_screen_state.should_refresh = false;
|
state.departure_screen_state.should_refresh = false;
|
||||||
|
state.departure_screen_state.last_refresh_time = std.time.milliTimestamp();
|
||||||
}
|
}
|
||||||
if (state.departure_screen_state.fetch_result) |old_result| {
|
if (state.departure_screen_state.fetch_result) |old_result| {
|
||||||
old_result.deinit();
|
old_result.deinit();
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub const DepartureScreenState = struct {
|
||||||
platform: std.ArrayListUnmanaged(u8),
|
platform: std.ArrayListUnmanaged(u8),
|
||||||
departure_date: std.time.Instant,
|
departure_date: std.time.Instant,
|
||||||
fetch_thread: ?std.Thread = null,
|
fetch_thread: ?std.Thread = null,
|
||||||
last_refresh_time: std.time.Instant = std.mem.zeroInit(std.time.Instant, .{}),
|
last_refresh_time: i64 = 0,
|
||||||
fetch_result: ?std.json.Parsed(std.json.Value) = null,
|
fetch_result: ?std.json.Parsed(std.json.Value) = null,
|
||||||
should_refresh: bool = false,
|
should_refresh: bool = false,
|
||||||
max_next_trains: c_int = 5,
|
max_next_trains: c_int = 5,
|
||||||
|
|
Loading…
Add table
Reference in a new issue