Skip to content

Commit

Permalink
Gated and refactored code to get the Localization export to work corr…
Browse files Browse the repository at this point in the history
…ectly
  • Loading branch information
vincode-io committed Jan 7, 2024
1 parent 63229c4 commit dfa124b
Show file tree
Hide file tree
Showing 48 changed files with 444 additions and 188 deletions.
100 changes: 100 additions & 0 deletions AppKitPlugin/AppKitDefaults.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// AppKitDefaults.swift
// AppKitPlugin
//
// Created by Maurice Parker on 1/6/24.
//

import Foundation

enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
case automatic = 0
case light = 1
case dark = 2

var description: String {
switch self {
case .automatic:
return String(localized: "Automatic", comment: "Control Label: Automatic")
case .light:
return String(localized: "Light", comment: "Control Label: Light")
case .dark:
return String(localized: "Dark", comment: "Control Label: Dark")
}
}
}

final class AppDefaults {

static let shared = AppDefaults()
private init() {}

static var store: UserDefaults = {
let appIdentifierPrefix = Bundle.main.object(forInfoDictionaryKey: "AppIdentifierPrefix") as! String
let suiteName = "\(appIdentifierPrefix)group.\(Bundle.main.bundleIdentifier!)"
return UserDefaults.init(suiteName: suiteName)!
}()

struct Key {
static let userInterfaceColorPalette = "userInterfaceColorPalette";
}

var userInterfaceColorPalette: UserInterfaceColorPalette {
get {
if let result = UserInterfaceColorPalette(rawValue: Self.int(for: Key.userInterfaceColorPalette)) {
return result
}
return .automatic
}
set {
Self.setInt(for: Key.userInterfaceColorPalette, newValue.rawValue)
}
}

}

// MARK: Helpers

private extension AppDefaults {

static func string(for key: String) -> String? {
return AppDefaults.store.string(forKey: key)
}

static func setString(for key: String, _ value: String?) {
AppDefaults.store.set(value, forKey: key)
}

static func bool(for key: String) -> Bool {
return AppDefaults.store.bool(forKey: key)
}

static func setBool(for key: String, _ flag: Bool) {
AppDefaults.store.set(flag, forKey: key)
}

static func int(for key: String) -> Int {
return AppDefaults.store.integer(forKey: key)
}

static func setInt(for key: String, _ x: Int) {
AppDefaults.store.set(x, forKey: key)
}

static func date(for key: String) -> Date? {
return AppDefaults.store.object(forKey: key) as? Date
}

static func setDate(for key: String, _ date: Date?) {
AppDefaults.store.set(date, forKey: key)
}

static func data(for key: String) -> Data? {
return AppDefaults.store.object(forKey: key) as? Data
}

static func setData(for key: String, _ data: Data?) {
AppDefaults.store.set(data, forKey: key)
}

}
2 changes: 1 addition & 1 deletion AppKitPlugin/AppKitWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import UniformTypeIdentifiers

func configureOpenQuickly(_ window: NSObject?) {
guard let nsWindow = window as? NSWindow else { return }
nsWindow.title = AppStringAssets.openQuicklyWindowTitle
nsWindow.title = String(localized: "Open Quickly", comment: "Window Title: Open Quickly")
nsWindow.titlebarAppearsTransparent = true
nsWindow.standardWindowButton(.zoomButton)?.isHidden = true
nsWindow.standardWindowButton(.miniaturizeButton)?.isHidden = true
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions AppKitPlugin/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"sourceLanguage" : "en",
"strings" : {
"%@ was moved or renamed while open." : {
"comment" : "Message text for app moved while running alert"
},
"Automatic" : {
"comment" : "Control Label: Automatic"
},
"Dark" : {
"comment" : "Control Label: Dark"
},
"Light" : {
"comment" : "Control Label: Light"
},
"Moving an open application can cause unexpected behavior. Manually relaunch the application to continue." : {
"comment" : "Informative text for app moved while running alert"
},
"Open Quickly" : {
"comment" : "Window Title: Open Quickly"
},
"Terminate" : {
"comment" : "Relaunch Button"
},
"This app" : {
"comment" : "Backup name if the app name cannot be deduced from the bundle"
}
},
"version" : "1.0"
}
2 changes: 2 additions & 0 deletions VinCloudKit/Sources/VinCloudKit/VCKModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public extension VCKModel {
}
}

#if canImport(UIKit)
func merge(client: Data?, ancestor: Data?, server: Data?) -> Data? {
switch VCKMergeScenario.evaluate(client: client, ancestor: ancestor, server: server) {
case .clientWins:
Expand Down Expand Up @@ -117,6 +118,7 @@ public extension VCKModel {
}
}
}
#endif

