@@ -828,44 +828,30 @@ static void prv_window_load(Window *window) {
828828}
829829// Window Unload event
830830static void prv_window_unload (Window * window ) {
831- layer_destroy (back_layer );
831+ layer_destroy (back_layer );
832+ window_destroy (s_main_window );
833+ text_layer_destroy (line1 .currentLayer );
834+ text_layer_destroy (line1 .nextLayer );
835+ text_layer_destroy (line2 .currentLayer );
836+ text_layer_destroy (line2 .nextLayer );
837+ text_layer_destroy (line3 .currentLayer );
838+ text_layer_destroy (line3 .nextLayer );
839+ layer_destroy (scroll );
840+ fonts_unload_custom_font (FontCond );
841+ fonts_unload_custom_font (Bold );
842+ fonts_unload_custom_font (BoldReduced1 );
843+ fonts_unload_custom_font (BoldReduced2 );
844+ fonts_unload_custom_font (Light );
845+ fonts_unload_custom_font (LightReduced1 );
846+ fonts_unload_custom_font (LightReduced2 );
847+ fonts_unload_custom_font (FontWDay );
848+ fonts_unload_custom_font (FontDate );
849+ fonts_unload_custom_font (FontSymbol );
832850}
833- static void prv_init (void ) {
834- prv_load_settings ();
835-
836- //Starting loop at 0
837- s_loop = 0 ;
838- s_countdown = settings .UpSlider ;
839- //Clean vars
840- strcpy (tempstring , "" );
841- strcpy (condstringday , "" );
842- strcpy (condstringnight , "" );
843-
844-
845- // Listen for AppMessages
846- app_message_register_inbox_received (prv_inbox_received_handler );
847- app_message_open (256 , 256 );
848851
849- // Configure main window
850- s_main_window = window_create ();
851- window_set_window_handlers (s_main_window , (WindowHandlers ) {
852- .load = prv_window_load ,
853- .unload = prv_window_unload ,
854- });
852+ void main_window_push () {
853+ s_main_window = window_create ();
855854
856- // Load fonts
857- Bold = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_39 ));
858- BoldReduced1 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_34 ));
859- BoldReduced2 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_30 ));
860- Light = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_39 ));
861- LightReduced1 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_34 ));
862- LightReduced2 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_30 ));
863- FontCond = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_WICON_26 ));
864- FontWDay = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_16 ));
865- FontDate = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_16 ));
866- FontSymbol = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_SYMBOL_16 ));
867-
868- window_stack_push (s_main_window , true);
869855 Layer * root = window_get_root_layer (s_main_window );
870856
871857 //Set bounds and offsets
@@ -898,9 +884,48 @@ static void prv_init(void) {
898884 layer_add_child (scroll , (Layer * )line2 .nextLayer );
899885 layer_add_child (scroll , (Layer * )line3 .currentLayer );
900886 layer_add_child (scroll , (Layer * )line3 .nextLayer );
901-
887+
888+ // Configure main window
889+ window_set_window_handlers (s_main_window , (WindowHandlers ) {
890+ .load = prv_window_load ,
891+ .unload = prv_window_unload ,
892+ });
893+
894+
895+ window_stack_push (s_main_window , true);
896+ }
897+
902898
899+ static void prv_init (void ) {
900+ prv_load_settings ();
901+
902+ //Starting loop at 0
903+ s_loop = 0 ;
904+ s_countdown = settings .UpSlider ;
905+ //Clean vars
906+ strcpy (tempstring , "" );
907+ strcpy (condstringday , "" );
908+ strcpy (condstringnight , "" );
909+
910+
911+ // Listen for AppMessages
912+ app_message_register_inbox_received (prv_inbox_received_handler );
913+ app_message_open (256 , 256 );
914+
915+ // Load fonts
916+ Bold = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_39 ));
917+ BoldReduced1 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_34 ));
918+ BoldReduced2 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_30 ));
919+ Light = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_39 ));
920+ LightReduced1 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_34 ));
921+ LightReduced2 = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_30 ));
922+ FontCond = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_WICON_26 ));
923+ FontWDay = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GBOLD_16 ));
924+ FontDate = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_GLIGHT_16 ));
925+ FontSymbol = fonts_load_custom_font (resource_get_handle (RESOURCE_ID_FONT_SYMBOL_16 ));
903926
927+ main_window_push ();
928+
904929 // Configure text time on init
905930 time_t now = time (NULL );
906931 struct tm * t = localtime (& now );
@@ -935,16 +960,9 @@ static void prv_init(void) {
935960 }
936961}
937962static void prv_deinit (void ) {
938- window_destroy ( s_main_window );
963+
939964 tick_timer_service_unsubscribe ();
940- app_message_deregister_callbacks (); //Destroy the callbacks for clean up
941- text_layer_destroy (line1 .currentLayer );
942- text_layer_destroy (line1 .nextLayer );
943- text_layer_destroy (line2 .currentLayer );
944- text_layer_destroy (line2 .nextLayer );
945- text_layer_destroy (line3 .currentLayer );
946- text_layer_destroy (line3 .nextLayer );
947- layer_destroy (scroll );
965+ app_message_deregister_callbacks (); //Destroy the callbacks for clean up
948966}
949967int main (void ) {
950968 prv_init ();
0 commit comments