|
|
@ -23,7 +23,7 @@ fn fetchThread(state: *AppState) !void { |
|
|
|
defer state.departure_screen_state.fetch_thread = null; |
|
|
|
defer state.departure_screen_state.fetch_thread = null; |
|
|
|
const allocator = state.allocator; |
|
|
|
const allocator = state.allocator; |
|
|
|
var station_id_buf = std.BoundedArray(u8, 10){}; |
|
|
|
var station_id_buf = std.BoundedArray(u8, 10){}; |
|
|
|
var include_tram = false; |
|
|
|
var transport_means = state.departure_screen_state.transport_means; |
|
|
|
var curl = Curl.init() orelse return; |
|
|
|
var curl = Curl.init() orelse return; |
|
|
|
defer curl.deinit(); |
|
|
|
defer curl.deinit(); |
|
|
|
|
|
|
|
|
|
|
@ -32,14 +32,16 @@ fn fetchThread(state: *AppState) !void { |
|
|
|
if (state.departure_screen_state.last_refresh_time + 30000 < std.time.milliTimestamp()) { |
|
|
|
if (state.departure_screen_state.last_refresh_time + 30000 < std.time.milliTimestamp()) { |
|
|
|
fetch_anyway = true; |
|
|
|
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) { |
|
|
|
const same_station = std.mem.eql(u8, station_id_buf.slice(), state.departure_screen_state.station_id.items); |
|
|
|
|
|
|
|
const same_transport_means = std.meta.eql(transport_means, state.departure_screen_state.transport_means); |
|
|
|
|
|
|
|
if (!fetch_anyway and same_station and same_transport_means) { |
|
|
|
std.time.sleep(100 * 1000); |
|
|
|
std.time.sleep(100 * 1000); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
station_id_buf.resize(state.departure_screen_state.station_id.items.len) catch continue; |
|
|
|
station_id_buf.resize(state.departure_screen_state.station_id.items.len) catch continue; |
|
|
|
std.mem.copyForwards(u8, station_id_buf.slice(), state.departure_screen_state.station_id.items); |
|
|
|
std.mem.copyForwards(u8, station_id_buf.slice(), state.departure_screen_state.station_id.items); |
|
|
|
include_tram = state.departure_screen_state.include_tram; |
|
|
|
transport_means = state.departure_screen_state.transport_means; |
|
|
|
std.debug.print("[departure/fetchThread] Detected update: {s}\n", .{station_id_buf.slice()}); |
|
|
|
std.debug.print("[departure/fetchThread] Detected update: {s}\n", .{station_id_buf.slice()}); |
|
|
|
|
|
|
|
|
|
|
|
curl.reset(); |
|
|
|
curl.reset(); |
|
|
@ -51,9 +53,20 @@ fn fetchThread(state: *AppState) !void { |
|
|
|
) catch continue; |
|
|
|
) catch continue; |
|
|
|
defer allocator.free(departures_base); |
|
|
|
defer allocator.free(departures_base); |
|
|
|
var departures_uri = std.Uri.parse(departures_base) catch unreachable; |
|
|
|
var departures_uri = std.Uri.parse(departures_base) catch unreachable; |
|
|
|
const query = std.fmt.allocPrint(allocator, "duration=300&bus=false&ferry=false&taxi=false&pretty=false{s}", .{if (include_tram) "" else "&tram=false&subway=false"}) catch continue; |
|
|
|
var queryBuilder = std.ArrayList(u8).init(allocator); |
|
|
|
defer allocator.free(query); |
|
|
|
defer queryBuilder.deinit(); |
|
|
|
departures_uri.query = query; |
|
|
|
queryBuilder.appendSlice("duration=300&pretty=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.ice) queryBuilder.appendSlice("&nationalExpress=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.ic) queryBuilder.appendSlice("&national=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.ir) queryBuilder.appendSlice("®ionalExpress=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.r) queryBuilder.appendSlice("®ional=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.s) queryBuilder.appendSlice("&suburban=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.bus) queryBuilder.appendSlice("&bus=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.ferry) queryBuilder.appendSlice("&ferry=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.u) queryBuilder.appendSlice("&subway=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.tram) queryBuilder.appendSlice("&tram=false") catch continue; |
|
|
|
|
|
|
|
if (!transport_means.taxi) queryBuilder.appendSlice("&taxi=false") catch continue; |
|
|
|
|
|
|
|
departures_uri.query = queryBuilder.items; |
|
|
|
defer departures_uri.query = null; |
|
|
|
defer departures_uri.query = null; |
|
|
|
std.debug.print("[departure/fetchThread] Making request to: {}\n", .{departures_uri}); |
|
|
|
std.debug.print("[departure/fetchThread] Making request to: {}\n", .{departures_uri}); |
|
|
|
|
|
|
|
|
|
|
@ -635,7 +648,8 @@ pub fn render(state: *AppState) !void { |
|
|
|
ds.max_next_trains = @min(ds.max_next_trains + 1, if (ds.fetch_result) |fr| @as(c_int, @intCast(fr.value.object.get("departures").?.array.items.len)) else 5); |
|
|
|
ds.max_next_trains = @min(ds.max_next_trains + 1, if (ds.fetch_result) |fr| @as(c_int, @intCast(fr.value.object.get("departures").?.array.items.len)) else 5); |
|
|
|
}, |
|
|
|
}, |
|
|
|
rl.KEY_T => { |
|
|
|
rl.KEY_T => { |
|
|
|
ds.include_tram = !ds.include_tram; |
|
|
|
ds.transport_means.u = !ds.transport_means.u; |
|
|
|
|
|
|
|
ds.transport_means.tram = !ds.transport_means.tram; |
|
|
|
}, |
|
|
|
}, |
|
|
|
rl.KEY_ONE => { |
|
|
|
rl.KEY_ONE => { |
|
|
|
ds.render_style = .db1; |
|
|
|
ds.render_style = .db1; |
|
|
|