totp_app_settings.c 23 KB

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