From 6260467f305c4b0e837b58f9fbc2b1a38bbc8853 Mon Sep 17 00:00:00 2001 From: liamcharger Date: Sat, 6 Apr 2024 11:45:48 -0400 Subject: [PATCH] Fix multiple issues with filesystem explorer --- InfiniLink/ContentView.swift | 9 +++++++-- InfiniLink/Core/Home/FileSystemView.swift | 14 ++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/InfiniLink/ContentView.swift b/InfiniLink/ContentView.swift index c0e5d83..54de5e7 100644 --- a/InfiniLink/ContentView.swift +++ b/InfiniLink/ContentView.swift @@ -29,6 +29,7 @@ struct ContentView: View { @AppStorage("showDisconnectAlert") var showDisconnectConfDialog: Bool = false @AppStorage("showClearHRMChartConf") var showClearHRMChartConf: Bool = false @AppStorage("showClearBatteryChartConf") var showClearBatteryChartConf: Bool = false + @AppStorage("lockNavigation") var lockNavigation = false @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \ChartDataPoint.timestamp, ascending: true)]) private var chartPoints: FetchedResults @@ -97,13 +98,17 @@ struct ContentView: View { HStack(spacing: 0) { TabBarItem(selection: $selection, tab: .home, imageName: "house") .onTapGesture { - switchToTab(tab: .home) + if !lockNavigation { + switchToTab(tab: .home) + } } .frame(maxWidth: .infinity) TabBarItem(selection: $selection, tab: .settings, imageName: "gear") .onTapGesture { - switchToTab(tab: .settings) + if !lockNavigation { + switchToTab(tab: .settings) + } } .frame(maxWidth: .infinity) } diff --git a/InfiniLink/Core/Home/FileSystemView.swift b/InfiniLink/Core/Home/FileSystemView.swift index 8300c20..4e7a8bc 100644 --- a/InfiniLink/Core/Home/FileSystemView.swift +++ b/InfiniLink/Core/Home/FileSystemView.swift @@ -164,11 +164,11 @@ struct FileSystemView: View { do { let fileURLs = try result.get() + self.files.removeAll() for fileURL in fileURLs { guard fileURL.startAccessingSecurityScopedResource() else { continue } self.fileSelected = true - self.files.removeAll() self.files.append(File(url: fileURL, filename: fileURL.lastPathComponent)) // Don't stop accessing the security-scoped resource because then the upload button won't work due to lack of necessary permissions @@ -255,8 +255,12 @@ struct FileSystemView: View { if fileConverting { Text("Converting...") } else { - Text("Uploading...\(Int(Double(bleFSHandler.progress) / Double(fileSize) * 100))%") - + if fileSize != 0 { + let progressPercentage = Int(Double(bleFSHandler.progress) / Double(fileSize) * 100) + Text("Uploading...\(progressPercentage)%") + } else { + Text("Uploading...") + } } } .foregroundColor(.gray) @@ -318,10 +322,12 @@ struct FileSystemView: View { if let convertedImage = convertedImage { self.fileSize = convertedImage.count self.fileUploading = true - var _ = bleFSHandler.writeFile(data: convertedImage, path: directory + "/" + fileNameWithoutExtension + ".bin", offset: 0) + var _ = bleFSHandler.writeFile(data: convertedImage, path: directory + "/" + String(fileNameWithoutExtension.prefix(30).trimmingCharacters(in: .whitespacesAndNewlines).replacingOccurrences(of: "\\s+", with: "_", options: .regularExpression)) + ".bin", offset: 0) } } else { + self.fileSize = 0 let fileData = try Data(contentsOf: fileDataPath) + self.fileSize = fileData.count self.fileUploading = true var _ = bleFSHandler.writeFile(data: fileData, path: directory + "/" + file.filename, offset: 0)