Skip to content

Commit

Permalink
Merge pull request #1752 from glushchenko/hotfixes
Browse files Browse the repository at this point in the history
A huge number of long-awaited fixes and improvements
  • Loading branch information
glushchenko committed Aug 15, 2024
2 parents dc7be4b + e310744 commit 5dbac0a
Show file tree
Hide file tree
Showing 74 changed files with 2,902 additions and 246 deletions.
38 changes: 36 additions & 2 deletions FSNotes iOS/CloudDriveManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CloudDriveManager {
}
}

print("N. iCloud Drive resources: \"\(results.count)\", caching finished in \(point.timeIntervalSinceNow * -1) seconds.")
// print("N. iCloud Drive resources: \"\(results.count)\", caching finished in \(point.timeIntervalSinceNow * -1) seconds.")
}

private func startInitialLoading(results: [NSMetadataItem]) {
Expand Down Expand Up @@ -148,6 +148,12 @@ class CloudDriveManager {
continue
}


if url.lastPathComponent == ".encrypt" {
self.loadEncryptionStatus(url: url)
continue
}

// Is file
guard storage.isValidNote(url: url) else { continue }

Expand Down Expand Up @@ -183,7 +189,7 @@ class CloudDriveManager {
delegate.refreshTextStorage(note: note)
}

print("File changed: \(url)")
// print("File changed: \(url)")

// Not updates in FS attributes, must be loaded from Cloud Drive Meta
if note.isTextBundle() {
Expand Down Expand Up @@ -314,6 +320,11 @@ class CloudDriveManager {
guard let url = (item.value(forAttribute: NSMetadataItemURLKey) as? URL)?.standardized
else { continue }

if url.lastPathComponent == ".encrypt" {
self.loadEncryptionStatus(url: url)
continue
}

if let note = storage.getBy(url: url) {
storage.removeNotes(notes: [note], fsRemove: false) {_ in
self.notesDeletionQueue.append(note)
Expand All @@ -329,6 +340,29 @@ class CloudDriveManager {
return removedMetadataItems.count
}

private func loadEncryptionStatus(url: URL) {
if let project = self.storage.getProjectBy(url: url.deletingLastPathComponent()) {
project.isEncrypted = FileManager.default.fileExists(atPath: url.path)

DispatchQueue.main.async {
if let indexPath = self.delegate.sidebarTableView.getIndexPathBy(project: project) {

if let sidebarItem = self.delegate.sidebarTableView.getSidebarItem(project: project) {

let type: SidebarItemType = project.isEncrypted ? .ProjectEncryptedLocked : .Project
sidebarItem.setType(type: type)

let cell = self.delegate.sidebarTableView.cellForRow(at: indexPath) as? SidebarTableCellView

cell?.configure(sidebarItem: sidebarItem)
}

self.delegate.sidebarTableView.reloadRows(at: [indexPath], with: .none)
}
}
}
}

public func resolveConflict(url: URL) {
if let conflicts = NSFileVersion.unresolvedConflictVersionsOfItem(at: url as URL) {
for conflict in conflicts {
Expand Down
37 changes: 37 additions & 0 deletions FSNotes iOS/Extensions/UIColor+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,41 @@ extension UIColor {
UIColor(red: 0.08, green: 0.60, blue: 0.85, alpha: 1.00)
}
}

public static func getBy(hex: String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()

if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}

if ((cString.count) != 6) {
return UIColor.gray
}

var rgbValue:UInt64 = 0
Scanner(string: cString).scanHexInt64(&rgbValue)

return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}

var hexString: String {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0

guard self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else {
return "#ffffff"
}

let rgb: Int = (Int)(red * 255) << 16 | (Int)(green * 255) << 8 | (Int)(blue * 255) << 0

return String(format: "#%06x", rgb)
}
}
116 changes: 116 additions & 0 deletions FSNotes iOS/Icons.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"images" : [
{
"size" : "20x20",
"idiom": "iphone",
"filename" : "[email protected]",
"scale": "2x"
},
{
"size" : "20x20",
"idiom": "iphone",
"filename" : "[email protected]",
"scale": "3x"
},
{
"size" : "20x20",
"idiom": "ipad",
"filename" : "icon-1024-20.png",
"scale": "1x"
},
{
"size" : "20x20",
"idiom": "ipad",
"filename" : "[email protected]",
"scale": "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "icon-1024-29.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "icon-1024-40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "icon-1024-76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "icon-1024-1024.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions FSNotes iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,41 @@
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>marsIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>mars</string>
</array>
</dict>
<key>dylanseegerDarkFullIcon</key>
<dict>
<key>UIPrerenderedIcon</key>
<false/>
<key>CFBundleIconFiles</key>
<array>
<string>dylanseegerDarkFull</string>
</array>
</dict>
<key>dylanseegerDarkIcon</key>
<dict>
<key>UIPrerenderedIcon</key>
<false/>
<key>CFBundleIconFiles</key>
<array>
<string>dylanseegerDark</string>
</array>
</dict>
<key>dylanseegerIcon</key>
<dict>
<key>UIPrerenderedIcon</key>
<false/>
<key>CFBundleIconFiles</key>
<array>
<string>dylanseeger</string>
</array>
</dict>
<key>kmstrrIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>kmstrr</string>
</array>
</dict>
</dict>
</dict>
<key>CFBundleIcons~ipad</key>
Expand Down
12 changes: 9 additions & 3 deletions FSNotes iOS/MainNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ class MainNavigationController: UINavigationController {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

guard traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else { return }

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
let evc = UIApplication.getEVC()

evc.topBorder.backgroundColor = UIColor.toolbarBorder.cgColor
evc.editArea.textStorage.updateCheckboxList()

MPreviewView.template = nil
NotesTextProcessor.hl = nil
if let previewView = evc.getPreviewView() {
let funcName = self.traitCollection.userInterfaceStyle == .dark ? "switchToDarkMode" : "switchToLightMode"
let switchScript = "if (typeof(\(funcName)) == 'function') { \(funcName)(); }"

evc.refill()
previewView.evaluateJavaScript(switchScript)
}
}
}
}
23 changes: 14 additions & 9 deletions FSNotes iOS/Settings/AppIconViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ import UIKit
class AppIconViewController: UITableViewController {
enum AppIconRows: Int, CaseIterable {
case system
case kmstrr
case dylanseeger
case dylanseegerDark
case dylanseegerDarkFull

public func getName() -> String {
switch self {
case .system:
return "System"
case .kmstrr:
return "Classic"
case .dylanseeger:
return "Modern (Light)"
return "Modern"
case .dylanseegerDark:
return "Modern (Dark)"
case .dylanseegerDarkFull:
return "Modern (Black)"
}
Expand All @@ -28,7 +34,9 @@ class AppIconViewController: UITableViewController {
var description : String {
switch self {
case .system: return "system"
case .kmstrr: return "kmstrr"
case .dylanseeger: return "dylanseeger"
case .dylanseegerDark: return "dylanseegerDark"
case .dylanseegerDarkFull: return "dylanseegerDarkFull"
}
}
Expand Down Expand Up @@ -60,10 +68,9 @@ class AppIconViewController: UITableViewController {
cell.accessoryType = .checkmark

if let icon = AppIconRows(rawValue: indexPath.row)?.description {
var name = icon == "system" ? nil : icon + "Icon"

let iconName = icon == "system" ? nil : icon

UIApplication.shared.setAlternateIconName(iconName) { error in
UIApplication.shared.setAlternateIconName(name) { error in
if let error = error {
print("Error setting alternate icon \(icon): \(error.localizedDescription)")
}
Expand Down Expand Up @@ -98,16 +105,14 @@ class AppIconViewController: UITableViewController {
cell.imageView?.layer.cornerRadius = 20

if let icon = AppIconRows(rawValue: indexPath.row) {
var descName = icon.description

var iconName = icon.description
if icon.description == "system" {
descName = "dylanseeger"
iconName = "dylanseeger"
}

if let image = UIImage(named: "app-icon-" + descName) {
if let image = UIImage(named: "app-icon-\(iconName)") {
cell.imageView?.image = image
}

cell.textLabel?.text = icon.getName()
}

Expand Down
3 changes: 2 additions & 1 deletion FSNotes iOS/ViewController+More.swift
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,11 @@ extension ViewController: UIDocumentPickerDelegate {
guard let selectedProject = selectedProject else { return }

getMasterPassword() { password in
let notes = selectedProject.storage.getNotesBy(project: selectedProject)
let decrypted = selectedProject.decrypt(password: password)

DispatchQueue.main.async {
guard decrypted.count > 0 else {
guard decrypted.count > 0 || notes.count == 0 else {
self.wrongPassAlert()
return
}
Expand Down
Loading

0 comments on commit 5dbac0a

Please sign in to comment.