Skip to content

Commit 57e890e

Browse files
committed
Cleanup and 'uninstall' attempt
1 parent 859389d commit 57e890e

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

esp32/modules/dialogs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
### Description: Some basic UGFX powered dialogs
44
### License: MIT
55

6-
import ugfx, badge, utime as time
6+
import ugfx, utime as time
77

88
wait_for_interrupt = True
99
button_pushed = ''

esp32/modules/inisetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def setup():
4646
print("wake from sleep")
4747
load_me = esp.rtcmem_read_string()
4848
if load_me != "":
49-
print("starting %s", load_me)
49+
print("starting %s" % load_me)
5050
esp.rtcmem_write_string("")
5151
__import__(load_me)
5252
else:

esp32/modules/launcher.py

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@
1717
ugfx.string(170,75,"Anyway","Roboto_BlackItalic24",ugfx.BLACK)
1818
ugfx.string(155,105,"MOTD: NVS","Roboto_Regular18",ugfx.BLACK)
1919

20-
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
20+
options = None
21+
install_path = None
2122

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())
2626

27-
options.add_item('installer')
28-
options.add_item('ota_update')
27+
try:
28+
apps = os.listdir('lib')
29+
except OSError:
30+
apps = []
2931

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)
3237

3338
def run_it(pushed):
3439
if (pushed):
@@ -43,8 +48,51 @@ def run_it(pushed):
4348
esp.rtcmem_write_string(selected)
4449
esp.start_sleeping(1)
4550

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+
4694
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)
4896

4997
ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0)
5098
ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy