Skip to content

Commit 3681254

Browse files
committed
1 parent 126311c commit 3681254

File tree

12 files changed

+316
-264
lines changed

12 files changed

+316
-264
lines changed

FSNotes iOS/AppDelegate.swift

+10-46
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2121

2222
public static var gitVC = [String: GitViewController]()
2323
public static var gitProgress: GitProgress?
24+
25+
// MARK: Static Properties
26+
static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"
2427

2528
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2629
var shouldPerformAdditionalDelegateHandling = true
@@ -108,16 +111,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
108111
func applicationWillEnterForeground(_ application: UIApplication) {
109112
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
110113
}
111-
112-
func applicationDidBecomeActive(_ application: UIApplication) {
113-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
114-
115-
guard let shortcut = launchedShortcutItem else { return }
116-
_ = handleShortCutItem(shortcut)
117-
118-
// Reset which shortcut was chosen for next time.
119-
launchedShortcutItem = nil
120-
}
121114

122115
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
123116
if let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").standardized,
@@ -134,43 +127,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
134127
}
135128

136129
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
137-
let handledShortCutItem = handleShortCutItem(shortcutItem)
138-
completionHandler(handledShortCutItem)
139-
}
140-
141-
// MARK: Static Properties
142-
static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"
143-
144-
func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
145-
var handled = false
146-
guard ShortcutIdentifier(fullType: shortcutItem.type) != nil else { return false }
147-
guard let shortCutType = shortcutItem.type as String? else { return false }
148-
149-
let vc = UIApplication.getVC()
150-
151-
switch shortCutType {
152-
case ShortcutIdentifier.makeNew.type:
153-
vc.createNote()
154-
155-
handled = true
156-
break
157-
case ShortcutIdentifier.clipboard.type:
158-
vc.createNote(pasteboard: true)
159-
160-
handled = true
161-
break
162-
case ShortcutIdentifier.search.type:
163-
vc.loadViewIfNeeded()
164-
vc.popViewController()
165-
vc.loadSearchController()
166-
handled = true
167-
break
168-
default:
169-
170-
break
130+
131+
if ShortcutIdentifier(fullType: shortcutItem.type) == .search {
132+
UIApplication.getVC().enableSearchFocus()
171133
}
172-
173-
return handled
134+
135+
UIApplication.getVC().handleShortCutItem(shortcutItem)
136+
completionHandler(true)
174137
}
175138

176139
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
@@ -191,6 +154,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
191154
note = storage.getBy(title: id)
192155
if !vc.isLoadedDB, note == nil {
193156
vc.restoreFindID = id
157+
return true
194158
}
195159
}
196160
}

FSNotes iOS/EditorViewController.swift

+13-8
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
196196

197197
public func fill(note: Note, selectedRange: NSRange? = nil, clearPreview: Bool = false, enableHandoff: Bool = true, completion: (() -> ())? = nil) {
198198

199-
UserDefaultsManagement.lastSelectedURL = note.url
200-
201199
if enableHandoff {
202200
registerHandoff(for: note)
203201
}
@@ -1446,8 +1444,10 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
14461444
}
14471445

14481446
@objc public func togglePreview() {
1449-
guard let note = editArea.note else { return }
1450-
1447+
guard let unwrappedNote = self.note, let note = Storage.shared().getBy(url: unwrappedNote.url) else { return }
1448+
1449+
note.loadPreviewState()
1450+
14511451
if note.previewState {
14521452
note.previewState = false
14531453
getPreviewView()?.removeFromSuperview()
@@ -1581,12 +1581,17 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
15811581
override func restoreUserActivityState(_ activity: NSUserActivity) {
15821582
if let id = activity.userInfo?["kCSSearchableItemActivityIdentifier"] as? String {
15831583
let url = URL(fileURLWithPath: id)
1584-
if let note = Storage.shared().getBy(url: url) {
1584+
1585+
var note = Storage.shared().getBy(url: url)
1586+
if nil === note {
1587+
note = Storage.shared().addNote(url: url)
1588+
}
1589+
1590+
if let note = note {
15851591
load(note: note)
1586-
return
1587-
} else {
1588-
UIApplication.getVC().restoreActivity = url
15891592
}
1593+
1594+
return
15901595
}
15911596

15921597
guard let name = activity.userInfo?["note-file-name"] as? String,

FSNotes iOS/Extensions/UIApplication+.swift

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ extension UIApplication {
2424
let appDelegate = UIApplication.shared.delegate as! AppDelegate
2525
return appDelegate.mainController
2626
}
27+
28+
static func getDelegate() -> AppDelegate {
29+
return UIApplication.shared.delegate as! AppDelegate
30+
}
2731
}

FSNotes iOS/View/NotesTableView.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class NotesTableView: UITableView,
8181
let note = self.notes[indexPath.row]
8282

8383
if !note.isLoaded && !note.isLoadedFromCache {
84-
note.load()
84+
note.uiLoad()
8585
}
8686

8787
cell.configure(note: note)
@@ -103,9 +103,10 @@ class NotesTableView: UITableView,
103103

104104
guard !self.isEditing, notes.indices.contains(indexPath.row) else { return }
105105

106-
let note = notes[indexPath.row]
106+
var note = notes[indexPath.row]
107+
note.loadPreviewState()
108+
107109
let evc = UIApplication.getEVC()
108-
109110
if let editArea = evc.editArea, let u = editArea.undoManager {
110111
u.removeAllActions()
111112
}

FSNotes iOS/View/SidebarTableView.swift

+4-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ class SidebarTableView: UITableView,
133133
vc.buildSearchQuery()
134134
vc.reloadNotesTable() {
135135
DispatchQueue.main.async {
136+
vc.notesTable.hideLoader()
136137
vc.setNavTitle(folder: name)
138+
vc.isLoadedSidebar = true
137139

138140
guard vc.notesTable.notes.count > 0 else {
139141
self.unloadAllTags()
@@ -147,13 +149,6 @@ class SidebarTableView: UITableView,
147149
self.loadAllTags()
148150
vc.resizeSidebar(withAnimation: true)
149151
}
150-
151-
if let url = UserDefaultsManagement.lastSelectedURL,
152-
let note = Storage.shared().getBy(url: url) {
153-
UserDefaultsManagement.lastSelectedURL = nil
154-
155-
UIApplication.getEVC().load(note: note)
156-
}
157152
}
158153
}
159154
}
@@ -730,6 +725,8 @@ class SidebarTableView: UITableView,
730725
}
731726

732727
tableView(self, didSelectRowAt: indexPath)
728+
729+
viewController?.resizeSidebar(withAnimation: true)
733730
}
734731

735732
public func reload(indexPath: IndexPath) {

0 commit comments

Comments
 (0)