Skip to content

KsuWebUI-SN 1.2-50

Choose a tag to compare

@dnascorpionofficial dnascorpionofficial released this 14 Nov 23:29
· 24 commits to main since this release
31d61e4

Tip

Highlights: this release adds a built-in WebUI file editor. A new Editor tab in the module console lets you browse a module's webroot folder, open text files with syntax colors, search, undo/redo and save them as root, all without leaving the app. Messages no longer pile up when shown quickly, and the APK is smaller. The new texts are translated in all five languages.

✨ New

  • WebUI editor: open the module console and use the new Editor tab (placed before Network) with the Open Editor button. It opens a file browser for that module's WebUI files (/data/adb/modules/<id>/webroot). Folders come first, files show their size, and the back button goes up one folder at a time.
  • Edit and save as root: tap a file to edit it. Files are saved with root access, so you can fix a module's WebUI directly on the device. The Save button is only active when something changed, and leaving with unsaved changes asks whether to Save, Discard or Cancel.
  • Syntax colors: HTML, XML, SVG, CSS, JavaScript (js, mjs, cjs, ts) and JSON files are colored, with separate colors for light and dark mode. Other file types open as plain text.
  • Undo and redo: step back and forward through your edits. Typing and deleting in a row are grouped together, and undoing back to the saved text marks the file as unchanged again.
  • Find in file: the search bar finds text without caring about upper or lower case, highlights every match, shows the match count and jumps to the previous or next one. If text is selected when you open it, it is used as the search word.
  • Safe file handling: only plain UTF-8 text files up to 1 MB can be edited. Larger or binary files show a clear message instead of opening. Files with Windows line endings (CRLF) are saved with the same line endings.
  • Editor messages: new texts for an empty folder, a file that can't be opened, too large or not text, saved, and save failed.

🔁 Changed

  • One message at a time: a new app message now replaces the one still on screen instead of waiting in line behind it. This applies to Copied, Refreshed, live reload, download and error messages.
  • Smaller APK: only the app's own languages (English, Arabic, French, Polish, Japanese and Simplified Chinese) are packed into the app. Extra languages from libraries are left out.
  • Translations: the new Editor texts are translated in Arabic, French, Polish, Japanese and Simplified Chinese with DeepL.

⚙️ Under the hood

For developers ⚠️ (Click to expand)

WebUI editor (new)

  • assets/eruda/editor.js (new): injected with erudaJs("editor") after network in the console setup. It registers an Editor tool in Eruda with a hint text and an Open Editor button, then moves its tab before network and calls updateSlider(). The button sends prompt('__ksu_editor__', ''). All of it is wrapped in try/catch and skipped if it was already added. Cost: it is only loaded together with the console (Eruda), so modules with the console off are not affected.
  • WebViewHelper.kt: new PROMPT_EDITOR. The handler starts FileBrowserActivity with EXTRA_ID (module id) and EXTRA_NAME (module name, or the id if empty), then confirms the prompt. ksuText has new openEditor and editorHint entries.
  • FileBrowserActivity.kt (new): lists /data/adb/modules/<id>/webroot through the root FileSystemManager from FileSystemService. It rejects an empty id or one containing / or ... Entries are sorted folders first, then by lowercase name, and the list is loaded on App.executor. A back callback goes up one folder and never leaves webroot. The list reloads in onResume so changes made in the editor show up. Files open in EditorActivity.
  • EditorActivity.kt (new): loads and saves through the root FileSystemManager (newOutputStream(false) to save).
    • Path check: the path must start with /data/adb/modules/, contain /webroot/ and contain no /../ or trailing /.., otherwise the activity finishes.
    • Loading: files over 1_000_000 bytes are refused (TooLarge). A 0 byte in the first 8192 bytes, or bytes that don't survive a UTF-8 round trip, are refused as NotText. CRLF is turned into \n while editing and turned back on save.
    • History: Edit(start, removed, added) records from a TextWatcher. Typing and deleting in a row merge up to 200 characters, newlines break a merge. At most 300 edits and 3,000,000 characters are kept. isClean() compares the last edit and a signature with the saved marker, so undoing back to the saved text clears the dirty state.
    • Search: case-insensitive indexOf, at most 3000 matches, 150 ms debounce, shown as MatchSpan and CurrentMatchSpan background spans. The count reads n/3000+ when the limit is hit.
    • Highlighting: tokens are built on Dispatchers.Default after a 350 ms debounce (900 ms above 300,000 characters) and dropped if the text changed meanwhile. Only a window of the visible lines plus 20,000 characters on each side gets SyntaxSpans, and it is moved when scrolling gets within a quarter of the margin of its edge (80 ms debounce).
    • UI: edge-to-edge with the bottom padding following the keyboard, adjustResize, and configChanges for orientation|screenSize|keyboardHidden|uiMode (the colors are redone on a dark mode switch). Back runs the search close, then the unsaved dialog (dialog_unsaved.xml).
  • SyntaxHighlighter.kt (new): regex based tokenizer with Language (PLAIN, HTML, CSS, JS, JSON) chosen from the file extension (html, htm, xml, svg → HTML; css; js, mjs, cjs, ts; json). Token kinds: comment, string, keyword, number, tag, attribute, property. HTML handles embedded script and style content by tokenizing it again with the matching language.
  • AndroidManifest.xml: registers FileBrowserActivity and EditorActivity, both exported="false".
  • Resources: new layouts activity_file_browser, activity_editor, item_file and dialog_unsaved, new menu editor_menu (save, undo, redo, search) and new icons ic_arrow_back, ic_arrow_down, ic_arrow_up, ic_close, ic_file, ic_folder, ic_redo, ic_save and ic_undo.

Messages

  • App.kt: new showToast(context, text|@StringRes, duration). It keeps the last Toast, cancels it before showing the new one, uses the application context, and posts to the main thread when called from another thread.
  • WebUIActivity.kt, WebViewHelper.kt, WebViewInterface.kt: every Toast.makeText(...).show() (root request, live reload, copied, refreshed, WebView crash, download start and failure, interface messages) now calls showToast.

Build

  • app/build.gradle.kts: appLocales is read from the values-* folders in src/main/res (pattern values-xx, values-xxx, with an optional region). localeFilters += listOf("en") + appLocales keeps only those languages in the APK, so a new language added with scripts/add_language.py is included automatically.
  • proguard-rules.pro: -assumenosideeffects for the four kotlin.jvm.internal.Intrinsics null-check functions (checkNotNullParameter, checkNotNullExpressionValue, checkParameterIsNotNull, checkExpressionValueIsNotNull), which removes those checks from release builds.

Strings

  • Strings: 20 new strings in English, Arabic, French, Polish, Japanese and Simplified Chinese: eruda_open_editor, eruda_editor_hint, folder_empty, file_open_failed, file_too_large, file_not_text, file_saved, file_save_failed, unsaved_title, unsaved_message, action_save, action_discard, action_cancel, navigate_back, action_undo, action_redo, action_search, search_hint, search_previous and search_next. There are no TODO translate markers.