forked from RogueMaster/flipperzero-firmware-wPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfw_app_scene_interface_desktop.c
417 lines (336 loc) · 15.3 KB
/
cfw_app_scene_interface_desktop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#include "../cfw_app.h"
#include "cfw_app_scene.h"
#define CFW_DESKTOP_SELECT_ICON_STYLE 0
#define CFW_DESKTOP_SELECT_BATTERY_DISPLAY 1
#define CFW_DESKTOP_SELECT_BT_ICON 3
#define CFW_DESKTOP_SELECT_CLOCK_DISPLAY 4
#define CFW_DESKTOP_SELECT_DUMBMODE_ICON 5
#define CFW_DESKTOP_SELECT_LOCK_ICON 6
#define CFW_DESKTOP_SELECT_RPC_ICON 7
#define CFW_DESKTOP_SELECT_SDCARD_ICON 8
#define CFW_DESKTOP_SELECT_STEALTH_ICON 9
#define CFW_DESKTOP_SELECT_TOP_BAR 10
#define FILE_NAME_LEN_MAX 256
#define BATTERY_VIEW_COUNT 7
const char* const battery_view_count_text[BATTERY_VIEW_COUNT] =
{"Bar", "%", "Inv. %", "Retro 3", "Retro 5", "Bar %", "None"};
const uint32_t displayBatteryPercentage_value[BATTERY_VIEW_COUNT] = {
DISPLAY_BATTERY_BAR,
DISPLAY_BATTERY_PERCENT,
DISPLAY_BATTERY_INVERTED_PERCENT,
DISPLAY_BATTERY_RETRO_3,
DISPLAY_BATTERY_RETRO_5,
DISPLAY_BATTERY_BAR_PERCENT,
DISPLAY_BATTERY_NONE};
uint8_t origBattDisp_value = 0;
//This can move to the model later if needed, but ^^ Battery gets away with it and I dont see the problem with a "global" in a FAP (except for convention)
uint8_t ManifestFileCount;
CharList_t ManifestFileNames;
CharList_t ManifestMenuNames;
#define CFW_DESKTOP_ICON_STYLE_COUNT 2
const char* const icon_style_count_text[CFW_DESKTOP_ICON_STYLE_COUNT] = {"Stock", "Slim"};
const uint32_t icon_style_value[CFW_DESKTOP_ICON_STYLE_COUNT] = {ICON_STYLE_STOCK, ICON_STYLE_SLIM};
uint8_t origIconStyle_value = 0;
#define CFW_DESKTOP_ON_OFF_COUNT 2
const char* const cfw_desktop_on_off_text[CFW_DESKTOP_ON_OFF_COUNT] = {
"OFF",
"ON",
};
const uint32_t clock_enable_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t lockicon_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t bticon_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t rpc_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t sdcard_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t stealth_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t topbar_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
const uint32_t dumbmode_icon_value[CFW_DESKTOP_ON_OFF_COUNT] = {false, true};
static void cfw_app_scene_interface_desktop_var_item_list_callback(void* context, uint32_t index) {
CfwApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
static void cfw_app_scene_interface_desktop_anim_style_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, *CharList_get(ManifestMenuNames, index));
CFW_SETTINGS()->manifest_name = *CharList_get(ManifestFileNames, index);
app->save_settings = true;
}
static void cfw_app_scene_interface_desktop_clock_enable_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.display_clock = index;
}
static void cfw_app_scene_interface_desktop_battery_view_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, battery_view_count_text[index]);
app->desktop.displayBatteryPercentage = index;
}
static void cfw_app_scene_interface_desktop_icon_style_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, icon_style_count_text[index]);
app->desktop.icon_style = icon_style_value[index];
}
static void cfw_app_scene_interface_desktop_lockicon_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.lock_icon = lockicon_value[index];
}
static void cfw_app_scene_interface_desktop_bticon_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.bt_icon = bticon_value[index];
}
static void cfw_app_scene_interface_desktop_rpc_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.rpc_icon = rpc_value[index];
}
static void cfw_app_scene_interface_desktop_sdcard_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.sdcard = sdcard_value[index];
}
static void cfw_app_scene_interface_desktop_stealth_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.stealth_icon = stealth_value[index];
}
static void cfw_app_scene_interface_desktop_topbar_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.top_bar = topbar_value[index];
}
static void cfw_app_scene_interface_desktop_dumbmode_icon_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[index]);
app->desktop.dumbmode_icon = dumbmode_icon_value[index];
}
void cfw_app_scene_interface_desktop_on_enter(void* context) {
CfwApp* app = context;
CfwSettings* cfw_settings = CFW_SETTINGS();
VariableItemList* var_item_list = app->var_item_list;
VariableItem* item;
uint8_t value_index;
origIconStyle_value = app->desktop.icon_style;
origBattDisp_value = app->desktop.displayBatteryPercentage;
//Initialization.
ManifestFileCount = 0;
CharList_init(ManifestFileNames);
CharList_init(ManifestMenuNames);
//Open up Storage.
Storage* storage = furi_record_open(RECORD_STORAGE);
File* folder = storage_file_alloc(storage);
FileInfo info;
char* name = malloc(FILE_NAME_LEN_MAX);
uint8_t current_manifest = 0;
//Lets walk the dolphin folder and get the filenamess.
if(storage_dir_open(folder, EXT_PATH("dolphin"))) {
while(storage_dir_read(folder, &info, name, FILE_NAME_LEN_MAX)) {
if(!(info.flags & FSF_DIRECTORY)) {
//Get a FuriString for all the string operations.
char* filenametmp = strdup(name);
//Are we on a manifest>
if(strncasecmp(filenametmp, "manifest", 8) == 0) {
if(strlen(filenametmp) == 12) {
//Add to the list of names.
CharList_push_back(ManifestFileNames, filenametmp);
CharList_push_back(ManifestMenuNames, "Default");
ManifestFileCount++;
} else {
//Allocate memory for the menuname
char* menuname = malloc(strlen(filenametmp) - 12);
snprintf(menuname, strlen(filenametmp) - 12, "%s", filenametmp + 9);
//Sanity Check.
if(strcmp(menuname, "") != 0) {
//Add to the list of names.
CharList_push_at(ManifestFileNames, ManifestFileCount, filenametmp);
CharList_push_at(ManifestMenuNames, ManifestFileCount, menuname);
//Select in menu if its our manifest.
if(strcmp(filenametmp, cfw_settings->manifest_name) == 0)
current_manifest = ManifestFileCount;
//Count the added Files.
ManifestFileCount++;
}
}
}
}
}
}
//Close up and free.
free(name);
storage_file_free(folder);
//Add items to list.
item = variable_item_list_add(
var_item_list,
"Animations",
ManifestFileCount,
cfw_app_scene_interface_desktop_anim_style_changed,
app);
variable_item_set_current_value_index(item, current_manifest);
variable_item_set_current_value_text(item, *CharList_get(ManifestMenuNames, current_manifest));
item = variable_item_list_add(
var_item_list,
"Icon Style",
CFW_DESKTOP_ICON_STYLE_COUNT,
cfw_app_scene_interface_desktop_icon_style_changed,
app);
value_index = value_index_uint32(
app->desktop.icon_style, icon_style_value, CFW_DESKTOP_ICON_STYLE_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, icon_style_count_text[value_index]);
item = variable_item_list_add(
var_item_list,
"Battery View",
BATTERY_VIEW_COUNT,
cfw_app_scene_interface_desktop_battery_view_changed,
app);
value_index = value_index_uint32(
app->desktop.displayBatteryPercentage, displayBatteryPercentage_value, BATTERY_VIEW_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, battery_view_count_text[value_index]);
item = variable_item_list_add(
var_item_list,
"BT Icon",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_bticon_changed,
app);
value_index = value_index_uint32(app->desktop.bt_icon, bticon_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"Clock",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_clock_enable_changed, //
app);
value_index = value_index_uint32(
app->desktop.display_clock, clock_enable_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"Games Only Icon",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_dumbmode_icon_changed,
app);
value_index = value_index_uint32(
app->desktop.dumbmode_icon, dumbmode_icon_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"Lock Icon",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_lockicon_changed,
app);
value_index =
value_index_uint32(app->desktop.lock_icon, lockicon_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"RPC Icon",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_rpc_changed,
app);
value_index = value_index_uint32(app->desktop.rpc_icon, rpc_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"SD Card Icon",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_sdcard_changed,
app);
value_index = value_index_uint32(app->desktop.sdcard, sdcard_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"Stealth Icon",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_stealth_changed,
app);
value_index =
value_index_uint32(app->desktop.stealth_icon, stealth_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
item = variable_item_list_add(
var_item_list,
"Top Bar",
CFW_DESKTOP_ON_OFF_COUNT,
cfw_app_scene_interface_desktop_topbar_changed,
app);
value_index = value_index_uint32(app->desktop.top_bar, topbar_value, CFW_DESKTOP_ON_OFF_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, cfw_desktop_on_off_text[value_index]);
variable_item_list_set_enter_callback(
var_item_list, cfw_app_scene_interface_desktop_var_item_list_callback, app);
variable_item_list_set_selected_item(
var_item_list,
scene_manager_get_scene_state(app->scene_manager, CfwAppSceneInterfaceDesktop));
view_dispatcher_switch_to_view(app->view_dispatcher, CfwAppViewVarItemList);
}
bool cfw_app_scene_interface_desktop_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case CFW_DESKTOP_SELECT_ICON_STYLE:
consumed = true;
break;
case CFW_DESKTOP_SELECT_BATTERY_DISPLAY:
consumed = true;
break;
case CFW_DESKTOP_SELECT_LOCK_ICON:
consumed = true;
break;
case CFW_DESKTOP_SELECT_BT_ICON:
consumed = true;
break;
case CFW_DESKTOP_SELECT_RPC_ICON:
consumed = true;
break;
case CFW_DESKTOP_SELECT_SDCARD_ICON:
consumed = true;
break;
case CFW_DESKTOP_SELECT_STEALTH_ICON:
consumed = true;
break;
case CFW_DESKTOP_SELECT_TOP_BAR:
consumed = true;
break;
case CFW_DESKTOP_SELECT_DUMBMODE_ICON:
consumed = true;
break;
case CFW_DESKTOP_SELECT_CLOCK_DISPLAY:
consumed = true;
break;
default:
break;
}
}
return consumed;
}
void cfw_app_scene_interface_desktop_on_exit(void* context) {
CfwApp* app = context;
variable_item_list_reset(app->var_item_list);
DESKTOP_SETTINGS_SAVE(&app->desktop);
if((app->desktop.icon_style != origIconStyle_value) ||
(app->desktop.displayBatteryPercentage != origBattDisp_value)) {
// Trigger UI update in case we changed battery layout
Power* power = furi_record_open(RECORD_POWER);
power_update_viewport(power);
furi_record_close(RECORD_POWER);
}
}