func merge<T>(client: OrderedSet<T>?, ancestor: OrderedSet<T>?, server: OrderedSet<T>?) -> OrderedSet<T> where T:Equatable {
let mergeClient = client != nil ? Array(client!) : nil
Expand Down
6 changes: 6 additions & 0 deletions VinOutlineKit/Sources/VinOutlineKit/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Maurice Parker on 11/6/20.
//

#if canImport(UIKit)
import UIKit
#else
import Foundation
#endif
import CloudKit
import VinXML
import VinCloudKit
Expand Down Expand Up @@ -121,9 +125,11 @@ public final class Account: NSObject, Identifiable, Codable {
cloudKitManager?.userDidAcceptCloudKitShareWith(shareMetadata)
}

#if canImport(UIKit)
public func prepareCloudSharingController(document: Document, completion: @escaping (Result<UICloudSharingController, Error>) -> Void) {
cloudKitManager?.prepareCloudSharingController(document: document, completion: completion)
}
#endif

public func activate() {
guard isActive == false else { return }
Expand Down
10 changes: 9 additions & 1 deletion VinOutlineKit/Sources/VinOutlineKit/AccountType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Maurice Parker on 11/6/20.
//

#if canImport(UIKit)
import UIKit
#else
import Foundation
#endif

public enum AccountType: Int, Codable {
case local = 0
Expand All @@ -14,6 +18,7 @@ public enum AccountType: Int, Codable {
public var name: String {
switch self {
case .local:
#if canImport(UIKit)
switch UIDevice.current.userInterfaceIdiom {
case .mac:
return VinOutlineKitStringAssets.accountOnMyMac
Expand All @@ -24,11 +29,14 @@ public enum AccountType: Int, Codable {
default:
fatalError()
}
#else
return VinOutlineKitStringAssets.accountOnMyMac
#endif
case .cloudKit:
return VinOutlineKitStringAssets.accountICloud
}
}

var folderName: String {
switch self {
case .local:
Expand Down
7 changes: 6 additions & 1 deletion VinOutlineKit/Sources/VinOutlineKit/AllDocuments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
// Created by Maurice Parker on 1/27/21.
//

#if canImport(UIKit)
import UIKit

#else
import Foundation
#endif
public final class AllDocuments: Identifiable, DocumentContainer {

public var id: EntityID
public var name: String? = VinOutlineKitStringAssets.all
#if canImport(UIKit)
public var image: UIImage? = UIImage(systemName: "tray")!
#endif

public var itemCount: Int? {
return account?.documents?.count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Maurice Parker on 2/6/21.
//

#if canImport(UIKit)
import UIKit
#else
import Foundation
#endif
import OSLog
import SystemConfiguration
import CloudKit
Expand Down Expand Up @@ -41,7 +45,9 @@ public class CloudKitManager {
private weak var errorHandler: ErrorHandler?
private weak var account: Account?

#if canImport(UIKit)
private var sendChangesBackgroundTaskID = UIBackgroundTaskIdentifier.invalid
#endif

private var debouncer = Debouncer(duration: 5)
private var zones = [CKRecordZone.ID: CloudKitOutlineZone]()
Expand Down Expand Up @@ -197,6 +203,7 @@ public class CloudKitManager {
container.add(op)
}

#if canImport(UIKit)
func prepareCloudSharingController(document: Document, completion: @escaping (Result<UICloudSharingController, Error>) -> Void) {
guard let zoneID = document.zoneID else {
completion(.failure(CloudKitOutlineZoneError.unknown))
Expand All @@ -210,7 +217,8 @@ public class CloudKitManager {
zone.prepareNewCloudSharingController(document: document, completion: completion)
}
}

#endif

func resume() {
sync()
}
Expand Down Expand Up @@ -256,6 +264,7 @@ private extension CloudKitManager {
func sendChanges(userInitiated: Bool, completion: @escaping (() -> Void)) {
isSyncing = true

#if canImport(UIKit)
let completeProcessing = { [unowned self] in
self.isSyncing = false

Expand All @@ -269,6 +278,7 @@ private extension CloudKitManager {
completeProcessing()
self?.logger.info("CloudKit sync processing terminated for running too long.")
}
#endif

let operation = CloudKitModifyOperation()

Expand All @@ -281,7 +291,9 @@ private extension CloudKitManager {
}
}

#if canImport(UIKit)
completeProcessing()
#endif
}

self.queue.add(operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Maurice Parker on 2/6/21.
//

#if canImport(UIKit)
import UIKit
#else
import Foundation
#endif
import OSLog
import CloudKit
import VinCloudKit
Expand Down Expand Up @@ -38,6 +42,7 @@ final class CloudKitOutlineZone: VCKZone {
self.zoneID = zoneID
}

#if canImport(UIKit)
func prepareSharedCloudSharingController(document: Document, completion: @escaping (Result<UICloudSharingController, Error>) -> Void) {
guard let shareRecordID = document.shareRecordID else {
fatalError()
Expand Down Expand Up @@ -94,5 +99,5 @@ final class CloudKitOutlineZone: VCKZone {

completion(.success(sharingController))
}

#endif
}
6 changes: 6 additions & 0 deletions VinOutlineKit/Sources/VinOutlineKit/CursorCoordinates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Maurice Parker on 12/20/20.
//

#if canImport(UIKit)
import UIKit
#else
import Foundation
#endif

public protocol CursorCoordinatesProvider {
var coordinates: CursorCoordinates? { get }
Expand All @@ -27,9 +31,11 @@ public struct CursorCoordinates {

@available(iOSApplicationExtension, unavailable)
public static var currentCoordinates: CursorCoordinates? {
#if canImport(UIKit)
if let provider = UIResponder.currentFirstResponder as? CursorCoordinatesProvider {
return provider.coordinates
}
#endif
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions VinOutlineKit/Sources/VinOutlineKit/DocumentContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
// Created by Maurice Parker on 11/9/20.
//

#if canImport(UIKit)
import UIKit
#else
import Foundation
#endif

public protocol DocumentContainer: DocumentProvider {
var id: EntityID { get }
var name: String? { get }
#if canImport(UIKit)
var image: UIImage? { get }
#endif
var itemCount: Int? { get }
var account: Account? { get }
}
Expand Down
Loading

0 comments on commit dfa124b

Please sign in to comment.