17
17
ugfx .string (170 ,75 ,"Anyway" ,"Roboto_BlackItalic24" ,ugfx .BLACK )
18
18
ugfx .string (155 ,105 ,"MOTD: NVS" ,"Roboto_Regular18" ,ugfx .BLACK )
19
19
20
- options = ugfx .List (0 ,0 ,int (ugfx .width ()/ 2 ),ugfx .height ())
20
+ options = None
21
+ install_path = None
21
22
22
- try :
23
- apps = os .listdir ('lib' )
24
- except OSError :
25
- apps = []
23
+ def populate_it ():
24
+ global options
25
+ options = ugfx .List (0 ,0 ,int (ugfx .width ()/ 2 ),ugfx .height ())
26
26
27
- options .add_item ('installer' )
28
- options .add_item ('ota_update' )
27
+ try :
28
+ apps = os .listdir ('lib' )
29
+ except OSError :
30
+ apps = []
29
31
30
- for app in apps :
31
- options .add_item (app )
32
+ options .add_item ('installer' )
33
+ options .add_item ('ota_update' )
34
+
35
+ for app in apps :
36
+ options .add_item (app )
32
37
33
38
def run_it (pushed ):
34
39
if (pushed ):
@@ -43,8 +48,51 @@ def run_it(pushed):
43
48
esp .rtcmem_write_string (selected )
44
49
esp .start_sleeping (1 )
45
50
51
+ def expandhome (s ):
52
+ if "~/" in s :
53
+ h = os .getenv ("HOME" )
54
+ s = s .replace ("~/" , h + "/" )
55
+ return s
56
+
57
+ def get_install_path ():
58
+ global install_path
59
+ if install_path is None :
60
+ # sys.path[0] is current module's path
61
+ install_path = sys .path [1 ]
62
+ install_path = expandhome (install_path )
63
+ return install_path
64
+
65
+
66
+ def uninstall_it (pushed ):
67
+ if (pushed ):
68
+ selected = options .selected_text ()
69
+ if selected == 'installer' :
70
+ return
71
+ if selected == 'ota_update' :
72
+ return
73
+ options .destroy ()
74
+ import dialogs
75
+ print (selected )
76
+ uninstall = dialogs .prompt_boolean ('Are you sure you want to remove %s?' % selected )
77
+ print (uninstall )
78
+ if uninstall :
79
+ ugfx .clear (ugfx .BLACK )
80
+ ugfx .string (40 ,25 ,"Uninstalling:" ,"Roboto_BlackItalic24" ,ugfx .WHITE )
81
+ ugfx .string (100 ,75 , selected ,"PermanentMarker22" ,ugfx .WHITE )
82
+ ugfx .flush ()
83
+ install_path = get_install_path ()
84
+ for rm_file in os .listdir ("%s/%s" % (install_path , selected )):
85
+ os .remove ("%s/%s/%s" % (install_path , selected , rm_file ))
86
+ os .rmdir ("%s/%s" % (install_path , selected ))
87
+ badge .eink_busy_wait ()
88
+ esp .rtcmem_write_string ('launcher' )
89
+ esp .start_sleeping (1 )
90
+
91
+
92
+ populate_it ()
93
+
46
94
ugfx .input_attach (ugfx .BTN_A , run_it )
47
- ugfx .input_attach (ugfx .BTN_B , run_it )
95
+ ugfx .input_attach (ugfx .BTN_B , uninstall_it )
48
96
49
97
ugfx .input_attach (ugfx .JOY_UP , lambda pushed : ugfx .flush () if pushed else 0 )
50
98
ugfx .input_attach (ugfx .JOY_DOWN , lambda pushed : ugfx .flush () if pushed else 0 )
0 commit comments