MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / viewFile

Method viewFile

Tactility/Source/app/files/View.cpp:196–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194// endregion
195
196void View::viewFile(const std::string& path, const std::string& filename) {
197 std::string file_path = path + "/" + filename;
198
199 // For PC we need to make the path relative to the current work directory,
200 // because that's how LVGL maps its 'drive letter' to the file system.
201 std::string processed_filepath;
202 if (kernel::getPlatform() == kernel::PlatformSimulator) {
203 char cwd[PATH_MAX];
204 if (getcwd(cwd, sizeof(cwd)) == nullptr) {
205 LOGGER.error("Failed to get current working directory");
206 return;
207 }
208 if (!file_path.starts_with(cwd)) {
209 LOGGER.error("Can only work with files in working directory {}", cwd);
210 return;
211 }
212 processed_filepath = file_path.substr(strlen(cwd));
213 } else {
214 processed_filepath = file_path;
215 }
216
217 LOGGER.info("Clicked {}", file_path);
218
219 if (isSupportedAppFile(filename)) {
220#ifdef ESP_PLATFORM
221 // install(filename);
222 auto message = std::format("Do you want to install {}?", filename);
223 installAppPath = processed_filepath;
224 auto choices = std::vector {"Yes", "No"};
225 installAppLaunchId = alertdialog::start("Install?", message, choices);
226#endif
227 } else if (isSupportedImageFile(filename)) {
228 imageviewer::start(processed_filepath);
229 } else if (isSupportedTextFile(filename)) {
230 if (kernel::getPlatform() == kernel::PlatformEsp) {
231 notes::start(processed_filepath);
232 } else {
233 // Remove forward slash, because we need a relative path
234 notes::start(processed_filepath.substr(1));
235 }
236 } else {
237 LOGGER.warn("Opening files of this type is not supported");
238 }
239
240 onNavigate();
241}
242
243bool View::resolveDirentFromListIndex(int32_t list_index, dirent& out_entry) {
244 const bool is_root = (state->getCurrentPath() == "/");

Callers

nothing calls this directly

Calls 8

getPlatformFunction · 0.85
isSupportedAppFileFunction · 0.85
isSupportedImageFileFunction · 0.85
isSupportedTextFileFunction · 0.85
errorMethod · 0.80
infoMethod · 0.80
warnMethod · 0.80
startFunction · 0.70

Tested by

no test coverage detected