Implement SD card autodetection, automount, and GUI/dmenu mounter
- Enable GPIO 38 active-low card detect (cd-gpios) with bias-pull-up on sdhci@7864000 across all MSM8905/MSM8909 device trees and DTBs - Add sxmo_sdcard.sh and 88-bananarchy-sdcard.rules udev rules for automatic mounting at /media/sdcard on insertion and cleanup on removal - Integrate SD card mount, unmount/eject, and navigation into the GUI File Manager (files.so) and built-in dmenu SD Card menu (@menu:sdcard)
This commit is contained in:
1 parent
370f8b085c
commit
32d5d2f2b4
26 files changed
+530
-24
No files matched your search
@@ -750,10 +750,22 @@ int runFilesApp(int argc, char** argv) {
|
||||
statusBannerUntilMs = nowMs() + 2200;
|
||||
};
|
||||
|
||||
auto isSdCardMounted = []() -> bool {
|
||||
std::ifstream f("/proc/mounts");
|
||||
std::string line;
|
||||
while (std::getline(f, line)) {
|
||||
if (line.find(" /media/sdcard ") != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
auto buildActionsList = [&]() {
|
||||
actionsList.clear();
|
||||
bool hasSel = !filteredItems.empty();
|
||||
bool isParent = hasSel && filteredItems[selected].isParent;
|
||||
bool sdMounted = isSdCardMounted();
|
||||
|
||||
if (hasSel) {
|
||||
if (!filteredItems[selected].isDir) {
|
||||
@@ -807,6 +819,14 @@ 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)"});
|
||||
}
|
||||
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"});
|
||||
actionSelected = 0;
|
||||
};
|
||||
@@ -1667,6 +1687,34 @@ int runFilesApp(int argc, char** argv) {
|
||||
filteredItems[selected].name);
|
||||
} else if (actId == 17 && !filteredItems.empty()) {
|
||||
openTextViewer(filteredItems[selected]);
|
||||
} else if (actId == 18) {
|
||||
loadDirectory("/media/sdcard");
|
||||
mode = ViewMode::Browser;
|
||||
} else if (actId == 19) {
|
||||
if (currentDir.rfind("/media/sdcard", 0) == 0) {
|
||||
loadDirectory(homeDir);
|
||||
}
|
||||
int rc = std::system("sxmo_sdcard.sh unmount >/dev/null 2>&1");
|
||||
loadDirectory(currentDir);
|
||||
statusBanner = (rc == 0 && !isSdCardMounted())
|
||||
? "SD card unmounted"
|
||||
: "Unmount failed (busy)";
|
||||
statusBannerUntilMs = nowMs() + 2200;
|
||||
mode = ViewMode::Browser;
|
||||
} else if (actId == 20) {
|
||||
mode = ViewMode::Browser;
|
||||
statusBanner = "Scanning SD card slot...";
|
||||
statusBannerUntilMs = nowMs() + 2500;
|
||||
drawUI();
|
||||
int rc = std::system("sxmo_sdcard.sh mount >/dev/null 2>&1");
|
||||
if (rc == 0 && isSdCardMounted()) {
|
||||
loadDirectory("/media/sdcard");
|
||||
statusBanner = "SD card mounted";
|
||||
} else {
|
||||
loadDirectory(currentDir);
|
||||
statusBanner = "No SD card detected";
|
||||
}
|
||||
statusBannerUntilMs = nowMs() + 2200;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -966,6 +966,24 @@ write_str_file(const char *path, const char *val)
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sdcard_is_mounted_fast(void)
|
||||
{
|
||||
FILE *fp = fopen("/proc/mounts", "r");
|
||||
if (!fp)
|
||||
return 0;
|
||||
char line[512];
|
||||
int mounted = 0;
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
if (strstr(line, " /media/sdcard ") != NULL) {
|
||||
mounted = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return mounted;
|
||||
}
|
||||
|
||||
static int
|
||||
dunst_window_visible(void)
|
||||
{
|
||||
@@ -2365,6 +2383,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
snprintf(label, sizeof(label), "%s Files", ICON_DIR);
|
||||
add_menu_item(label, "@plugin:files", 0);
|
||||
|
||||
snprintf(label, sizeof(label), "%s SD Card %s", ICON_DIR, sdcard_is_mounted_fast() ? ICON_TON : ICON_TOF);
|
||||
add_menu_item(label, "@menu:sdcard", 1);
|
||||
|
||||
snprintf(label, sizeof(label), "%s Dialer", ICON_PHN);
|
||||
add_menu_item(label, "@plugin:dialer", 0);
|
||||
|
||||
@@ -2610,6 +2631,26 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
snprintf(label, sizeof(label), "%s Back to Config", ICON_CFG);
|
||||
add_menu_item(label, "@menu:config", 1);
|
||||
populate_timezone_menu();
|
||||
} else if (strcmp(menu_name, "sdcard") == 0) {
|
||||
reset_session_defaults(1, "SD Card");
|
||||
append_active_call_entries();
|
||||
int mounted = sdcard_is_mounted_fast();
|
||||
snprintf(label, sizeof(label), "%s Status: %s %s", ICON_DIR,
|
||||
mounted ? "Mounted (/media/sdcard)" : "Unmounted",
|
||||
mounted ? ICON_TON : ICON_TOF);
|
||||
add_menu_item(label, mounted ? "sxmo_sdcard.sh unmount >/dev/null 2>&1" : "sxmo_sdcard.sh mount >/dev/null 2>&1", 1);
|
||||
snprintf(label, sizeof(label), "%s Open SD Card in Files", ICON_DIR);
|
||||
add_menu_item(label, "@plugin:files:/media/sdcard", 0);
|
||||
snprintf(label, sizeof(label), "%s Mount SD Card", ICON_DIR);
|
||||
add_menu_item(label, "sxmo_sdcard.sh mount >/dev/null 2>&1", 1);
|
||||
snprintf(label, sizeof(label), "%s Unmount / Eject SD Card", ICON_OUT);
|
||||
add_menu_item(label, "sxmo_sdcard.sh unmount >/dev/null 2>&1", 1);
|
||||
snprintf(label, sizeof(label), "%s Rescan SD Card Slot", ICON_RLD);
|
||||
add_menu_item(label, "sxmo_sdcard.sh rescan >/dev/null 2>&1", 1);
|
||||
snprintf(label, sizeof(label), "%s System Menu", ICON_MNU);
|
||||
add_menu_item(label, "@menu:sys", 1);
|
||||
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
|
||||
add_menu_item(label, "@close", 0);
|
||||
} else if (strcmp(menu_name, "config") == 0) {
|
||||
reset_session_defaults(1, "Config");
|
||||
append_active_call_entries();
|
||||
@@ -2631,6 +2672,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
snprintf(label, sizeof(label), "%s Bluetooth %s", ICON_BTH, bt_is_unblocked_fast() ? ICON_TON : ICON_TOF);
|
||||
add_menu_item(label, "@toggle:bluetooth", 1);
|
||||
|
||||
snprintf(label, sizeof(label), "%s SD Card %s", ICON_DIR, sdcard_is_mounted_fast() ? ICON_TON : ICON_TOF);
|
||||
add_menu_item(label, "@menu:sdcard", 1);
|
||||
|
||||
snprintf(label, sizeof(label), "%s Change Timezone", ICON_CLK);
|
||||
add_menu_item(label, "@menu:timezone", 1);
|
||||
|
||||
|
||||
Reference in new issue
Block a user