Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 66a36ef

Browse files
committed
Fixed iOS Printing UI And iOS Metadata Issues
1 parent 564265e commit 66a36ef

File tree

4 files changed

+38
-70
lines changed

4 files changed

+38
-70
lines changed

Source Code/Note.it/Note.it iOS/ContentView.swift

Lines changed: 29 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ struct ContentView: View {
3535
return bcf
3636
}()
3737

38-
@State var showingExport = false
39-
@State var showingPrinting = false
4038
@State var activeSheet: ActiveSheet?
4139
@AppStorage("selectedAppearance") var selectedAppearance = 3
4240

@@ -63,14 +61,12 @@ struct ContentView: View {
6361
var body: some View {
6462
CodeView(theme: themes.theme, code: $document.text, mode: themes.syntax.mode(), fontSize: editor.fontSize, showInvisibleCharacters: editor.showInvisibleCharacters, lineWrapping: editor.lineWrapping)
6563
.onLoadSuccess {
66-
getDirList()
6764
getAttributes()
6865
}
6966
.onLoadFail { error in
7067
print("Load Failed: \(error.localizedDescription)")
7168
}
7269
.onContentChange { change in
73-
getDirList()
7470
getAttributes()
7571
}
7672
.onAppear {
@@ -170,27 +166,20 @@ struct ContentView: View {
170166
}
171167
var metadata: some View {
172168
Form {
173-
Label("Title - \(fileNameAttribute)", systemImage: "textformat")
174-
Label("Extension - \(fileExtensionAttribute)", systemImage: "square.grid.3x1.folder.badge.plus")
175-
Label("Size - \(fileByteCountFormatter.string(fromByteCount: fileSizeAttribute))", systemImage: "externaldrive")
176-
Label("Path - \(filePathAttribute)", systemImage: "point.topleft.down.curvedto.point.bottomright.up")
177-
Label("Owner - \(fileOwnerAttribute)", systemImage: "person")
178-
Label("Created - \(fileCreatedAttribute.formatted(.dateTime))", systemImage: "calendar.badge.plus")
179-
Label("Modified - \(fileModifiedAttribute.formatted(.dateTime))", systemImage: "calendar.badge.clock")
180-
Label("File Type - \(fileTypeAttribute)", systemImage: "doc")
181-
}
182-
.navigationTitle("Metadata")
183-
.toolbar {
184-
ToolbarItem(placement: .navigationBarTrailing) {
185-
Button(action: {
186-
getDirList()
187-
getAttributes()
188-
}) {
189-
Label("Update Metadata", systemImage: "arrow.counterclockwise")
190-
}
191-
.help("Update Metadata")
169+
Section {
170+
Label("Title - \(fileNameAttribute)", systemImage: "textformat")
171+
Label("Extension - \(fileExtensionAttribute)", systemImage: "square.grid.3x1.folder.badge.plus")
172+
Label("Size - \(fileByteCountFormatter.string(fromByteCount: fileSizeAttribute))", systemImage: "externaldrive")
173+
Label("Path - \(filePathAttribute)", systemImage: "point.topleft.down.curvedto.point.bottomright.up")
174+
Label("Owner - \(fileOwnerAttribute)", systemImage: "person")
175+
Label("Created - \(fileCreatedAttribute.formatted(.dateTime))", systemImage: "calendar.badge.plus")
176+
Label("Modified - \(fileModifiedAttribute.formatted(.dateTime))", systemImage: "calendar.badge.clock")
177+
Label("File Type - \(fileTypeAttribute)", systemImage: "doc")
178+
} footer: {
179+
Text("Metadata Generated From Last Time The File Was Opened")
192180
}
193181
}
182+
.navigationTitle("Metadata")
194183
}
195184
var export: some View {
196185
Form {
@@ -422,33 +411,17 @@ struct ContentView: View {
422411
.navigationTitle("Export")
423412
.toolbar {
424413
ToolbarItem(placement: .navigationBarTrailing) {
425-
Button(action: {showingPrinting = true}) {
426-
Image(systemName: "printer")
427-
}
428-
.help("Print")
429-
.sheet(isPresented: $showingPrinting) {
430-
NavigationStack {
431-
SamplePrintSetup(page:
432-
VStack {
433-
HStack {
434-
Text(document.text)
435-
Spacer()
436-
}
414+
PrintSetup(page:
415+
VStack {
416+
HStack {
417+
Text(document.text)
437418
Spacer()
438419
}
439-
.padding()
440-
)
441-
.navigationTitle("Print")
442-
.navigationBarTitleDisplayMode(.inline)
443-
.toolbar {
444-
ToolbarItem(placement: .navigationBarTrailing) {
445-
Button(action: {showingPrinting = false}) {
446-
Text("Done")
447-
}
448-
}
420+
Spacer()
449421
}
450-
}
451-
}
422+
.padding()
423+
)
424+
.help("Print")
452425
}
453426
}
454427
}
@@ -471,28 +444,6 @@ struct ContentView: View {
471444
fileModifiedAttribute = modificationDate!
472445
fileCreatedAttribute = creationDate!
473446
}
474-
func getDirList() {
475-
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
476-
477-
guard let directoryURL = URL(string: paths.path) else { return }
478-
479-
do {
480-
let contents = try FileManager.default.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys:[.contentAccessDateKey], options: [.skipsHiddenFiles])
481-
.sorted(by: {
482-
let date0 = try $0.promisedItemResourceValues(forKeys:[.contentAccessDateKey]).contentAccessDate!
483-
let date1 = try $1.promisedItemResourceValues(forKeys:[.contentAccessDateKey]).contentAccessDate!
484-
return date0.compare(date1) == .orderedAscending
485-
})
486-
487-
for item in contents {
488-
guard let t = try? item.promisedItemResourceValues(forKeys:[.contentAccessDateKey]).contentAccessDate else { return }
489-
print("\(t) \(item.lastPathComponent)")
490-
fileURL = item
491-
}
492-
} catch {
493-
print(error)
494-
}
495-
}
496447
private func copyToClipBoard(textToCopy: String) {
497448
let paste = UIPasteboard.general
498449
paste.string = textToCopy
@@ -557,3 +508,12 @@ extension UIApplication {
557508
.first(where: \.isKeyWindow)
558509
}
559510
}
511+
512+
struct PrintSetup<Page>: View where Page: View {
513+
let page: Page
514+
var body: some View {
515+
Button(action: {presentPrintInteractionController(page: page)}) {
516+
Image(systemName: "printer")
517+
}
518+
}
519+
}

Source Code/Note.it/Note.it iOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<string>$(PRODUCT_BUNDLE_IDENTIFIER).example-document</string>
1818
</dict>
1919
</array>
20+
<key>UIFileSharingEnabled</key>
21+
<true/>
2022
<key>UTImportedTypeDeclarations</key>
2123
<array>
2224
<dict>

Source Code/Note.it/Note.it iOS/Note_it_iOSApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SwiftUI
1111
struct Note_it_iOSApp: App {
1212
var body: some Scene {
1313
DocumentGroup(newDocument: Note_it_iOSDocument()) { file in
14-
ContentView(document: file.$document, fileURL: URL(string: "/")!, fileTypeAttribute: "N/A", fileSizeAttribute: 0, fileTitleAtribute: "N/A", fileCreatedAttribute: Date(), fileModifiedAttribute: Date(), fileExtensionAttribute: "N/A", fileOwnerAttribute: "N/A", fileNameAttribute: "N/A", filePathAttribute: "N/A")
14+
ContentView(document: file.$document, fileURL: file.fileURL!, fileTypeAttribute: "N/A", fileSizeAttribute: 0, fileTitleAtribute: "N/A", fileCreatedAttribute: Date(), fileModifiedAttribute: Date(), fileExtensionAttribute: "N/A", fileOwnerAttribute: "N/A", fileNameAttribute: "N/A", filePathAttribute: "N/A")
1515
}
1616
}
1717
}

Source Code/Note.it/Note.it.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
CLANG_WARN_UNREACHABLE_CODE = YES;
335335
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
336336
COPY_PHASE_STRIP = NO;
337+
DEAD_CODE_STRIPPING = YES;
337338
DEBUG_INFORMATION_FORMAT = dwarf;
338339
ENABLE_STRICT_OBJC_MSGSEND = YES;
339340
ENABLE_TESTABILITY = YES;
@@ -395,6 +396,7 @@
395396
CLANG_WARN_UNREACHABLE_CODE = YES;
396397
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
397398
COPY_PHASE_STRIP = NO;
399+
DEAD_CODE_STRIPPING = YES;
398400
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
399401
ENABLE_NS_ASSERTIONS = NO;
400402
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -425,6 +427,7 @@
425427
CODE_SIGN_STYLE = Automatic;
426428
COMBINE_HIDPI_IMAGES = YES;
427429
CURRENT_PROJECT_VERSION = 5;
430+
DEAD_CODE_STRIPPING = YES;
428431
DEVELOPMENT_ASSET_PATHS = "\"Note.it/Preview Content\"";
429432
DEVELOPMENT_TEAM = ZWASU9HFBU;
430433
ENABLE_HARDENED_RUNTIME = YES;
@@ -454,6 +457,7 @@
454457
CODE_SIGN_STYLE = Automatic;
455458
COMBINE_HIDPI_IMAGES = YES;
456459
CURRENT_PROJECT_VERSION = 5;
460+
DEAD_CODE_STRIPPING = YES;
457461
DEVELOPMENT_ASSET_PATHS = "\"Note.it/Preview Content\"";
458462
DEVELOPMENT_TEAM = ZWASU9HFBU;
459463
ENABLE_HARDENED_RUNTIME = YES;
@@ -488,6 +492,7 @@
488492
INFOPLIST_FILE = "Note.it iOS/Info.plist";
489493
INFOPLIST_KEY_CFBundleDisplayName = Note.it;
490494
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
495+
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
491496
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
492497
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
493498
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -526,6 +531,7 @@
526531
INFOPLIST_FILE = "Note.it iOS/Info.plist";
527532
INFOPLIST_KEY_CFBundleDisplayName = Note.it;
528533
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
534+
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
529535
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
530536
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
531537
INFOPLIST_KEY_UILaunchScreen_Generation = YES;

0 commit comments

Comments
 (0)