Skip to content

Commit

Permalink
Fix multiple issues with filesystem explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcharger committed Apr 6, 2024
1 parent 585787f commit 6260467
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions InfiniLink/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChartDataPoint>
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 10 additions & 4 deletions InfiniLink/Core/Home/FileSystemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6260467

Please sign in to comment.