totp_app_settings.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. #include "totp_app_settings.h"
  2. #include <math.h>
  3. #include <totp_icons.h>
  4. #include "../../../services/fonts/font_provider.h"
  5. #include "../../canvas_extensions.h"
  6. #include "../../ui_controls.h"
  7. #include "../../common_dialogs.h"
  8. #include "../../scene_director.h"
  9. #include "../../constants.h"
  10. #include "../../../services/config/config.h"
  11. #include "../../../services/convert/convert.h"
  12. #include "../../../services/kb_layouts/kb_layout_provider.h"
  13. #include <roll_value.h>
  14. #include "../../../config/app/config.h"
  15. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  16. #include "../../../workers/bt_type_code/bt_type_code.h"
  17. #endif
  18. #include <assets_icons.h>
  19. #define FONT_TEST_STR_LENGTH (7)
  20. static const char* YES_NO_LIST[] = {"NO", "YES"};
  21. static const char* TOKEN_GROUPING_LIST[] = {"NO", "2", "3"};
  22. static const uint8_t TOKEN_GROUPING_LIST_VALUES[] = {0, 2, 3};
  23. static const uint8_t TOKEN_GROUPING_LIST_VALUES_INDEXES[] = {0, 0, 1, 2};
  24. static const char* AUTOMATION_LIST[] = {
  25. "None",
  26. "USB"
  27. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  28. ,
  29. "Bluetooth",
  30. "BT and USB"
  31. #endif
  32. };
  33. static const char* FONT_TEST_STR = "0123BCD";
  34. typedef enum {
  35. HoursInput,
  36. MinutesInput,
  37. FontSelect,
  38. SoundSwitch,
  39. VibroSwitch,
  40. AutomationSwitch,
  41. BadKeyboardLayoutSelect,
  42. AutomationDelaySelect,
  43. BadBtProfileSelect,
  44. SplitTokenIntoGroupsSelect,
  45. ConfirmButton
  46. } Control;
  47. typedef struct {
  48. int8_t tz_offset_hours;
  49. uint8_t tz_offset_minutes;
  50. bool notification_sound;
  51. bool notification_vibro;
  52. AutomationMethod automation_method;
  53. uint16_t y_offset;
  54. AutomationKeyboardLayout automation_kb_layout;
  55. uint8_t automation_kb_layout_count;
  56. char automation_kb_layout_name[TOTP_KB_LAYOUT_NAME_MAX_LENGTH + 1];
  57. Control selected_control;
  58. uint8_t active_font_index;
  59. FontInfo* active_font;
  60. uint8_t total_fonts_count;
  61. uint16_t automation_initial_delay;
  62. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  63. uint8_t badbt_profile_index;
  64. #endif
  65. char automation_initial_delay_formatted[10];
  66. uint8_t split_token_into_groups;
  67. } SceneState;
  68. static void two_digit_to_str(int8_t num, char* str) {
  69. char* s = str;
  70. if(num < 0) {
  71. *(s++) = '-';
  72. num = -num;
  73. }
  74. uint8_t d1 = (num / 10) % 10;
  75. uint8_t d2 = num % 10;
  76. *(s++) = CONVERT_DIGIT_TO_CHAR(d1);
  77. *(s++) = CONVERT_DIGIT_TO_CHAR(d2);
  78. *(s++) = '\0';
  79. }
  80. static void update_formatted_automation_initial_delay(SceneState* scene_state) {
  81. snprintf(
  82. &scene_state->automation_initial_delay_formatted[0],
  83. sizeof(scene_state->automation_initial_delay_formatted),
  84. "%.1f sec.",
  85. (double)(scene_state->automation_initial_delay / 1000.0f));
  86. }
  87. static void update_formatted_automation_kb_layout_name(SceneState* scene_state) {
  88. totp_kb_layout_provider_get_layout_name(
  89. scene_state->automation_kb_layout,
  90. &scene_state->automation_kb_layout_name[0],
  91. sizeof(scene_state->automation_kb_layout_name));
  92. }
  93. void totp_scene_app_settings_activate(PluginState* plugin_state) {
  94. SceneState* scene_state = malloc(sizeof(SceneState));
  95. furi_check(scene_state != NULL);
  96. plugin_state->current_scene_state = scene_state;
  97. float off_int;
  98. float off_dec = modff(plugin_state->timezone_offset, &off_int);
  99. scene_state->tz_offset_hours = off_int;
  100. scene_state->tz_offset_minutes = 60.0f * off_dec;
  101. scene_state->notification_sound = plugin_state->notification_method & NotificationMethodSound;
  102. scene_state->notification_vibro = plugin_state->notification_method & NotificationMethodVibro;
  103. scene_state->automation_method =
  104. MIN(plugin_state->automation_method, COUNT_OF(AUTOMATION_LIST) - 1);
  105. scene_state->automation_kb_layout_count = totp_kb_layout_provider_get_layouts_count();
  106. scene_state->automation_kb_layout =
  107. MIN(plugin_state->automation_kb_layout, scene_state->automation_kb_layout_count - 1);
  108. scene_state->automation_initial_delay = plugin_state->automation_initial_delay;
  109. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  110. scene_state->badbt_profile_index = plugin_state->bt_type_code_worker_profile_index;
  111. #endif
  112. scene_state->total_fonts_count = totp_font_provider_get_fonts_count();
  113. scene_state->active_font_index = plugin_state->active_font_index;
  114. scene_state->active_font = totp_font_info_alloc();
  115. if(!totp_font_provider_get_font(scene_state->active_font_index, scene_state->active_font)) {
  116. scene_state->active_font_index = 0;
  117. totp_font_provider_get_font(scene_state->active_font_index, scene_state->active_font);
  118. }
  119. update_formatted_automation_initial_delay(scene_state);
  120. update_formatted_automation_kb_layout_name(scene_state);
  121. scene_state->split_token_into_groups =
  122. TOKEN_GROUPING_LIST_VALUES_INDEXES[plugin_state->split_token_into_groups];
  123. }
  124. void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plugin_state) {
  125. const SceneState* scene_state = plugin_state->current_scene_state;
  126. if(scene_state->selected_control < FontSelect) {
  127. canvas_set_font(canvas, FontPrimary);
  128. canvas_draw_str_aligned(
  129. canvas, 0, 0 - scene_state->y_offset, AlignLeft, AlignTop, "Timezone offset");
  130. canvas_set_font(canvas, FontSecondary);
  131. char tmp_str[4];
  132. two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]);
  133. canvas_draw_str_aligned(
  134. canvas, 0, 17 - scene_state->y_offset, AlignLeft, AlignTop, "Hours:");
  135. ui_control_select_render(
  136. canvas,
  137. 36,
  138. 10 - scene_state->y_offset,
  139. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  140. &tmp_str[0],
  141. scene_state->selected_control == HoursInput);
  142. two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]);
  143. canvas_draw_str_aligned(
  144. canvas, 0, 35 - scene_state->y_offset, AlignLeft, AlignTop, "Minutes:");
  145. ui_control_select_render(
  146. canvas,
  147. 36,
  148. 28 - scene_state->y_offset,
  149. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  150. &tmp_str[0],
  151. scene_state->selected_control == MinutesInput);
  152. } else if(scene_state->selected_control < SoundSwitch) {
  153. canvas_set_font(canvas, FontPrimary);
  154. canvas_draw_str_aligned(
  155. canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Font");
  156. canvas_set_font(canvas, FontSecondary);
  157. const FontInfo* const font = scene_state->active_font;
  158. ui_control_select_render(
  159. canvas,
  160. 0,
  161. 74 - scene_state->y_offset,
  162. SCREEN_WIDTH - UI_CONTROL_VSCROLL_WIDTH,
  163. font->name,
  164. scene_state->selected_control == FontSelect);
  165. uint8_t font_x_offset =
  166. SCREEN_WIDTH_CENTER -
  167. (((font->char_info[0].width + font->space_width) * FONT_TEST_STR_LENGTH) >> 1);
  168. uint8_t font_y_offset = 108 - scene_state->y_offset - (font->height >> 1);
  169. canvas_draw_str_ex(
  170. canvas, font_x_offset, font_y_offset, FONT_TEST_STR, FONT_TEST_STR_LENGTH, font);
  171. } else if(scene_state->selected_control < AutomationSwitch) {
  172. canvas_set_font(canvas, FontPrimary);
  173. canvas_draw_str_aligned(
  174. canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications");
  175. canvas_set_font(canvas, FontSecondary);
  176. canvas_draw_str_aligned(
  177. canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:");
  178. ui_control_select_render(
  179. canvas,
  180. 36,
  181. 138 - scene_state->y_offset,
  182. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  183. YES_NO_LIST[scene_state->notification_sound],
  184. scene_state->selected_control == SoundSwitch);
  185. canvas_draw_str_aligned(
  186. canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:");
  187. ui_control_select_render(
  188. canvas,
  189. 36,
  190. 156 - scene_state->y_offset,
  191. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  192. YES_NO_LIST[scene_state->notification_vibro],
  193. scene_state->selected_control == VibroSwitch);
  194. } else if(scene_state->selected_control < SplitTokenIntoGroupsSelect) {
  195. canvas_set_font(canvas, FontPrimary);
  196. canvas_draw_str_aligned(
  197. canvas, 0, 192 - scene_state->y_offset, AlignLeft, AlignTop, "Automation");
  198. canvas_set_font(canvas, FontSecondary);
  199. int group_offset = 0;
  200. if(scene_state->selected_control <= BadKeyboardLayoutSelect) {
  201. canvas_draw_str_aligned(
  202. canvas,
  203. 0,
  204. 209 - scene_state->y_offset - group_offset,
  205. AlignLeft,
  206. AlignTop,
  207. "Method:");
  208. ui_control_select_render(
  209. canvas,
  210. 36,
  211. 202 - scene_state->y_offset - group_offset,
  212. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  213. AUTOMATION_LIST[scene_state->automation_method],
  214. scene_state->selected_control == AutomationSwitch);
  215. } else {
  216. group_offset += 18;
  217. }
  218. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  219. if(scene_state->selected_control <= AutomationDelaySelect ||
  220. (scene_state->automation_method & AutomationMethodBadBt) == 0) {
  221. #endif
  222. canvas_draw_str_aligned(
  223. canvas,
  224. 0,
  225. 227 - scene_state->y_offset - group_offset,
  226. AlignLeft,
  227. AlignTop,
  228. "Layout:");
  229. ui_control_select_render(
  230. canvas,
  231. 36,
  232. 220 - scene_state->y_offset - group_offset,
  233. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  234. scene_state->automation_kb_layout_name,
  235. scene_state->selected_control == BadKeyboardLayoutSelect);
  236. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  237. } else if((scene_state->automation_method & AutomationMethodBadBt) != 0) {
  238. group_offset += 18;
  239. }
  240. #endif
  241. canvas_draw_str_aligned(
  242. canvas, 0, 245 - scene_state->y_offset - group_offset, AlignLeft, AlignTop, "Delay:");
  243. ui_control_select_render(
  244. canvas,
  245. 36,
  246. 238 - scene_state->y_offset - group_offset,
  247. SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
  248. &scene_state->automation_initial_delay_formatted[0],
  249. scene_state->selected_control == AutomationDelaySelect);
  250. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  251. if((scene_state->automation_method & AutomationMethodBadBt) != 0) {
  252. canvas_draw_str_aligned(
  253. canvas,
  254. 0,
  255. 263 - scene_state->y_offset - group_offset,
  256. AlignLeft,
  257. AlignTop,
  258. "BT Profile:");
  259. char profile_index_formatted[4];
  260. snprintf(profile_index_formatted, 4, "%d", scene_state->badbt_profile_index);
  261. ui_control_select_render(
  262. canvas,
  263. 42,
  264. 256 - scene_state->y_offset - group_offset,
  265. SCREEN_WIDTH - 42 - UI_CONTROL_VSCROLL_WIDTH,
  266. &profile_index_formatted[0],
  267. scene_state->selected_control == BadBtProfileSelect);
  268. }
  269. #endif
  270. } else {
  271. canvas_set_font(canvas, FontPrimary);
  272. canvas_draw_str_aligned(canvas, 0, 256 - scene_state->y_offset, AlignLeft, AlignTop, "UI");
  273. canvas_set_font(canvas, FontSecondary);
  274. canvas_draw_str_aligned(
  275. canvas, 0, 273 - scene_state->y_offset, AlignLeft, AlignTop, "Digit grouping:");
  276. ui_control_select_render(
  277. canvas,
  278. 64,
  279. 266 - scene_state->y_offset,
  280. SCREEN_WIDTH - 64 - UI_CONTROL_VSCROLL_WIDTH,
  281. TOKEN_GROUPING_LIST[scene_state->split_token_into_groups],
  282. scene_state->selected_control == SplitTokenIntoGroupsSelect);
  283. ui_control_button_render(
  284. canvas,
  285. SCREEN_WIDTH_CENTER - 24,
  286. 306 - scene_state->y_offset,
  287. 48,
  288. 13,
  289. "Confirm",
  290. scene_state->selected_control == ConfirmButton);
  291. }
  292. ui_control_vscroll_render(
  293. canvas, SCREEN_WIDTH - 3, 0, SCREEN_HEIGHT, scene_state->selected_control, ConfirmButton);
  294. }
  295. bool totp_scene_app_settings_handle_event(
  296. const PluginEvent* const event,
  297. PluginState* plugin_state) {
  298. if(event->type != EventTypeKey) {
  299. return true;
  300. }
  301. SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
  302. if(event->input.type == InputTypePress || event->input.type == InputTypeRepeat) {
  303. switch(event->input.key) {
  304. case InputKeyUp:
  305. totp_roll_value_uint8_t(
  306. &scene_state->selected_control,
  307. -1,
  308. HoursInput,
  309. ConfirmButton,
  310. RollOverflowBehaviorStop);
  311. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  312. if((scene_state->automation_method & AutomationMethodBadBt) == 0 &&
  313. scene_state->selected_control == BadBtProfileSelect) {
  314. scene_state->selected_control--;
  315. }
  316. #endif
  317. if(scene_state->selected_control >
  318. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  319. BadBtProfileSelect
  320. #else
  321. AutomationDelaySelect
  322. #endif
  323. ) {
  324. scene_state->y_offset = SCREEN_HEIGHT * 4;
  325. } else if(scene_state->selected_control > VibroSwitch) {
  326. scene_state->y_offset = SCREEN_HEIGHT * 3;
  327. } else if(scene_state->selected_control > FontSelect) {
  328. scene_state->y_offset = SCREEN_HEIGHT * 2;
  329. } else if(scene_state->selected_control > MinutesInput) {
  330. scene_state->y_offset = SCREEN_HEIGHT;
  331. } else {
  332. scene_state->y_offset = 0;
  333. }
  334. break;
  335. case InputKeyDown:
  336. totp_roll_value_uint8_t(
  337. &scene_state->selected_control,
  338. 1,
  339. HoursInput,
  340. ConfirmButton,
  341. RollOverflowBehaviorStop);
  342. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  343. if((scene_state->automation_method & AutomationMethodBadBt) == 0 &&
  344. scene_state->selected_control == BadBtProfileSelect) {
  345. scene_state->selected_control++;
  346. }
  347. #endif
  348. if(scene_state->selected_control >
  349. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  350. BadBtProfileSelect
  351. #else
  352. AutomationDelaySelect
  353. #endif
  354. ) {
  355. scene_state->y_offset = SCREEN_HEIGHT * 4;
  356. } else if(scene_state->selected_control > VibroSwitch) {
  357. scene_state->y_offset = SCREEN_HEIGHT * 3;
  358. } else if(scene_state->selected_control > FontSelect) {
  359. scene_state->y_offset = SCREEN_HEIGHT * 2;
  360. } else if(scene_state->selected_control > MinutesInput) {
  361. scene_state->y_offset = SCREEN_HEIGHT;
  362. } else {
  363. scene_state->y_offset = 0;
  364. }
  365. break;
  366. case InputKeyRight:
  367. if(scene_state->selected_control == HoursInput) {
  368. totp_roll_value_int8_t(
  369. &scene_state->tz_offset_hours, 1, -12, 14, RollOverflowBehaviorStop);
  370. } else if(scene_state->selected_control == MinutesInput) {
  371. totp_roll_value_uint8_t(
  372. &scene_state->tz_offset_minutes, 15, 0, 45, RollOverflowBehaviorRoll);
  373. } else if(scene_state->selected_control == FontSelect) {
  374. totp_roll_value_uint8_t(
  375. &scene_state->active_font_index,
  376. 1,
  377. 0,
  378. scene_state->total_fonts_count - 1,
  379. RollOverflowBehaviorRoll);
  380. totp_font_provider_get_font(
  381. scene_state->active_font_index, scene_state->active_font);
  382. } else if(scene_state->selected_control == SoundSwitch) {
  383. scene_state->notification_sound = !scene_state->notification_sound;
  384. } else if(scene_state->selected_control == VibroSwitch) {
  385. scene_state->notification_vibro = !scene_state->notification_vibro;
  386. } else if(scene_state->selected_control == AutomationSwitch) {
  387. totp_roll_value_uint8_t(
  388. &scene_state->automation_method,
  389. 1,
  390. 0,
  391. COUNT_OF(AUTOMATION_LIST) - 1,
  392. RollOverflowBehaviorRoll);
  393. } else if(scene_state->selected_control == BadKeyboardLayoutSelect) {
  394. totp_roll_value_uint8_t(
  395. &scene_state->automation_kb_layout,
  396. 1,
  397. 0,
  398. scene_state->automation_kb_layout_count - 1,
  399. RollOverflowBehaviorRoll);
  400. update_formatted_automation_kb_layout_name(scene_state);
  401. } else if(scene_state->selected_control == AutomationDelaySelect) {
  402. totp_roll_value_uint16_t(
  403. &scene_state->automation_initial_delay,
  404. 500,
  405. 0,
  406. 60000,
  407. RollOverflowBehaviorStop);
  408. update_formatted_automation_initial_delay(scene_state);
  409. }
  410. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  411. else if(scene_state->selected_control == BadBtProfileSelect) {
  412. totp_roll_value_uint8_t(
  413. &scene_state->badbt_profile_index, 1, 0, UINT8_MAX, RollOverflowBehaviorRoll);
  414. }
  415. #endif
  416. else if(scene_state->selected_control == SplitTokenIntoGroupsSelect) {
  417. totp_roll_value_uint8_t(
  418. &scene_state->split_token_into_groups,
  419. 1,
  420. 0,
  421. COUNT_OF(TOKEN_GROUPING_LIST) - 1,
  422. RollOverflowBehaviorRoll);
  423. }
  424. break;
  425. case InputKeyLeft:
  426. if(scene_state->selected_control == HoursInput) {
  427. totp_roll_value_int8_t(
  428. &scene_state->tz_offset_hours, -1, -12, 14, RollOverflowBehaviorStop);
  429. } else if(scene_state->selected_control == MinutesInput) {
  430. totp_roll_value_uint8_t(
  431. &scene_state->tz_offset_minutes, -15, 0, 45, RollOverflowBehaviorRoll);
  432. } else if(scene_state->selected_control == FontSelect) {
  433. totp_roll_value_uint8_t(
  434. &scene_state->active_font_index,
  435. -1,
  436. 0,
  437. scene_state->total_fonts_count - 1,
  438. RollOverflowBehaviorRoll);
  439. totp_font_provider_get_font(
  440. scene_state->active_font_index, scene_state->active_font);
  441. } else if(scene_state->selected_control == SoundSwitch) {
  442. scene_state->notification_sound = !scene_state->notification_sound;
  443. } else if(scene_state->selected_control == VibroSwitch) {
  444. scene_state->notification_vibro = !scene_state->notification_vibro;
  445. } else if(scene_state->selected_control == AutomationSwitch) {
  446. totp_roll_value_uint8_t(
  447. &scene_state->automation_method,
  448. -1,
  449. 0,
  450. COUNT_OF(AUTOMATION_LIST) - 1,
  451. RollOverflowBehaviorRoll);
  452. } else if(scene_state->selected_control == BadKeyboardLayoutSelect) {
  453. totp_roll_value_uint8_t(
  454. &scene_state->automation_kb_layout,
  455. -1,
  456. 0,
  457. scene_state->automation_kb_layout_count - 1,
  458. RollOverflowBehaviorRoll);
  459. update_formatted_automation_kb_layout_name(scene_state);
  460. } else if(scene_state->selected_control == AutomationDelaySelect) {
  461. totp_roll_value_uint16_t(
  462. &scene_state->automation_initial_delay,
  463. -500,
  464. 0,
  465. 60000,
  466. RollOverflowBehaviorStop);
  467. update_formatted_automation_initial_delay(scene_state);
  468. }
  469. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  470. else if(scene_state->selected_control == BadBtProfileSelect) {
  471. totp_roll_value_uint8_t(
  472. &scene_state->badbt_profile_index, -1, 0, UINT8_MAX, RollOverflowBehaviorRoll);
  473. }
  474. #endif
  475. else if(scene_state->selected_control == SplitTokenIntoGroupsSelect) {
  476. totp_roll_value_uint8_t(
  477. &scene_state->split_token_into_groups,
  478. -1,
  479. 0,
  480. COUNT_OF(TOKEN_GROUPING_LIST) - 1,
  481. RollOverflowBehaviorRoll);
  482. }
  483. break;
  484. case InputKeyOk:
  485. if(scene_state->selected_control == ConfirmButton) {
  486. plugin_state->timezone_offset = (float)scene_state->tz_offset_hours +
  487. (float)scene_state->tz_offset_minutes / 60.0f;
  488. plugin_state->notification_method =
  489. (scene_state->notification_sound ? NotificationMethodSound :
  490. NotificationMethodNone) |
  491. (scene_state->notification_vibro ? NotificationMethodVibro :
  492. NotificationMethodNone);
  493. plugin_state->automation_method = scene_state->automation_method;
  494. plugin_state->active_font_index = scene_state->active_font_index;
  495. plugin_state->automation_kb_layout = scene_state->automation_kb_layout;
  496. plugin_state->automation_initial_delay = scene_state->automation_initial_delay;
  497. plugin_state->split_token_into_groups =
  498. TOKEN_GROUPING_LIST_VALUES[scene_state->split_token_into_groups];
  499. #ifdef TOTP_BADBT_AUTOMATION_ENABLED
  500. if(((scene_state->automation_method & AutomationMethodBadBt) == 0 ||
  501. plugin_state->bt_type_code_worker_profile_index !=
  502. scene_state->badbt_profile_index) &&
  503. plugin_state->bt_type_code_worker_context != NULL) {
  504. totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context);
  505. plugin_state->bt_type_code_worker_context = NULL;
  506. }
  507. plugin_state->bt_type_code_worker_profile_index = scene_state->badbt_profile_index;
  508. #endif
  509. if(!totp_config_file_update_user_settings(plugin_state)) {
  510. totp_dialogs_config_updating_error(plugin_state);
  511. return false;
  512. }
  513. totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
  514. }
  515. break;
  516. case InputKeyBack: {
  517. totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
  518. break;
  519. }
  520. default:
  521. break;
  522. }
  523. }
  524. return true;
  525. }
  526. void totp_scene_app_settings_deactivate(PluginState* plugin_state) {
  527. if(plugin_state->current_scene_state == NULL) return;
  528. SceneState* scene_state = plugin_state->current_scene_state;
  529. totp_font_info_free(scene_state->active_font);
  530. free(scene_state);
  531. plugin_state->current_scene_state = NULL;
  532. }