Skip to content

Commit da9ab1d

Browse files
committed
Sane session window construction.
Signed-off-by: Katharine Berry <[email protected]>
1 parent 1a0d7a1 commit da9ab1d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

app/src/c/converse/session_window.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ struct SessionWindow {
4848
time_t query_time;
4949
AppTimer *timeout_handle;
5050
ActionMenuLevel *action_menu;
51+
int timeout;
5152
};
5253

53-
// this is a stupid hack because the way the session window is pushed is also stupid for some reason
54-
// since we only ever have one session window, we get away with it. but ew.
55-
static int s_timeout = 0;
56-
5754
static void prv_window_load(Window *window);
5855
static void prv_window_appear(Window *window);
5956
static void prv_window_disappear(Window *window);
@@ -75,8 +72,11 @@ static void prv_action_menu_report_thread(ActionMenu *action_menu, const ActionM
7572

7673
void session_window_push(int timeout) {
7774
Window *window = window_create();
78-
window_set_user_data(window, (void *)1);
79-
s_timeout = timeout;
75+
SessionWindow *sw = malloc(sizeof(SessionWindow));
76+
memset(sw, 0, sizeof(SessionWindow));
77+
window_set_user_data(window, sw);
78+
sw->window = window;
79+
sw->timeout = timeout;
8080
window_set_window_handlers(window, (WindowHandlers) {
8181
.load = prv_window_load,
8282
.unload = prv_window_unload,
@@ -112,11 +112,9 @@ static void prv_window_load(Window *window) {
112112
Layer* root_layer = window_get_root_layer(window);
113113
bool start_dictation = (bool)window_get_user_data(window);
114114
GSize window_size = layer_get_frame(window_get_root_layer(window)).size;
115-
SessionWindow *sw = malloc(sizeof(SessionWindow));
116-
memset(sw, 0, sizeof(SessionWindow));
115+
SessionWindow *sw = window_get_user_data(window);
117116
sw->dictation_pending = start_dictation;
118117
APP_LOG(APP_LOG_LEVEL_INFO, "created SessionWindow %p.", sw);
119-
sw->window = window;
120118
sw->manager = conversation_manager_create();
121119
conversation_manager_set_handler(sw->manager, prv_conversation_manager_handler, sw);
122120
sw->dictation = dictation_session_create(0, prv_dictation_status_callback, sw);
@@ -402,14 +400,14 @@ static void prv_scrolled_handler(ScrollLayer* scroll_layer, void* context) {
402400
}
403401

404402
static void prv_refresh_timeout(SessionWindow* sw) {
405-
if (s_timeout == 0) {
403+
if (sw->timeout == 0) {
406404
return;
407405
}
408406
if (sw->timeout_handle) {
409407
app_timer_cancel(sw->timeout_handle);
410408
}
411409
APP_LOG(APP_LOG_LEVEL_DEBUG, "Refreshed timeout");
412-
sw->timeout_handle = app_timer_register(s_timeout, prv_timed_out, sw);
410+
sw->timeout_handle = app_timer_register(sw->timeout, prv_timed_out, sw);
413411
}
414412

415413
static void prv_cancel_timeout(SessionWindow* sw) {

0 commit comments

Comments
 (0)