Add NeoUI passcode configurator, duress mode profile, and Bluetooth OBEX UI
This commit is contained in:
1 parent
51a1a91d42
commit
62ac46e498
100 files changed
+2736
-240
No files matched your search
@@ -32,8 +32,64 @@ enum class ViewMode {
|
||||
ConfirmDelete = 6,
|
||||
TextEdit = 7,
|
||||
RingtoneView = 8,
|
||||
BtSendModal = 9,
|
||||
};
|
||||
|
||||
struct BtSendTarget {
|
||||
std::string mac;
|
||||
std::string name;
|
||||
bool paired = false;
|
||||
bool connected = false;
|
||||
};
|
||||
|
||||
std::vector<BtSendTarget> queryBtSendTargets(bool scanFirst = false) {
|
||||
std::string rfk = runCaptureCmd("/usr/sbin/rfkill list bluetooth 2>/dev/null");
|
||||
if (rfk.find("Soft blocked: yes") != std::string::npos ||
|
||||
rfk.find("Hard blocked: yes") != std::string::npos) {
|
||||
runCaptureCmd("SXMO_OS=alpine doas -n sxmo_bluetoothtoggle.sh on >/dev/null 2>&1");
|
||||
}
|
||||
if (scanFirst) {
|
||||
runCaptureCmd("bluetoothctl --timeout 4 scan on >/dev/null 2>&1");
|
||||
}
|
||||
std::unordered_set<std::string> pairedMacs;
|
||||
std::unordered_set<std::string> connectedMacs;
|
||||
auto parseSet = [](const std::string& raw, std::unordered_set<std::string>& dst) {
|
||||
std::istringstream ss(raw);
|
||||
std::string line;
|
||||
while (std::getline(ss, line)) {
|
||||
if (line.rfind("Device ", 0) == 0 && line.size() >= 24) {
|
||||
dst.insert(line.substr(7, 17));
|
||||
}
|
||||
}
|
||||
};
|
||||
parseSet(runCaptureCmd("bluetoothctl devices Paired 2>/dev/null || "
|
||||
"bluetoothctl paired-devices 2>/dev/null"),
|
||||
pairedMacs);
|
||||
parseSet(runCaptureCmd("bluetoothctl devices Connected 2>/dev/null"),
|
||||
connectedMacs);
|
||||
|
||||
std::vector<BtSendTarget> out;
|
||||
std::string allRaw = runCaptureCmd("bluetoothctl devices 2>/dev/null");
|
||||
std::istringstream ss(allRaw);
|
||||
std::string line;
|
||||
while (std::getline(ss, line)) {
|
||||
if (line.rfind("Device ", 0) != 0 || line.size() < 24) continue;
|
||||
BtSendTarget d;
|
||||
d.mac = line.substr(7, 17);
|
||||
d.name = (line.size() > 25) ? trimStr(line.substr(25)) : d.mac;
|
||||
d.paired = (pairedMacs.count(d.mac) > 0);
|
||||
d.connected = (connectedMacs.count(d.mac) > 0);
|
||||
out.push_back(d);
|
||||
}
|
||||
std::sort(out.begin(), out.end(),
|
||||
[](const BtSendTarget& a, const BtSendTarget& b) {
|
||||
if (a.connected != b.connected) return a.connected > b.connected;
|
||||
if (a.paired != b.paired) return a.paired > b.paired;
|
||||
return a.name < b.name;
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
enum class SortMode {
|
||||
Name = 0,
|
||||
Date = 1,
|
||||
@@ -226,8 +282,7 @@ bool isLikelyTextFile(const std::string& path, off_t size) {
|
||||
}
|
||||
|
||||
std::string shortenPath(const std::string& path) {
|
||||
const char* home = std::getenv("HOME");
|
||||
std::string h = (home && home[0]) ? home : "/home/user";
|
||||
std::string h = getHomeDirPath();
|
||||
std::string out = path;
|
||||
if (out == h) {
|
||||
out = "~";
|
||||
@@ -356,10 +411,15 @@ int runFilesApp(int argc, char** argv) {
|
||||
auto& colOrange = pt.colOrange;
|
||||
auto& colRed = pt.colRed;
|
||||
|
||||
const char* homeEnv = std::getenv("HOME");
|
||||
std::string homeDir = (homeEnv && homeEnv[0]) ? homeEnv : "/home/user";
|
||||
std::string homeDir = getHomeDirPath();
|
||||
std::string currentDir = homeDir;
|
||||
|
||||
// Bluetooth send modal state
|
||||
std::vector<BtSendTarget> btTargets;
|
||||
int btTargetSel = 0;
|
||||
std::string btSendFilePath;
|
||||
std::string btSendFileName;
|
||||
|
||||
ViewMode mode = ViewMode::Browser;
|
||||
SortMode sortMode = SortMode::Name;
|
||||
bool showHidden = false;
|
||||
@@ -476,11 +536,19 @@ int runFilesApp(int argc, char** argv) {
|
||||
|
||||
auto loadDirectory = [&](const std::string& targetDir,
|
||||
const std::string& selectName = "") {
|
||||
homeDir = getHomeDirPath();
|
||||
char resolved[4096];
|
||||
std::string dir = targetDir;
|
||||
if (::realpath(targetDir.c_str(), resolved) != nullptr) {
|
||||
dir = resolved;
|
||||
}
|
||||
if (isDuressMode()) {
|
||||
std::string root = kDuressHomeDirPath;
|
||||
::mkdir(root.c_str(), 0700);
|
||||
if (dir != root && dir.rfind(root + "/", 0) != 0) {
|
||||
dir = root;
|
||||
}
|
||||
}
|
||||
DIR* d = ::opendir(dir.c_str());
|
||||
if (!d) {
|
||||
statusBanner = "Cannot open directory";
|
||||
@@ -490,7 +558,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
currentDir = dir;
|
||||
allItems.clear();
|
||||
|
||||
if (currentDir != "/") {
|
||||
std::string topLimit = isDuressMode() ? std::string(kDuressHomeDirPath) : "/";
|
||||
if (currentDir != "/" && currentDir != topLimit) {
|
||||
FileItem parent;
|
||||
parent.name = "..";
|
||||
size_t slash = currentDir.rfind('/');
|
||||
@@ -964,14 +1033,17 @@ int runFilesApp(int argc, char** argv) {
|
||||
actionsList.clear();
|
||||
bool hasSel = !filteredItems.empty();
|
||||
bool isParent = hasSel && filteredItems[selected].isParent;
|
||||
bool sdMounted = isSdCardMounted();
|
||||
bool duress = isDuressMode();
|
||||
bool sdMounted = !duress && isSdCardMounted();
|
||||
|
||||
if (hasSel) {
|
||||
if (!filteredItems[selected].isDir) {
|
||||
std::string ext = getExtLower(filteredItems[selected].name);
|
||||
if (isImageExt(ext)) {
|
||||
actionsList.push_back({1, kIconEye, "Preview Image"});
|
||||
actionsList.push_back({14, kIconImage, "Set as Wallpaper"});
|
||||
if (!duress) {
|
||||
actionsList.push_back({14, kIconImage, "Set as Wallpaper"});
|
||||
}
|
||||
} else if (isRingtoneExt(ext)) {
|
||||
actionsList.push_back({1, kIconBell, "Preview Ringtone"});
|
||||
actionsList.push_back({15, kIconCheck, "Set as Ringtone"});
|
||||
@@ -992,12 +1064,13 @@ int runFilesApp(int argc, char** argv) {
|
||||
if (ext == "jad") {
|
||||
actionsList.push_back({17, kIconEye, "View JAD Descriptor"});
|
||||
}
|
||||
} else if (isYabasicExt(ext)) {
|
||||
} else if (isYabasicExt(ext) && !duress) {
|
||||
actionsList.push_back({1, kIconTerm, "Run in Yabasic (Terminal)"});
|
||||
actionsList.push_back({17, kIconEye, "View Text"});
|
||||
} else {
|
||||
actionsList.push_back({1, kIconEye, "Open / View"});
|
||||
}
|
||||
actionsList.push_back({25, kIconBluetooth, "Send via Bluetooth"});
|
||||
actionsList.push_back({16, kIconEdit, "Edit in Text Editor"});
|
||||
} else {
|
||||
actionsList.push_back({1, kIconFolderOpen, "Open Folder"});
|
||||
@@ -1011,7 +1084,7 @@ int runFilesApp(int argc, char** argv) {
|
||||
actionsList.push_back({3, kIconPlus, "New Folder"});
|
||||
actionsList.push_back({4, kIconFileText, "New Empty File"});
|
||||
if (hasSel && !isParent) {
|
||||
if (!filteredItems[selected].isDir) {
|
||||
if (!filteredItems[selected].isDir && !duress) {
|
||||
actionsList.push_back({2, kIconEdit, "Edit in nano"});
|
||||
}
|
||||
actionsList.push_back({5, kIconEdit, "Rename"});
|
||||
@@ -1028,15 +1101,17 @@ int runFilesApp(int argc, char** argv) {
|
||||
else if (sortMode == SortMode::Date) sortLbl += "Size (#)";
|
||||
else sortLbl += "Name (#)";
|
||||
actionsList.push_back({11, kIconSort, sortLbl});
|
||||
if (sdMounted) {
|
||||
if (currentDir != "/media/sdcard") {
|
||||
actionsList.push_back({18, kIconFolderOpen, "Open SD Card (/media/sdcard)"});
|
||||
if (!duress) {
|
||||
if (sdMounted) {
|
||||
if (currentDir != "/media/sdcard") {
|
||||
actionsList.push_back({18, kIconFolderOpen, "Open SD Card (/media/sdcard)"});
|
||||
}
|
||||
actionsList.push_back({19, kIconOutCall, "Unmount / Eject SD Card"});
|
||||
} else {
|
||||
actionsList.push_back({20, kIconFolder, "Mount SD Card (/media/sdcard)"});
|
||||
}
|
||||
actionsList.push_back({19, kIconOutCall, "Unmount / Eject SD Card"});
|
||||
} else {
|
||||
actionsList.push_back({20, kIconFolder, "Mount SD Card (/media/sdcard)"});
|
||||
actionsList.push_back({12, kIconTerm, "Open Terminal Here"});
|
||||
}
|
||||
actionsList.push_back({12, kIconTerm, "Open Terminal Here"});
|
||||
actionSelected = 0;
|
||||
};
|
||||
|
||||
@@ -1734,6 +1809,64 @@ int runFilesApp(int argc, char** argv) {
|
||||
drawPango(layoutSmall, &colMuted, 6, 240, 20,
|
||||
"*:Play #:Set Notif L/R:Step 1:Edit", kWinWidth - 12);
|
||||
drawSoftkeyBar("Set Ring", isPl ? "Stop" : "Play [*]", "Back");
|
||||
} else if (mode == ViewMode::BtSendModal) {
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 28);
|
||||
drawPango(layoutMain, &colYellow, 6, 0, 28,
|
||||
std::string(kIconBluetooth) + " Send via Bluetooth",
|
||||
kWinWidth - 12);
|
||||
XSetForeground(dpy, gc, pt.spec.border);
|
||||
XDrawLine(dpy, pix, gc, 0, 27, kWinWidth, 27);
|
||||
|
||||
XSetForeground(dpy, gc, pt.spec.bgAltOdd);
|
||||
XFillRectangle(dpy, pix, gc, 6, 32, kWinWidth - 12, 22);
|
||||
drawPango(layoutSmall, &colLight, 10, 32, 22,
|
||||
"File: " + btSendFileName, kWinWidth - 20);
|
||||
|
||||
if (btTargets.empty()) {
|
||||
drawPango(layoutMain, &colMuted, 12, 110, 24,
|
||||
"No Bluetooth devices found", kWinWidth - 24);
|
||||
drawPango(layoutSmall, &colMuted, 12, 136, 20,
|
||||
"Press * to scan for nearby devices", kWinWidth - 24);
|
||||
} else {
|
||||
btTargetSel = std::clamp(
|
||||
btTargetSel, 0, static_cast<int>(btTargets.size()) - 1);
|
||||
const int listY = 58;
|
||||
const int rowH = 30;
|
||||
const int maxVis = 6;
|
||||
int startIdx = std::max(0, btTargetSel - maxVis / 2);
|
||||
if (startIdx + maxVis > static_cast<int>(btTargets.size())) {
|
||||
startIdx = std::max(0, static_cast<int>(btTargets.size()) - maxVis);
|
||||
}
|
||||
for (int i = 0; i < maxVis; ++i) {
|
||||
int idx = startIdx + i;
|
||||
if (idx >= static_cast<int>(btTargets.size())) break;
|
||||
int ry = listY + i * rowH;
|
||||
bool isSel = (idx == btTargetSel);
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.selBg : pt.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, 6, ry, kWinWidth - 12, rowH - 2);
|
||||
if (isSel) {
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XFillRectangle(dpy, pix, gc, 6, ry, 3, rowH - 2);
|
||||
}
|
||||
std::string label =
|
||||
std::string(kIconBluetooth) + " " + btTargets[idx].name;
|
||||
drawPango(layoutMain, isSel ? &colWhite : &colLight, 12, ry, 18,
|
||||
label, kWinWidth - 74);
|
||||
std::string st = btTargets[idx].connected
|
||||
? "Connected"
|
||||
: (btTargets[idx].paired ? "Paired" : "Nearby");
|
||||
drawPango(layoutSmall,
|
||||
btTargets[idx].connected ? &colGreen : &colMuted,
|
||||
12, ry + 14, 14, btTargets[idx].mac + " [" + st + "]",
|
||||
kWinWidth - 24);
|
||||
}
|
||||
}
|
||||
|
||||
drawPango(layoutSmall, &colMuted, 8, 242, 18,
|
||||
"*:Scan Bluetooth OK:Send file", kWinWidth - 16);
|
||||
drawSoftkeyBar(btTargets.empty() ? "Scan [*]" : "Send",
|
||||
btTargets.empty() ? "Scan" : "Send", "Cancel");
|
||||
}
|
||||
|
||||
int64_t tNow = nowMs();
|
||||
@@ -2118,6 +2251,12 @@ int runFilesApp(int argc, char** argv) {
|
||||
statusBanner = "No SD card detected";
|
||||
}
|
||||
statusBannerUntilMs = nowMs() + 2200;
|
||||
} else if (actId == 25 && !filteredItems.empty()) {
|
||||
btSendFilePath = filteredItems[selected].fullPath;
|
||||
btSendFileName = filteredItems[selected].name;
|
||||
btTargets = queryBtSendTargets(false);
|
||||
btTargetSel = 0;
|
||||
mode = ViewMode::BtSendModal;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2262,6 +2401,32 @@ int runFilesApp(int argc, char** argv) {
|
||||
} else {
|
||||
mode = ViewMode::Browser;
|
||||
}
|
||||
} else if (mode == ViewMode::BtSendModal) {
|
||||
if (isLeft) {
|
||||
if (btTargets.empty()) {
|
||||
statusBanner = "Scanning Bluetooth...";
|
||||
statusBannerUntilMs = nowMs() + 2500;
|
||||
drawUI();
|
||||
btTargets = queryBtSendTargets(true);
|
||||
btTargetSel = 0;
|
||||
statusBanner.clear();
|
||||
statusBannerUntilMs = 0;
|
||||
} else {
|
||||
btTargetSel = std::clamp(
|
||||
btTargetSel, 0, static_cast<int>(btTargets.size()) - 1);
|
||||
std::string mac = btTargets[btTargetSel].mac;
|
||||
std::string devName = btTargets[btTargetSel].name;
|
||||
std::string cmd =
|
||||
"/usr/bin/bananarchy-bt-obex send " + shellQuote(mac) + " " +
|
||||
shellQuote(btSendFilePath) + " >/dev/null 2>&1 &";
|
||||
std::system(cmd.c_str());
|
||||
statusBanner = "Sending to " + devName + "...";
|
||||
statusBannerUntilMs = nowMs() + 2500;
|
||||
mode = ViewMode::Browser;
|
||||
}
|
||||
} else {
|
||||
mode = ViewMode::Browser;
|
||||
}
|
||||
}
|
||||
drawUI();
|
||||
};
|
||||
@@ -2277,6 +2442,9 @@ int runFilesApp(int argc, char** argv) {
|
||||
continue;
|
||||
} else if (cmd == "RELOAD_THEME") {
|
||||
pt.reload();
|
||||
if (isDuressMode() && currentDir.rfind(kDuressHomeDirPath, 0) != 0) {
|
||||
loadDirectory(kDuressHomeDirPath);
|
||||
}
|
||||
if (visible) drawUI();
|
||||
} else if (cmd == "CLOSE") {
|
||||
hideWindow();
|
||||
@@ -2345,7 +2513,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
|
||||
if (sym == XK_BackSpace || sym == XK_Delete) {
|
||||
if (mode == ViewMode::Browser && searchQuery.empty() &&
|
||||
currentDir != "/") {
|
||||
currentDir != "/" &&
|
||||
(!isDuressMode() || currentDir != kDuressHomeDirPath)) {
|
||||
std::string prevBase = currentDir;
|
||||
size_t sl = prevBase.rfind('/');
|
||||
std::string prevName =
|
||||
@@ -2375,7 +2544,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
drawUI();
|
||||
}
|
||||
} else if (sym == XK_Left || sym == XK_KP_Left) {
|
||||
if (currentDir != "/") {
|
||||
if (currentDir != "/" &&
|
||||
(!isDuressMode() || currentDir != kDuressHomeDirPath)) {
|
||||
std::string prevBase = currentDir;
|
||||
size_t sl = prevBase.rfind('/');
|
||||
std::string prevName =
|
||||
@@ -2602,6 +2772,33 @@ int runFilesApp(int argc, char** argv) {
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
handleSoftkeyAction(true);
|
||||
}
|
||||
} else if (mode == ViewMode::BtSendModal) {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (sym == XK_Up || sym == XK_KP_Up) {
|
||||
if (!btTargets.empty()) {
|
||||
btTargetSel =
|
||||
(btTargetSel - 1 + static_cast<int>(btTargets.size())) %
|
||||
static_cast<int>(btTargets.size());
|
||||
drawUI();
|
||||
}
|
||||
} else if (sym == XK_Down || sym == XK_KP_Down) {
|
||||
if (!btTargets.empty()) {
|
||||
btTargetSel =
|
||||
(btTargetSel + 1) % static_cast<int>(btTargets.size());
|
||||
drawUI();
|
||||
}
|
||||
} else if (d == '*') {
|
||||
statusBanner = "Scanning Bluetooth...";
|
||||
statusBannerUntilMs = nowMs() + 2500;
|
||||
drawUI();
|
||||
btTargets = queryBtSendTargets(true);
|
||||
btTargetSel = 0;
|
||||
statusBanner.clear();
|
||||
statusBannerUntilMs = 0;
|
||||
drawUI();
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
handleSoftkeyAction(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2671,6 +2868,9 @@ int runFilesApp(int argc, char** argv) {
|
||||
for (const auto& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "RELOAD_THEME") {
|
||||
pt.reload();
|
||||
if (isDuressMode() && currentDir.rfind(kDuressHomeDirPath, 0) != 0) {
|
||||
loadDirectory(kDuressHomeDirPath);
|
||||
}
|
||||
if (visible) drawUI();
|
||||
} else if (cmd == "CLOSE") {
|
||||
hideWindow();
|
||||
|
||||
Reference in new issue
Block a user