From b761c660913793378be774149ab48a1d91ac3d63 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 5 Aug 2023 15:24:06 +0530 Subject: [PATCH 1/7] feat: adds experimental ability to autorun boot.dd --- src/code.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/code.py b/src/code.py index b7598c0..660cddc 100644 --- a/src/code.py +++ b/src/code.py @@ -44,9 +44,15 @@ def api(request: Request): server.serve_forever(str(wifi.radio.ipv4_address_ap)) +async def run_boot_script(): + boot_script = 'payloads/boot.dd' + if os.path.exists(boot_script): + run_script_file(boot_script) + + if __name__ == "__main__": try: - asyncio.run(main()) + asyncio.gather(main(), run_boot_script()) # For some reason, wifi.stop_ap is not implemented. except NotImplementedError: microcontroller.reset() From 4626de8d3430707894a7cfb5195eee26442f1ba4 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 12 Aug 2023 09:21:46 +0530 Subject: [PATCH 2/7] ui: make file list more accessible for small screens, adds checkmark for setting file name --- src/static/index.html | 11 +++++++++-- src/static/main.css | 35 ++++++++++++++++++++++++++++------- src/static/script.js | 8 +++++++- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/static/index.html b/src/static/index.html index 6d4d00b..9de3f6d 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -11,7 +11,7 @@
-
+
- +
+ + +
diff --git a/src/static/main.css b/src/static/main.css index 40a87bd..7b6e9c5 100644 --- a/src/static/main.css +++ b/src/static/main.css @@ -13,8 +13,9 @@ body { } .container { - height: calc(70vh); + height: 70vh; display: flex; + overflow: hidden; flex-direction: row; } @@ -44,8 +45,9 @@ body { background: #111; display: flex; flex-direction: column; - width: 25vw; + width: 0; overflow: scroll; + flex-shrink: 0; } .entry { @@ -90,23 +92,36 @@ body { .editorarea { display: flex; flex-direction: column; - width: 100%; + flex: 1; } -.editorarea > .title { - padding: 0.5rem 1rem; +.editorarea > .title-bar { color: #888; background: #222; outline: none; - border: none; border-bottom: #444 solid 0.1rem; + display: flex; + flex-direction: row; +} + +.editorarea > .title-bar > .title { + outline: none; + border: none; + background: #222; + flex-grow: 1; + padding: 0.5rem 1rem; +} + +.editorarea > .title-bar > .title-btn { + border: none; + background: #222; + padding: 0 0.4rem 0 0.4rem; } .editor { background: #222; border: none; resize: none; - min-width: max-content; height: calc(70vh - 3rem); padding: 0.5rem; } @@ -136,3 +151,9 @@ body { .editor:focus { outline: none; } + +@media screen and (orientation: portrait) { + .show { + width: calc(100vw - 3rem); + } +} \ No newline at end of file diff --git a/src/static/script.js b/src/static/script.js index 504b135..aa44169 100644 --- a/src/static/script.js +++ b/src/static/script.js @@ -11,7 +11,8 @@ const logs = document.querySelector('.logs') const documents_icon = document.querySelector('.documents') const run_icon = document.querySelector('.run') const add_icon = document.querySelector('.add') -const title = document.querySelector('.editorarea > .title') +const title = document.querySelector('.editorarea > .title-bar > .title') +const title_button = document.querySelector('.editorarea > .title-bar > .title-btn') let timer function doApi(message) { @@ -74,6 +75,11 @@ title.addEventListener('keypress', (e) => { } }) +title_button.addEventListener('click', () => { + title.readOnly = true + doApi({"action": "create", "filename": title.value}) +}); + add_icon.addEventListener('click', () => { editor.value = '' title.value = '' From 30fc09bfca1cdc98b83901ee962365c998bb399a Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 12 Aug 2023 09:23:27 +0530 Subject: [PATCH 3/7] doc: document run_boot_script --- src/code.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/code.py b/src/code.py index 660cddc..17f7b0c 100644 --- a/src/code.py +++ b/src/code.py @@ -45,6 +45,10 @@ def api(request: Request): async def run_boot_script(): + """ + If a script with the name 'boot.dd' exists, + run it without user interaction on boot. + """ boot_script = 'payloads/boot.dd' if os.path.exists(boot_script): run_script_file(boot_script) From 41eedec43864075553255744ff8acec36a9c0d21 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 12 Aug 2023 09:34:03 +0530 Subject: [PATCH 4/7] refactor: move common functionality into separate function --- src/static/script.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/static/script.js b/src/static/script.js index aa44169..b818b35 100644 --- a/src/static/script.js +++ b/src/static/script.js @@ -68,18 +68,18 @@ function reload_listing() { }) } +function create_file() { + title.readOnly = true + doApi({"action": "create", "filename": title.value}) +} + +title_button.addEventListener('click', create_file); title.addEventListener('keypress', (e) => { if (e.keyCode==13) { - title.readOnly = true - doApi({"action": "create", "filename": title.value}) + create_file() } }) -title_button.addEventListener('click', () => { - title.readOnly = true - doApi({"action": "create", "filename": title.value}) -}); - add_icon.addEventListener('click', () => { editor.value = '' title.value = '' @@ -88,14 +88,8 @@ add_icon.addEventListener('click', () => { }) documents_icon.addEventListener('click', () => { - const classList = files.classList - if (classList.contains("show")) { - files.classList.replace('show', 'hide') - } else if (classList.contains("hide")) { - files.classList.replace('hide', 'show') - } else { - files.classList.add('hide') - } + files.classList.toggle("show"); + files.classList.toggle("hide"); }); run_icon.addEventListener('click', () => { From 1fadfd0bb229afcd2e26133614343352a6b378a2 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 12 Aug 2023 09:41:35 +0530 Subject: [PATCH 5/7] fix: import run_script_file from ducky module --- src/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/code.py b/src/code.py index 17f7b0c..1abdf05 100644 --- a/src/code.py +++ b/src/code.py @@ -9,6 +9,7 @@ import socketpool import wifi from adafruit_httpserver import POST, FileResponse, Request, Server +from ducky import run_script_file from api import handle From 43b911d3e276995bd77ad5d6e78b9bcec4a906ed Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 12 Aug 2023 11:04:12 +0530 Subject: [PATCH 6/7] fix: asynchronously run boot script alongside setting up the server --- src/code.py | 20 ++++++++------------ src/ducky.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/code.py b/src/code.py index 1abdf05..b67ec09 100644 --- a/src/code.py +++ b/src/code.py @@ -9,12 +9,11 @@ import socketpool import wifi from adafruit_httpserver import POST, FileResponse, Request, Server -from ducky import run_script_file +from ducky import run_boot_script from api import handle - -async def main(): +async def setup_server(): """ Begin a wifi access point defined by the SSID and PASSWORD environment variables. @@ -45,19 +44,16 @@ def api(request: Request): server.serve_forever(str(wifi.radio.ipv4_address_ap)) -async def run_boot_script(): - """ - If a script with the name 'boot.dd' exists, - run it without user interaction on boot. - """ - boot_script = 'payloads/boot.dd' - if os.path.exists(boot_script): - run_script_file(boot_script) +async def main(): + await asyncio.gather( + run_boot_script(), + setup_server() + ) if __name__ == "__main__": try: - asyncio.gather(main(), run_boot_script()) + asyncio.run(main()) # For some reason, wifi.stop_ap is not implemented. except NotImplementedError: microcontroller.reset() diff --git a/src/ducky.py b/src/ducky.py index 9babdac..65c31b2 100644 --- a/src/ducky.py +++ b/src/ducky.py @@ -118,3 +118,15 @@ def run_script_file(path: str): run_script(handle.read()) except OSError as error: warn(f"unable to open file {path}: {error}") + + +async def run_boot_script(): + """ + If a script with the name 'boot.dd' exists, + run it without user interaction on boot. + """ + try: + with open("payloads/boot.dd", "r", encoding="utf-8") as handle: + run_script(handle.read()) + except OSError: + info("boot script does not exist, skipping its execution") From 1da6232bf90329995309e7632bbb4f22e4539ce2 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 12 Aug 2023 11:07:29 +0530 Subject: [PATCH 7/7] doc: document the new entrypoint --- src/code.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/code.py b/src/code.py index b67ec09..fe7962b 100644 --- a/src/code.py +++ b/src/code.py @@ -45,6 +45,10 @@ def api(request: Request): async def main(): + """ + Asynchronously run the boot script while setting + the server up for the web interface. + """ await asyncio.gather( run_boot_script(), setup_server()