Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Nov 21, 2024
1 parent 126311c commit 3681254
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 264 deletions.
56 changes: 10 additions & 46 deletions FSNotes iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

public static var gitVC = [String: GitViewController]()
public static var gitProgress: GitProgress?

// MARK: Static Properties
static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
var shouldPerformAdditionalDelegateHandling = true
Expand Down Expand Up @@ -108,16 +111,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillEnterForeground(_ application: UIApplication) {
// 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.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// 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.

guard let shortcut = launchedShortcutItem else { return }
_ = handleShortCutItem(shortcut)

// Reset which shortcut was chosen for next time.
launchedShortcutItem = nil
}

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

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handledShortCutItem = handleShortCutItem(shortcutItem)
completionHandler(handledShortCutItem)
}

// MARK: Static Properties
static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"

func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
var handled = false
guard ShortcutIdentifier(fullType: shortcutItem.type) != nil else { return false }
guard let shortCutType = shortcutItem.type as String? else { return false }

let vc = UIApplication.getVC()

switch shortCutType {
case ShortcutIdentifier.makeNew.type:
vc.createNote()

handled = true
break
case ShortcutIdentifier.clipboard.type:
vc.createNote(pasteboard: true)

handled = true
break
case ShortcutIdentifier.search.type:
vc.loadViewIfNeeded()
vc.popViewController()
vc.loadSearchController()
handled = true
break
default:

break

if ShortcutIdentifier(fullType: shortcutItem.type) == .search {
UIApplication.getVC().enableSearchFocus()
}

return handled

UIApplication.getVC().handleShortCutItem(shortcutItem)
completionHandler(true)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
Expand All @@ -191,6 +154,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
note = storage.getBy(title: id)
if !vc.isLoadedDB, note == nil {
vc.restoreFindID = id
return true
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions FSNotes iOS/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick

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

UserDefaultsManagement.lastSelectedURL = note.url

if enableHandoff {
registerHandoff(for: note)
}
Expand Down Expand Up @@ -1446,8 +1444,10 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
}

@objc public func togglePreview() {
guard let note = editArea.note else { return }

guard let unwrappedNote = self.note, let note = Storage.shared().getBy(url: unwrappedNote.url) else { return }

note.loadPreviewState()

if note.previewState {
note.previewState = false
getPreviewView()?.removeFromSuperview()
Expand Down Expand Up @@ -1581,12 +1581,17 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
override func restoreUserActivityState(_ activity: NSUserActivity) {
if let id = activity.userInfo?["kCSSearchableItemActivityIdentifier"] as? String {
let url = URL(fileURLWithPath: id)
if let note = Storage.shared().getBy(url: url) {

var note = Storage.shared().getBy(url: url)
if nil === note {
note = Storage.shared().addNote(url: url)
}

if let note = note {
load(note: note)
return
} else {
UIApplication.getVC().restoreActivity = url
}

return
}

guard let name = activity.userInfo?["note-file-name"] as? String,
Expand Down
4 changes: 4 additions & 0 deletions FSNotes iOS/Extensions/UIApplication+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ extension UIApplication {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
return appDelegate.mainController
}

static func getDelegate() -> AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
}
7 changes: 4 additions & 3 deletions FSNotes iOS/View/NotesTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class NotesTableView: UITableView,
let note = self.notes[indexPath.row]

if !note.isLoaded && !note.isLoadedFromCache {
note.load()
note.uiLoad()
}

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

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

let note = notes[indexPath.row]
var note = notes[indexPath.row]
note.loadPreviewState()

let evc = UIApplication.getEVC()

if let editArea = evc.editArea, let u = editArea.undoManager {
u.removeAllActions()
}
Expand Down
11 changes: 4 additions & 7 deletions FSNotes iOS/View/SidebarTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ class SidebarTableView: UITableView,
vc.buildSearchQuery()
vc.reloadNotesTable() {
DispatchQueue.main.async {
vc.notesTable.hideLoader()
vc.setNavTitle(folder: name)
vc.isLoadedSidebar = true

guard vc.notesTable.notes.count > 0 else {
self.unloadAllTags()
Expand All @@ -147,13 +149,6 @@ class SidebarTableView: UITableView,
self.loadAllTags()
vc.resizeSidebar(withAnimation: true)
}

if let url = UserDefaultsManagement.lastSelectedURL,
let note = Storage.shared().getBy(url: url) {
UserDefaultsManagement.lastSelectedURL = nil

UIApplication.getEVC().load(note: note)
}
}
}
}
Expand Down Expand Up @@ -730,6 +725,8 @@ class SidebarTableView: UITableView,
}

tableView(self, didSelectRowAt: indexPath)

viewController?.resizeSidebar(withAnimation: true)
}

public func reload(indexPath: IndexPath) {
Expand Down
Loading

0 comments on commit 3681254

Please sign in to comment.